Side-by-side before/after: one Django 5.2 LTS plus DRF deployable with six in-process bounded-context apps sharing a single Postgres schema and one transaction.atomic() checkout spanning order, inventory, payment, and notification, versus six independent FastAPI services plus a Strawberry GraphQL gateway, each owning its own schema, reached through one Starlette-based ASGI strangler proxy with a Kafka event backbone carrying the outbox and saga traffic.
Figure 0.1: The monolith this book starts with, and the six-service system it ends as
Download .excalidraw source
·
Edit on excalidraw.com
The six extractions in the order this book executes them, rising in difficulty left to right: review (REST leaf on a shared schema), notification (async transactional outbox), inventory (Debezium CDC plus a gRPC seam), payment (choreographed saga), shipping (orchestrated saga with crash-resume), and order with its Strawberry GraphQL gateway (CQRS).
Figure 0.2: The extraction order: rising difficulty, not rising domain importance
Download .excalidraw source
·
Edit on excalidraw.com
The local toolchain split into the two pieces every chapter needs (uv, managing the Python 3.14 interpreter, the virtual environment, and the lockfile; ruff and pytest as the dev-dependency group every service pulls in) and two ghosted later-scoped tools (grpcio-tools and a proto-drift check, both scoped to the inventory gRPC seam), alongside the compose stack's live services (Postgres, single-broker KRaft-mode Kafka, the Grafana LGTM bundle) and its two ghosted later services (Debezium Connect, the Apicurio schema registry), both landing in the same repository tree: examples/, tooling/, demos/, infra/, scripts/, and _docs/.
Figure 1.1: The local toolchain and the repository layout it builds, runs, and stands up.
Download .excalidraw source
·
Edit on excalidraw.com
The ledger's files mapped onto the ADLC's seven phases: the build plan and each iteration's own plan are produced during Plan, those same files are what Generate and Verify execute and check against, and the decision log plus the reconciliation log are written during Reconcile, which also loops back to update the build plan's own status line. Plan and Verify are marked as the two human-gate phases.
Figure 2.1: The ledger's files, mapped onto the ADLC's phases, and how an interrupted session resumes from them
Download .excalidraw source
·
Edit on excalidraw.com
A ten-cell grid of microservice traits: independently deployable; modeled around a business domain; communicate over the network; an opinionated form of service-oriented architecture; technology agnostic; a distributed system true of the set rather than one service; API-focused; decentralized governance; decentralized data management; designed for failure, each re-grounded in this project's FastAPI/Django stack rather than stated abstractly.
Figure 3.1: The ten traits 'microservices' is actually promising
Download .excalidraw source
·
Edit on excalidraw.com
A risk-shape contrast. Left: the big-bang rewrite concentrates three simultaneous bets (correctly understanding every piece of accumulated behavior, outbuilding the old system's decay, and the business tolerating a long stretch of no new value shipped) into one irreversible cutover at the end. Right: the strangler fig distributes the same risk across many small, independently reversible steps, starting with the review extraction live behind a flag before any other bounded context has been touched.
Figure 3.2: Why a big-bang rewrite concentrates risk a strangler fig distributes
Download .excalidraw source
·
Edit on excalidraw.com
A bar-style comparison of Phase A (illustrative, Django ORM bridged via sync_to_async) versus Phase B (shipped, idiomatic FastAPI plus async SQLAlchemy): import/startup time 0.32-0.35s versus 0.35-0.36s, import-only RSS about 73.5MB versus about 72.3MB: the two bars drawn nearly equal length because the near-equality is the finding, not a rendering quirk.
Figure 3.3: Phase A vs. Phase B: a structural win, not a startup-time number
Download .excalidraw source
·
Edit on excalidraw.com
Four migration strategies compared side by side: big-bang rewrite (highest risk, one long cutover), the strangler fig (this book's choice, incremental and independently verifiable), branch-by-abstraction (an in-process seam toggle), and parallel-run (a live shadow comparison of two running paths).
Figure 4.1: The migration-strategy spectrum, from big-bang rewrite to the strangler fig
Download .excalidraw source
·
Edit on excalidraw.com
A four-quadrant plot of strategic value against change frequency. High value, high change frequency favors incremental re-architecture. Low value, low change frequency favors Lift and Shift or Retain. This book's own monolith is plotted high on strategic value (the order-taking and fulfillment path for a shipping business) and, on the ease-of-migration rubric, difficult on data (one shared schema with cross-app foreign keys) and moderate everywhere else.
Figure 4.2: Where this book's monolith lands on the value-versus-change quadrant
Download .excalidraw source
·
Edit on excalidraw.com
Four left-to-right snapshots of the system's topology over the course of the book: one Django deployable with six in-process apps and one shared schema; the same monolith with the ASGI strangler proxy standing in front, every call still passing through unchanged; review and notification live as FastAPI services behind the proxy while four contexts still answer from the shrinking monolith; and the fully extracted end state, a flagless edge router in front of all six services plus the GraphQL gateway, with the monolith decommissioned from the running topology and kept frozen as the 'before' referent.
Figure 4.3: The evolution arc this book actually executes, snapshot by snapshot
Download .excalidraw source
·
Edit on excalidraw.com
Two parallel eight-step cycles. Left, the traditional SDLC: requirements and planning (days-weeks), system design (weeks), implementation and coding (weeks-months), testing and QA (days-weeks), code review (days), deploy and release (days), monitoring and observability (ongoing), feedback and iteration (continuous), looping back to step one. Right, the agentic SDLC: express intent (minutes), agent understands (seconds), agent implements (minutes), agent tests and docs (minutes), human review (minutes-hours), deploy and ship (minutes), monitoring and observability (continuous), learn and iterate (ongoing), looping back to step one. A transformation arrow connects the two loops, with a Key Differences table below.
Figure 5.1: The traditional SDLC (weeks to months, handoff-driven) and the agentic SDLC it's becoming (hours to days, human-guides/agent-executes)
Download .excalidraw source
·
Edit on excalidraw.com
Two stacked bands. Top band: agentic SDLC (8 steps): express intent, agent understands, agent implements, agent tests and docs, human review, deploy and ship, monitoring and observability, learn and iterate. Bottom band: ADLC (7 phases): Frame, Map, Plan, Generate, Verify, Operate, Reconcile. Dashed lines map each top step down to the phase or phases it corresponds to: express intent to Frame, agent understands to Map, agent implements spanning both Plan and Generate, agent tests and docs to Generate, human review to Verify, deploy and ship and monitoring and observability both to Operate, learn and iterate to Reconcile. Two gate markers sit between the bands: plan approval, and equivalence sign-off.
Figure 5.2: Mapping the agentic SDLC's eight steps onto this book's seven-phase ADLC, with the two human gates marked where they land
Download .excalidraw source
·
Edit on excalidraw.com
A seven-phase cycle, each phase annotated with the tool role for this project's stack: Frame: human, intent plus PRD; Map: manual reconnaissance plus a scaffolding skill, no MCP equivalent; Plan: the relay, Opus plans; Generate: the relay, Sonnet executes, plus a scaffolding skill scaffolds; Verify: the relay, Opus validates, pytest plus Newman plus a security scan; Operate: a local-stack skill or a cluster-stack skill plus feature flags; Reconcile: the three ledger files.
Figure 5.3: The ADLC's seven phases, annotated with the tool at each one, including where the tooling runs out
Download .excalidraw source
·
Edit on excalidraw.com
A shared outer path (express intent, learn and iterate, monitoring and observability, deploy and ship) flanked by two parallel inner bands covering agent understands through human review. The local band runs each step through a local coding agent plus uv, pytest, and Testcontainers against Docker Engine. The hosted band runs the same steps through a hosted AI platform, with agent tests and docs landing in GitHub Actions' code-ci.yml. Both bands converge back onto the shared deploy-and-ship step.
Figure 5.4: The same agentic loop, run two ways: a local execution path (uv plus Docker Engine) versus a hosted path (a hosted AI platform plus GitHub Actions)
Download .excalidraw source
·
Edit on excalidraw.com
Six boxes in a row: Frame (human, states intent, writes the decision-log entry), Plan tier (Opus, reads Frame plus Map recon, drafts the step plan), Human gate 1 (plan approval, before any diff exists), Execute tier (Sonnet, Generate: scaffolds, writes code and tests, runs them), Validate tier (Opus again, adversarial: re-reads plan and diff against the equivalence suite), Human gate 2 (equivalence sign-off, Verify phase). A dashed line below the row connects the Plan and Validate boxes, labeled: same model tier, now adversarial, not self-vouching.
Figure 6.1: The relay: the planning tier drafts, the execution tier builds, the same planning tier validates adversarially, with a human gate on either side of Generate
Download .excalidraw source
·
Edit on excalidraw.com
A client request hits the strangler proxy's one catch-all route, mounted at the application root. A backend-selection function matches the full request path against six fixed prefixes, each mapped to one operator-configured backend base URL; no match returns a real 404. The matched request is rebuilt: hop-by-hop headers are stripped, the body is buffered so the outbound request carries a correct Content-Length instead of falling back to chunked encoding, and the request streams to the backend. A reachable backend's response streams back to the client verbatim; an unreachable backend becomes a real 502, never a swallowed 200. A callout names the trap: the full request path must be matched, not a route-pattern-relative value with the mount prefix already stripped.
Figure 6.2: The Python analog of a content-based router, built from first principles instead of an integration framework
Download .excalidraw source
·
Edit on excalidraw.com
Two stacked panels. Top: the structural gate, here necessarily weaker and more manual than a live route-validator MCP tool would be: ruff check plus Python's own import-time wiring, where a Starlette or FastAPI app that fails to construct raises immediately rather than deploying silently. It catches a malformed route registration or a typo'd dependency signature, but has no opinion about whether a routing predicate matches the right requests once real traffic flows. Bottom: the behavioral gate, the Newman equivalence suite and its adversarial follow-up, run during Verify against a running service. This is the layer that caught the strangler proxy's real chunked-body bug: the in-process routing tests passed while the proxy silently sent every POST upstream with no body, because only a real socket run surfaces that class of defect.
Figure 6.3: The structural gate (what ruff and import-time wiring catch) and the behavioral gate (what the equivalence suite catches) are different layers, and this stack's structural layer is weaker than a framework-aware MCP tool's would be
Download .excalidraw source
·
Edit on excalidraw.com
Two panels. Left: the ASGI strangler proxy can route an /api/reviews request to either the Django monolith or the FastAPI review-service, and because Review's extraction kept sharing the monolith's existing Postgres schema, both backends read and write the exact same rows: a suite that only checks HTTP response shape cannot tell a correctly-served request apart from one that silently fell through, because for this slice both statements describe the same table. Right: what actually closed the gap: exercising a real POST over a real socket against the real WSGI backend, which is exactly the surface where the chunked-body bug was hiding, invisible to the in-process mock-transport tests and caught only once the suite ran against a live socket.
Figure 7.1: Why a response-shape-only check needed a real socket to be trusted here
Download .excalidraw source
·
Edit on excalidraw.com
Three stacked layers. Layer 1, automated: the Newman behavior-equivalence suite, re-run against every candidate build over a real socket, which caught the chunked-body bug that an in-process mock-transport suite structurally could not see; removing this layer lets every POST through the proxy keep silently arriving empty. Layer 2, adversarial verification: checking the suite's result against what actually persisted in the shared table, not just the HTTP response shape; removing this layer lets a shape-only green run get trusted even when both backends happen to look similar for different reasons. Layer 3, the two human gates: plan approval before any diff exists, and equivalence sign-off judging whether the suite's specific coverage is the right coverage for the stakes; removing this layer means a green suite run gets trusted as self-certifying.
Figure 7.2: The safety net's three layers, and what each one stops
Download .excalidraw source
·
Edit on excalidraw.com
The monolith as one Django deployable: a single ASGI/WSGI process fronting six Django apps, all backed by one shared Postgres schema
Figure 8.1: One deployable, six contexts, one schema
Download .excalidraw source
·
Edit on excalidraw.com
Six Django apps (order, inventory, payment, shipping, notification, review) plus the common shared kernel, all registered in one INSTALLED_APPS list
Figure 8.2: Six contexts, one shared kernel, one Django project
Download .excalidraw source
·
Edit on excalidraw.com
Entity-relationship diagram of the monolith's one Postgres schema: customers, inventory_items, orders, order_items, payments, shipments, notifications, reviews, and outbox, with foreign keys crossing context boundaries
Figure 8.3: One schema, eight tables, foreign keys crossing every bounded-context line
Download .excalidraw source
·
Edit on excalidraw.com
Sequence diagram of place_order(): order creation, inventory reservation, payment capture, shipment dispatch, and an outbox write, all inside one transaction.atomic() block
Figure 8.4: place_order()'s single transaction, five contexts deep
Download .excalidraw source
·
Edit on excalidraw.com
Map of the monolith's seven deliberate smells, each pointing from its planted location to the chapter that cures it
Figure 9.1: Seven smells, seven curing chapters
Download .excalidraw source
·
Edit on excalidraw.com
Test pyramid for the monolith: a broad base of Django ORM/service-layer tests, a middle layer of DRF view tests via APIClient, and a thin top layer of full-stack checkout scenarios against real Postgres
Figure 10.1: The monolith's whitebox pyramid
Download .excalidraw source
·
Edit on excalidraw.com
Two parallel structures: the whitebox pytest pyramid testing the monolith's internals, versus the one flat Newman contract collection asserting only externally observable HTTP behavior, re-pointable at either the monolith or an extracted service
Figure 10.2: Whitebox pyramid vs. blackbox equivalence: two different questions, two different shapes
Download .excalidraw source
·
Edit on excalidraw.com
A context map of the monolith's six bounded contexts: order's edge into inventory is conformist, with no anti-corruption layer at the seam; order's edges into payment and shipping are direct synchronous calls inside one transaction.atomic(), with no port; order's edge into notification is already cured, reached only via an outbox and an asynchronous consumer; review has zero outbound edges to any sibling context; and all six sit on one Postgres schema, a shared kernel with no governed edges.
Figure 11.1: Context map: six bounded contexts, one relationship nobody decided
Download .excalidraw source
·
Edit on excalidraw.com
A hexagonal-architecture diagram: a domain core at center, holding entities, aggregates, and business logic, with no dependency on any web framework, ORM, or message broker; driving adapters (a REST route, a gRPC service, a message consumer) each depending inward on an inbound port; driven adapters (a database repository module, an event publisher) each depending inward on an outbound port the core declared.
Figure 11.2: Hexagonal architecture: ports and adapters, dependencies pointing inward
Download .excalidraw source
·
Edit on excalidraw.com
Two stacked readings of the checkout flow: the top band shows today's _place_order_local as one synchronous call chain inside a single transaction.atomic() across inventory, payment, and shipping, ending in an outbox write already cured for notification; the bottom band shows the same business process re-read with the event-storming grammar: an actor and command producing an Order aggregate, a timeline of domain events (OrderPlaced, StockReserved, PaymentCaptured or PaymentDeclined, ShipmentDispatched, OrderConfirmed, NotificationSent) separated by policies and reactions, an external payment gateway, and an Order Status read model fed by the events.
Figure 12.1: The checkout flow, read two ways: one call chain today, a timeline of domain events once it's event-stormed
Download .excalidraw source
·
Edit on excalidraw.com
A seven-row legend card listing the event-storming note types in the order a session introduces them: domain event (orange sticky, a past-tense fact, e.g. OrderPlaced), command (blue sticky, the imperative that triggered it, e.g. Place Order), actor (small yellow figure left of its command, e.g. Customer), aggregate (large yellow sticky, the data cluster enforcing an invariant, e.g. Order), policy/reaction (lilac sticky, 'whenever X then issue command Y', no human actor), read model (green sticky, a view projected forward from events, e.g. Order Status), and external system (pink sticky, outside the team's control, e.g. the Payment Gateway stand-in). Each row also names this book's house-style box type that stands in for the real sticky color.
Figure 12.2: The event-storming note-type legend: the wall's color grammar, named as the chapter calls it
Download .excalidraw source
·
Edit on excalidraw.com
A four-row table mapping each event boundary this chapter's storm found to its extraction chapter and mechanism: OrderPlaced to StockReserved (inventory's seam) to the inventory extraction, a gRPC proto-as-ACL plus CDC backfill; StockReserved to PaymentCaptured/PaymentDeclined (payment's seam) to the payment extraction, a choreographed saga via an aiokafka consumer; PaymentCaptured to ShipmentDispatched (shipping's seam) to the shipping extraction, an orchestrated saga with a single FastAPI coordinator; and ShipmentDispatched to OrderConfirmed/NotificationSent (notification's seam, cut first behaviorally) to the notification extraction, a transactional outbox. A footnote box notes order/services.py::place_order() itself is cut last, in the order extraction, after all four boundaries already fire events.
Figure 12.3: From the storm wall to the extraction backlog: each boundary, its chapter, and its mechanism
Download .excalidraw source
·
Edit on excalidraw.com
The Constantine coupling ladder drawn as seven stacked rungs, worst to best, each paired with its monolith example. Content coupling: _place_order_local reading a live InventoryItem's sku/name/price_cents straight from get_by_sku()/reserve(), with no ACL at the seam and only Python's lack of access modifiers standing in for one. Common coupling: one shared Postgres schema across order, inventory, payment, shipping, notification, and customers, with no single owner. Control coupling: OrderCreateSerializer.paymentMethod threaded into payment.services.charge, where DECLINE_SENTINEL selects an approve-or-decline code path. Stamp coupling: the same get_by_sku()/reserve() handoff returning the full InventoryItem for the three fields OrderItem actually needs. Data coupling: InventoryItemSerializer and OrderSerializer returning serialized output, not raw models, already done right. Message coupling and API/data-structure coupling have no monolith example: they're what examples/02-07 already reach.
Figure 13.1: The Constantine coupling ladder, worst to best, each rung pinned to its monolith example
Download .excalidraw source
·
Edit on excalidraw.com
A directed dependency graph of the six contexts. Order sits at the center with its remaining outbound edges (place_order()'s calls into inventory, payment, and shipping (three synchronous) plus one already-async edge into notification) its efferent coupling; and three inbound foreign-key edges from payment, shipment, and notification back to order, its afferent coupling. Inventory also carries a data-level edge from order via the historical FK the planted smells flag. Review has no edges in or out. A dashed edge from shipping to payment marks the dependency payment only gains once shipping is extracted. Below, the same six contexts sorted into the resolved extraction order: review, notification, inventory, payment, shipping, then order, lowest Ca/Ce first.
Figure 13.2: The six contexts' dependency graph, scored by Ca/Ce, resolving into the extraction order
Download .excalidraw source
·
Edit on excalidraw.com
Four ordered moves of the strangler fig pattern: intercept, route, incrementally replace, retire, with a reversibility window spanning the first three and a warning about retiring too early
Figure 14.1: The strangler fig's four moves, in the order that matters
Download .excalidraw source
·
Edit on excalidraw.com
The strangler proxy's content-based routing with STRANGLER_REVIEW_ENABLED off versus on, shown as two stacked topologies, each routing client requests through the proxy to either the monolith or the review-service, both against a shared Postgres schema
Figure 14.2: Content-based routing: the flag OFF vs ON
Download .excalidraw source
·
Edit on excalidraw.com
Timeline of four Newman runs against the strangler proxy: flag off baseline, flag on cutover, flag off reverted, and a negative check with the review-service killed returning 502s by design, with decommission ghosted as a future irreversible step
Figure 14.3: The cutover evidence trail: one unedited Newman suite, four runs
Download .excalidraw source
·
Edit on excalidraw.com
Side by side comparison of Phase A (FastAPI routes calling the Django ORM via sync_to_async, behind a path dependency on the monolith) and Phase B (FastAPI routes calling native async SQLAlchemy and asyncpg directly, with no Django import), both reading and writing the same shared Postgres schema
Figure 15.1: Phase A (illustrative) vs Phase B (shipped)
Download .excalidraw source
·
Edit on excalidraw.com
One routing topology: client through the strangler proxy to one of three backends (monolith default, review-service on a path-prefix match, notification-service on a path-prefix match), with a side panel naming header- and payload-based routing as generalizations of today's path-prefix predicate
Figure 16.1: One routing decision, generalized past a single URL-path predicate
Download .excalidraw source
·
Edit on excalidraw.com
Two panels: Panel A shows review-service reaching directly into the monolith's shared Postgres tables with no anti-corruption layer; Panel B shows notification-service's OrderPlacedEvent as a translation boundary between the monolith's Kafka contract and the service's own owned schema
Figure 16.2: The ACL is a translation boundary, not just another request
Download .excalidraw source
·
Edit on excalidraw.com
Before and after inside place_order()'s single transaction: the before panel ends with a synchronous out-of-process notification send, the dual-write hazard; the after panel ends with one ordinary OutboxEvent row, atomic with everything else automatically
Figure 17.1: The outbox cure changes the last write inside checkout's transaction, not the transaction itself
Download .excalidraw source
·
Edit on excalidraw.com
End-to-end pipeline: checkout writes an outbox row, the relay publishes it to Kafka at-least-once, and two independent consumer groups (monolith-notification and notification-service) each consume the same topic into their own read model, with the strangler proxy flag choosing which one answers GET /api/notifications
Figure 17.2: One outbox row, two independent consumer groups, one flag choosing who answers the read
Download .excalidraw source
·
Edit on excalidraw.com
What happens on a redelivered order.placed event: application-level check-then-insert handles the common case, and a database-level partial unique index on order_id backstops the narrow window where two redeliveries race the check itself, so exactly one Notification row survives either way
Figure 17.3: At-least-once delivery, exactly-once effect
Download .excalidraw source
·
Edit on excalidraw.com
Three stacked panels: Review stays on the monolith's shared schema (a named deferral), Notification owns its schema from day one (async seam), and Inventory owns its schema too but needs a one-time transaction-log backfill from the still-live monolith table during the cutover window
Figure 18.1: The three data-ownership postures this book builds, in the order they were built
Download .excalidraw source
·
Edit on excalidraw.com
Before and after OrderItem's relationship to InventoryItem: a live FK requiring a join versus a denormalized sku/item_name/unit_price_cents snapshot with no FK, plus the three-step add-backfill-drop migration sequence
Figure 18.2: From foreign key to snapshot: the denormalization move, concretely
Download .excalidraw source
·
Edit on excalidraw.com
The monolith's domain vocab, inventory.proto's distinct wire vocab, and inventory-service's own domain vocab, each translated by a client-side and server-side ACL
Figure 19.1: The proto IS the ACL: two separate vocabularies meet only at the wire
Download .excalidraw source
·
Edit on excalidraw.com
Transaction-log tailing end to end: Postgres WAL, replication slot, Debezium Postgres connector, Kafka topic, and InventoryCdcConsumer's upsert into the owned schema, with the retire runbook ghosted as the step that follows cutover
Figure 19.2: CDC tails the WAL for a one-time backfill plus transition sync, then is retired
Download .excalidraw source
·
Edit on excalidraw.com
Before and after panels: the single local transaction.atomic() giving a free rollback across reserve, order, payment, and shipping, versus the gRPC Reserve committing outside any local transaction with an explicit compensating Release wired to PaymentDeclined and ShippingFailed
Figure 19.3: Reserve/release across the boundary: where the free rollback went
Download .excalidraw source
·
Edit on excalidraw.com
The two independent cutover flags as a 2x2 grid, marking the two exercised locked-together corners against the two split corners sound only during the CDC-backfilled transition window
Figure 19.4: Two independent cutover dimensions, locked together in this book's exercised runs
Download .excalidraw source
·
Edit on excalidraw.com
One DB transaction commits the state row and the outbox row together, a relay polls and publishes at-least-once, and the necessary counterpart is an idempotent consumer in whichever idiom fits the write
Figure 20.1: The bridge, the relay, and the counterpart that makes at-least-once survive contact with reality
Download .excalidraw source
·
Edit on excalidraw.com
The monolith's order.placed outbox feeds payment-service's consumer, which writes its own outbox, which the monolith's own saga listener consumes in turn, two outboxes chained end to end, no orchestrator
Figure 20.2: Two outboxes, chained: this project's first multi-service outbox choreography
Download .excalidraw source
·
Edit on excalidraw.com
The CQRS command/query split inside order-service: the command path reserves over gRPC outside any local transaction, then persists the write aggregate, the order_view projection, and the order.placed outbox row in one transaction; the query path reads order_view exclusively, never the write tables
Figure 21.1: CQRS, concretely: one write aggregate, one projection, upserted in the same transaction as every mutation
Download .excalidraw source
·
Edit on excalidraw.com
Aggregate feeds a projection feeds the view under normal operation; rebuild_order_view recomputes the view from the current aggregate at any time; the projection-disabled negative test proves the read path never silently falls back to the aggregate by showing it go stale instead
Figure 21.2: A rebuildable read model: the projection-disabled negative is the proof the read path never falls back to the aggregate
Download .excalidraw source
·
Edit on excalidraw.com
What the single transaction.atomic() used to span versus what it spans now: Atomicity, Consistency, and Durability survive for a smaller scope; Isolation is gone for the gap outside it, where a PENDING order is visible and real before payment or shipping have resolved
Figure 22.1: ACID → ACD: three letters kept, one traded for a window the saga has to manage explicitly
Download .excalidraw source
·
Edit on excalidraw.com
PENDING's three idempotent terminal exits (CONFIRMED, SHIPPING_FAILED, PAYMENT_DECLINED) plus the documented stuck-PENDING failure mode a bounded-wait poll catches
Figure 22.2: The state machine ACD introduces: three protected exits, and one clearly-named failure mode
Download .excalidraw source
·
Edit on excalidraw.com
Before/after panels: PAYMENT_MODE=synchronous's one round trip ending in a terminal 201/402/422/409, versus choreographed's same round trip ending in a 202 PENDING promise the caller must poll to resolve
Figure 23.1: The contract change: 202 is a promise, not a faster 201
Download .excalidraw source
·
Edit on excalidraw.com
The full choreographed saga top to bottom, branching into its three terminal outcomes, every arrow is an event one side reacted to, no orchestrator box anywhere
Figure 23.2: The choreographed saga: every arrow is a reaction, not a call
Download .excalidraw source
·
Edit on excalidraw.com
A compensating Release survives redelivery at both the Kafka-event layer (the saga's status-transition guard) and the RPC layer (inventory-service's compensations ledger, INSERT ... ON CONFLICT DO NOTHING)
Figure 23.3: The deferred idempotency gap closed: idempotent at the event layer, idempotent at the RPC layer, independently
Download .excalidraw source
·
Edit on excalidraw.com
The choreographed payment saga and the orchestrated shipping saga side by side, the left panel has no box that knows the whole sequence, the right panel has exactly one
Figure 24.1: Choreography has no coordinator; orchestration has exactly one
Download .excalidraw source
·
Edit on excalidraw.com
The four-step orchestrated saga top to bottom, with one coordinator sequencing enrich, dispatch, book_carrier, and emit, and the reverse-order compensation path on a book_carrier failure
Figure 24.2: The orchestrated saga: one coordinator, four steps, one compensation decision
Download .excalidraw source
·
Edit on excalidraw.com
The saga's status state machine, the saga_log row each step appends, and the crash-resume path that is this service's durability upgrade over an in-memory saga coordinator
Figure 24.3: Resumable by construction: the row remembers what the process forgot
Download .excalidraw source
·
Edit on excalidraw.com
The full order lifecycle once SHIPPING_MODE=orchestrated: PENDING to AWAITING_SHIPMENT to CONFIRMED or SHIPPING_FAILED, plus the refund hop that closes the stranded-payment gap
Figure 24.4: AWAITING_SHIPMENT is a real intermediate status, not an implementation detail
Download .excalidraw source
·
Edit on excalidraw.com
The resilience chassis: four mechanisms this system already depends on, one new mechanism this chapter adds, and two patterns named as deferred, with the reason
Figure 25.1: What already runs, what's new, and what's not built yet
Download .excalidraw source
·
Edit on excalidraw.com
REST, gRPC, and GraphQL side by side, each labeled with the real seam this project chose it for: REST's request/reply for every service's own surface, gRPC's strongly-typed hot path for order-service's inventory reservation, GraphQL's bounded aggregation for the gateway's one query
Figure 26.1: Three protocols, three different problems, used side by side in one system
Download .excalidraw source
·
Edit on excalidraw.com
One order(id) query fanning out to five sources: order-service REST for the order itself, payment-service and shipping-service REST for payments and shipments, inventory-service gRPC for per-item stock, and review-service REST for per-item reviews, each field resolved lazily and nullable
Figure 26.2: One query, five sources, no data owned locally: partial failure is a null field, never a crashed request
Download .excalidraw source
·
Edit on excalidraw.com
The end-state topology: six independently deployable services plus the GraphQL gateway, reached through one flagless edge router with no monolith fallback left, and the monolith itself frozen and unwired
Figure 26.3: The final topology: six services and a GraphQL gateway behind one flagless router, the monolith frozen and unwired
Download .excalidraw source
·
Edit on excalidraw.com
A band labeled 'Inside one FastAPI service, startup to request' containing: config.py's frozen dataclass Settings.from_env() and stdlib RotatingFileHandler logging feeding from the uvicorn ASGI entry point; the lifespan() context manager wiring db engine, Kafka consumer, and outbox relay; errors.py's uniform error body and the GET /health route as request-time concerns present on 6 of 8 services; a box for the Containerfile present on all 8; tenacity retry as the one resilience wrapper, used only in shipping-service's enrich_client.py; and a dashed ghost box naming OpenTelemetry/Prometheus, pybreaker/bulkhead, and a shared chassis library named as not yet built.
Figure 27.1: The chassis inside one FastAPI service: what every service does identically, what's opt-in, and what's named but not built
Download .excalidraw source
·
Edit on excalidraw.com
Three stacked bands. USED, every service: config via a frozen dataclass and from_env() (7 of 8, review-service is the exception), stdlib RotatingFileHandler logging to logs/ (8 of 8), and a Containerfile (8 of 8). PARTIAL, a real count with a named reason for each gap: GET /health (6 of 8, absent in the proxy and review-service), errors.py's uniform error mapping (6 of 8, absent in the proxy and the GraphQL gateway, each for a structural reason), and tenacity retry (1 of 8, shipping-service's one outbound HTTP call site). DEFERRED, zero footprint today: metrics/OpenTelemetry (the mesh work adds it to three services), pybreaker/bulkhead (named in planning prose, no code), and a true shared chassis library (each file is copied and adapted per service, never imported from one shared package).
Figure 27.2: The chassis scorecard: used, partial, and deferred, across all 8 services
Download .excalidraw source
·
Edit on excalidraw.com
Two side-by-side panels. Left, today: payment-service's seven-field OrderPlacedEvent with paymentMethod and notification-service's six-field copy without it, two independent hand-authored understandings of the same frozen contract. Right, the registry demonstrator: one order-placed-v1.avsc registered once with Apicurio, resolved by global id from both a producer and a consumer, with a BACKWARD compatibility rule standing between any future version and the registry.
Figure 28.1: Two hand-duplicated Pydantic copies of the same contract, one drifted silently, versus one registry-governed schema demonstrated in parallel
Download .excalidraw source
·
Edit on excalidraw.com
Top band: the wire envelope byte layout, a 1-byte magic value, an 8-byte big-endian Apicurio global schema id, and the raw schemaless Avro bytes, contrasted with Confluent's 4-byte-id format. Bottom band: the full produce/consume flow against a live Apicurio registry, register_or_resolve, encode and publish, consume, fetch the writer schema by global id, decode with that exact schema.
Figure 28.2: The hand-rolled wire envelope and the register/resolve round trip against Apicurio's v3 REST API
Download .excalidraw source
·
Edit on excalidraw.com
Three schema versions in sequence: v1 registers cleanly, v2 adds an optional giftMessage field with a default and is ACCEPTED (200), v3 retypes totalCents from long to string and is REJECTED (400, RuleViolationException), the actual status observed against the pinned Apicurio 3.3.3 image, against a BACKWARD compatibility rule attached to the artifact.
Figure 28.3: Schema evolution against a live BACKWARD rule: an additive change passes, a retype is rejected before a single message ships
Download .excalidraw source
·
Edit on excalidraw.com
The mea namespace: strangler-proxy as the single NodePort 30888 edge, six bounded-context services plus graphql-gateway's own ClusterIP-only front door, a shared postgres StatefulSet (schema-per-service in app code) and a shared kafka StatefulSet, with order-service and graphql-gateway each a gRPC client of inventory-service
Figure 29.1: The mea namespace: 8 Deployments/Services, 2 StatefulSets, one NodePort edge
Download .excalidraw source
·
Edit on excalidraw.com
The mea namespace with the mesh active: all 8 app Deployments carry the sidecar.istio.io/inject pod-template label and run with an injected Envoy sidecar; PeerAuthentication STRICT makes every meshed-to-meshed hop mTLS, with one PERMISSIVE exception on strangler-proxy's plaintext NodePort inbound edge; postgres, kafka, and the lgtm observability backend carry no inject label and stay unmeshed; the three OTel-instrumented services (strangler-proxy, order-service, inventory-service) export app-level OTLP spans to lgtm alongside the mesh-wide Envoy spans and the istio-proxy Prometheus scrape every service contributes.
Figure 30.1: The meshed mea namespace: mTLS STRICT inside, one PERMISSIVE edge, two unmeshed backends
Download .excalidraw source
·
Edit on excalidraw.com
The hero trace as nested spans across three hops: Hop 1, client to strangler-proxy, an Envoy ingress span wrapping an app-level proxy_handler span; Hop 2, strangler-proxy to order-service, an Envoy span wrapping a FastAPI server span with two asyncpg child spans (the order aggregate insert and the order_view CQRS write) and an outbound grpc-client span; Hop 3, order-service to inventory-service over gRPC crossing the ACL seam, an Envoy span wrapping a grpc-server span with its own asyncpg child span reserving the inventory row. Grey boxes are mesh spans present for all 8 services; green boxes are app-level OTel spans present only on the 3 instrumented services.
Figure 30.2: The hero trace: mesh spans (breadth) wrapping app spans (depth), three hops, one connected trace
Download .excalidraw source
·
Edit on excalidraw.com
Top band: the syft-to-grype-to-policy pipeline run for both order-service (gate required) and the monolith (gate reported), both producing the identical 265-match, 35-High result from their shared UBI base layer, with the fixable-only ignore rule routing order-service's 35 not-fixed High findings out of the pass/fail decision so the service passes with zero fixable High findings. Bottom band: the four separate, additive GitHub Actions workflows this repo ships, each with its own changes/gate/star-ok summary job and no paths filter, converging on one repository ruleset with four required checks; monolith-scan hangs off supply-chain.yml's sbom-scan job but is explicitly excluded from the required check.
Figure 31.1: The supply-chain gate pipeline, and the four additive CI checks it joins
Download .excalidraw source
·
Edit on excalidraw.com
Two chained rows of patterns across the book's chapters, colored by verdict. Row one (Strangler Fig through Orchestrated Sagas): Strangler Fig, ACL plus gRPC seam, Transactional Outbox, CQRS, Saga Choreographed, Saga Orchestrated, all accent (earned). Row two (FastAPI Chassis through CI/CD): Contracts and Schema Registry and Microservices Chassis in user-blue (adapted), Deployment in accent (earned), Service Mesh plus Observability in user-blue (adapted, mesh earned/OTel on 3 of 8), CI/CD plus Supply Chain in accent (earned). A ghost row below names five further horizons connected by dashed arrows from the pattern each would extend: full event sourcing from CQRS, pybreaker/bulkhead from the chassis, a GitOps operator plus canary from deployment, Loki log aggregation and Kafka saga-hop tracing both from service mesh plus observability.
Figure 32.1: The pattern language as one connected flow, colored by verdict
Download .excalidraw source
·
Edit on excalidraw.com
Three stacked bands of the book-wide pattern scorecard. EARNED (8 cards): Strangler Fig, Content-Based Routing plus ACL, Shared to Owned Data plus sync gRPC, Transactional Outbox plus event-driven, CQRS plus ACID to ACD, Saga Choreographed plus Orchestrated, Deployment via kustomize, CI/CD plus Supply Chain. ADAPTED (5 cards): Microservices Chassis, Contracts and Schema Registry, Service Mesh plus Observability (mesh earned, OTel on 3 of 8), CDC and Transaction Log Tailing (transition-only, retired), Event Sourcing (light, outbox-as-log framing). NAMED, DEFERRED (6 ghost cards): full event sourcing, pybreaker and bulkhead, a GitOps operator plus canary, Loki log aggregation, Kafka saga-hop tracing, and Caching (demoted to Appendix H).
Figure 32.2: The book-wide pattern scorecard
Download .excalidraw source
·
Edit on excalidraw.com
A host-side podman build and push pipeline on the left feeding, across the registry Route, ImageStream tags inside the mea project on the right; a mirror-infra branch pulls and re-pushes postgres and kafka images for a CRC VM with no outbound egress; the monolith image and an infra image pull both flow from the same ImageStream tags toward a bootstrap Job and the postgres/kafka StatefulSets respectively.
Figure 33.1: Image delivery: podman build and push on the host, pulled in-cluster from the integrated registry
Download .excalidraw source
·
Edit on excalidraw.com
The mea namespace with OSSM 3 active: every service pairs with an istio-proxy sidecar joined by the istio.io/rev label; a namespace-wide STRICT PeerAuthentication governs every sidecar-to-sidecar hop; strangler-proxy and graphql-gateway each carry a workload-scoped PERMISSIVE PeerAuthentication because Route traffic arrives from outside the mesh with no sidecar on the client side; postgres and kafka carry no istio.io/rev label and stay unmeshed; Kiali reads otel-lgtm's own bundled Prometheus instead of a cluster Prometheus, which CRC does not run.
Figure 33.3: STRICT mesh-wide, a PERMISSIVE carve-out at each Route, the Route itself as the one unmeshed edge
Download .excalidraw source
·
Edit on excalidraw.com
The mea project on OpenShift Local: strangler-proxy and graphql-gateway each behind their own Route under restricted-v2, the other six services under restricted-v2 with no external exposure, postgres and kafka under the mea-infra ServiceAccount bound to nonroot-v2, and otel-lgtm under anyuid with only runAsUser 0 set.
Figure 33.2: The mea project on OpenShift Local: three SCC postures, two Routes as the only edge
Download .excalidraw source
·
Edit on excalidraw.com