Designing an Event-Driven System End to End
On this page
Learning Objective
Combine every pattern in this course into a coherent design for a realistic system, apply each one only where its specific question is answered yes, and plan an incremental adoption path that delivers value before the full architecture exists.
Concept Explanation
This course has presented a set of independent tools: event-driven integration, event sourcing, CQRS, the outbox, change data capture, and sagas with orchestration or choreography. The failure mode at this point is to apply all of them everywhere. The discipline is to run each design question separately for each bounded context and accept a deliberately non-uniform architecture as the correct outcome.
The four questions are worth restating in their decision form. Do other services need to react to changes here without this service knowing about them? If yes, publish events, and use an outbox or change data capture to publish them reliably. Is the history of changes valuable as data, legally required, or needed to explain past decisions? If yes, event-source this context, and only this one. Do the read and write workloads differ enough in shape, volume, or scaling needs that one model cannot serve both? If yes, apply CQRS, starting with separate code paths and moving to a separate store only when the workload demands it. Does a business process span services or aggregates that cannot be updated atomically? If yes, build a saga, orchestrated if it has more than a few steps or needs compensation.
Applied to a realistic commerce system, those questions produce a mixed answer, which is the point. The ledger context is event-sourced because finance and audit require it. The catalog context is CQRS with a conventional relational write side and an Elasticsearch read model, because search is the workload. The order context is conventional storage with an outbox, because it needs reliable publication but its history has no independent value beyond a status trail. Inventory uses a saga for reservation across services. And user preferences, content pages, and half the administrative surface are plain create-read-update-delete with no events at all, because nothing about them justifies anything else.
The adoption sequence matters as much as the target design, because a rewrite that delivers nothing for six months is the most common way these projects fail. A workable order is: first add an outbox to the service that most needs to publish reliably, which fixes real lost-event bugs immediately and requires no new mental model; then add one asynchronous consumer, which proves the pipeline end to end; then build one read model for the query that hurts most, which delivers visible performance; then, only if a context genuinely needs it, introduce event sourcing there; and finally introduce a saga when the first cross-service workflow actually appears. Each step is independently valuable and independently reversible.
Three things should exist before the second consumer is written, and they are the ones most often deferred. A schema and envelope standard, so every event carries an id, a type, a version, a correlation id, a causation id, and a timestamp from the very first event rather than being retrofitted across a log that already has millions of entries. Observability, meaning distributed tracing across the broker, per-consumer lag alerting, and dead letter monitoring that a human actually sees. And a clear statement of consistency expectations per user-facing surface, because the question of what the interface shows during the convergence window is a product decision that engineering should raise early rather than discover late.
| Bounded context | Write model | Read model | Integration | Why |
|---|---|---|---|---|
| Ledger and payments | Event-sourced | Projections rebuilt from the log | Events via the event store | Audit, regulation, and temporal correctness |
| Catalog and search | Relational, conventional | Elasticsearch documents | Outbox plus change data capture | Read workload is faceted search; history has no value |
| Orders | Relational with a status trail | Denormalized order views | Outbox | Reliable publication needed; full event sourcing not justified |
| Inventory reservation | Relational with reservations | Availability projection | Orchestrated saga | The workflow spans services and needs compensation |
| User preferences, content | Relational | The same tables | None | No fan-out, no history value, no read pressure |
Worked Example: A Single Order Traced Through the Whole Architecture
One order, followed from the HTTP request to the final projection, touching every pattern in the course exactly where its question was answered yes.
// 1. COMMAND arrives. Structural validation at the edge, authorization from
// context, invariant enforced inside the aggregate. (Lesson 14)
POST /orders { commandId: 'cmd-5510', items: [...], idempotencyKey: 'cmd-5510' }
// 2. WRITE + OUTBOX in one transaction. No dual write, so the event cannot be
// lost or become a phantom. (Lessons 19, 20)
BEGIN;
INSERT INTO orders (id, customer_id, status, total_cents) VALUES ('9f12', 'c-771', 'placed', 17700);
INSERT INTO outbox (aggregate_id, event_type, payload, headers)
VALUES ('9f12', 'OrderPlaced', {...},
{ correlationId: 'txn-9f12', causationId: 'cmd-5510' });
COMMIT;
// Response: 202 Accepted { orderId: '9f12', consistencyToken: 88214 }
// 3. RELAY publishes, keyed by aggregate id so per-order ordering holds.
// At-least-once: every consumer below is idempotent. (Lessons 3, 20)
// Debezium tails the WAL -> topic 'orders', key '9f12'. (Lesson 21)
// 4. FAN-OUT. Each consumer subscribes independently; the order service does
// not know any of them exist. (Lessons 1, 2)
// a) rm_order_detail projection -> denormalized read model (Lessons 10, 15)
// b) search indexer -> Elasticsearch document (Lesson 15)
// c) analytics loader -> warehouse rollup (Lesson 15)
// d) order fulfilment saga -> orchestrated workflow (Lessons 22, 23)
// 5. THE SAGA coordinates what spans services, with compensation before the
// pivot and retry-with-escalation after it. (Lessons 22, 23)
// reserveInventory -> capturePayment -> [PIVOT] dispatchShipment -> notify
// Payment fails -> release inventory -> cancel order -> notify customer.
// 6. THE LEDGER context, which IS event-sourced because audit requires it,
// appends PaymentCaptured to stream payment-p441 with an expected version,
// and its balance projections are folded from that log. (Lessons 6, 7, 10)
// 7. THE READ, moments later, carrying the consistency token so the user sees
// their own write rather than a stale view. (Lesson 16)
GET /orders/9f12?minPosition=88214
// 8. WHAT IS OBSERVABLE THROUGHOUT: correlationId 'txn-9f12' retrieves the
// whole flow, causationId reconstructs its exact tree, per-projection lag
// is alerted in events and seconds, and any unprocessable message lands in
// a dead letter queue a human watches. (Lessons 4, 16, 18)Real-World Examples
- Uber's engineering publications describe an architecture combining Kafka as the event backbone, change data capture from transactional databases, materialized read models for latency-sensitive queries, and Cadence for long-running workflows, applied selectively across domains rather than uniformly. It is a working example of the non-uniform outcome this lesson argues for, with different domains sitting at different points on the spectrum according to their actual requirements.
- The industry's accumulated retrospectives on event-driven adoption converge on a consistent set of lessons: teams that started with a broker and a full event-sourced rewrite usually struggled, while teams that began by fixing reliable publication with an outbox, added one consumer, and grew the architecture incrementally generally succeeded. The recurring theme is that the patterns are individually valuable and only collectively expensive, which is why incremental adoption is both lower risk and faster to deliver value.
Review Questions & Answers
Because it fixes a real, present, and usually invisible bug rather than enabling a future capability, and it costs almost nothing conceptually. Any service that commits and then publishes is already losing events, most often during deployments and broker incidents, so adding an outbox stops an active source of data loss immediately. It requires no new mental model for the team, no eventual consistency to explain to product, no new store, and no change to any consumer. It is also a prerequisite for everything that follows, since projections, sagas, and downstream consumers are all unreliable if the events that drive them can vanish.
The benefits of event sourcing are concentrated in contexts where history has genuine value, a ledger, a regulated workflow, a claims or policy engine, while its costs, projection-only querying, versioning and upcaster discipline, correction handling, erasure mechanics, and onboarding burden, apply uniformly to every context it is used in. Applying it to user preferences, content pages, and administrative modules therefore pays the full price for no return, and it makes the system harder for every engineer who joins. Consistency of approach is worth something, but it is worth far less than fit, and the right consistency is in the decision rule applied to each context rather than in the answer it produces.
An event envelope standard with event id, type, version, correlation id, causation id and timestamp; observability comprising distributed tracing across the broker, per-consumer lag alerting, and dead letter monitoring; and an agreed statement of consistency expectations for each user-facing surface. The timing matters because all three are cheap to establish and expensive to retrofit. Once a log contains millions of events without correlation ids, no amount of later work makes that history traceable, and the first incident that requires reconstructing causality is exactly when it will be needed. The second consumer is the threshold because that is the point at which causality genuinely spans processes.
The event sourcing question. A wrong yes on integration events costs an unnecessary broker and some operational overhead, and can be unwound. A wrong yes on CQRS costs redundant read models that can be deleted. A wrong yes on sagas costs a workflow engine for a process that could have been a transaction, which can be simplified later. A wrong yes on event sourcing, however, is encoded permanently in every stream already written: the aggregate boundaries, the event shapes, and the absence of any conventional current-state store cannot be undone without rewriting history or maintaining a compatibility layer forever, and the team lives with the query, versioning, and correction costs for the life of the system.
Course complete: you can now choose deliberately among event-driven integration, event sourcing, CQRS, the outbox and change data capture, and sagas, and justify each choice against the specific problem it solves.