Distributed architecture patterns
On this page 9 topics
Overview
Topics
- CQRS
- event sourcing
- sagas
- orchestration
- materialized views
Learn first
4.5 h of practice (estimate)
Learning outcomes
- Apply full CQRS with separate write and read models, and say when CQRS-lite is enough.
- Explain event sourcing (event store, projections, snapshots, upcasting) and its operational costs.
- Build materialized views across service boundaries and manage their staleness.
- Choose between orchestration engines (e.g., Temporal, Camunda) and hand-built sagas.
Lessons
- 01Patterns as trade-offs, not upgrades
- 02CQRS in full
- 03Event sourcing
- 04Projections, snapshots, and upcasting
- 05Materialized views across services
- 06Workflow engines vs hand-built sagas
- 07Demo: modeling shipment tracking with and without event sourcing
- 08Demo: rebuilding a broken projection from the event store
Lab and exercises
Lab
SRB-001-LAB1 · Shipment tracking design
Outcomes: 1, 2, 3, 4 · Time: ~4.5 h
- List FulfillCo's shipment tracking requirements (status, history, corrections, partner feed, audit).
- Design option A: event-sourced; option B: state plus outbox.
- Estimate replay time, schema evolution effort, and storage for each at expected volume.
- Write an ADR with the decision, rejected option, and revisit triggers.
Acceptance: operational costs (replay time, schema evolution, storage) estimated for both options; ADR records the decision.
Exercises
| ID | Outcome | Task |
|---|---|---|
| SRB-001-EX01 | 1 | Your read screens need a different shape but load is light. Choose CQRS-lite or full CQRS and justify. |
| SRB-001-EX02 | 2 | List three costs of event sourcing for shipment tracking that a state table would not have. |
| SRB-001-EX03 | 2 | A v1 event lacks a field the new projection needs. Describe the upcasting approach. |
| SRB-001-EX04 | 3 | Shop shows carrier status from FulfillCo. Define acceptable staleness and the reconciliation job. |
| SRB-001-EX05 | 4 | Three workflows exist, each two steps with no timers. Engine or hand-built saga? Argue. |
| SRB-001-EX06 | 1 | Review a proposal to event-source the product catalog. Write a five-line critique. |
Show solutions
- EX01 CQRS-lite: SQL views or separate read classes on the same database; full CQRS adds a second store and lag for no needed gain.
- EX02 Replay time for rebuilds, permanent event schema and upcasting work, harder ad hoc queries and deletion of personal data.
- EX03 Add an upcaster mapping v1 to v2 with a default or derived value on read; do not rewrite history unless unavoidable.
- EX04 e.g. status within 30 s of the event, timestamp shown; a nightly job compares counts per status and repairs gaps by re-consuming.
- EX05 Hand-built with an outbox and state table: small, short, no timers; revisit if workflows grow.
- EX06 Catalog history is rarely business-critical, reads dominate, edits are simple; an audit history table suffices; propose a spike measuring need first.
Workplace evidence: a design where you chose a simpler pattern over a fashionable one and could show why.
Quiz
Outcomes: O1 CQRS · O2 event sourcing · O3 materialized views · O4 orchestration choice.
A self-check for you: nothing is graded, saved or sent anywhere. Choose an answer, then check it. You can try again as often as you like.
Practical part
Pattern-selection defense: present the ADR from SRB-001-LAB1 and defend it against challenges. Pass: 70% on the quiz and an ADR with costs estimated for both options.
Common mistakes
Event sourcing everything; projections nobody can rebuild; workflow engines adopted for one saga.
Assessment
Pattern-selection defense.
Workplace evidence
A design where you chose a simpler pattern over a fashionable one and could show why.
Career relevance
Architecture at scale (SRA-001).