Free course · 20 lessons · Advanced
Event Sourcing & CQRS
Model domains as events: event modeling, aggregates, event stores, CQRS and projections, eventual consistency in the UI, snapshots, versioning and upcasting, GDPR crypto-shredding, testing and when not to use it.
1. Event Sourcing Concepts
Events as the source of truth, modeling, aggregates and event stores.
- What Event Sourcing Is — Store every change as an immutable event and derive state from them.
- Modeling Domain Events — Discover events with Event Storming and name them well.
- Aggregates and Consistency Boundaries — Where invariants are enforced and how commands become events.
- Event Store Design — Streams, global ordering, subscriptions and implementing a store on Postgres.
- When Not to Use Event Sourcing — Recognize the cases where it adds cost without value.
2. CQRS and Projections
Separate reads from writes, build read models and handle eventual consistency.
- CQRS Explained — Separate the write model from read models — with or without event sourcing.
- Building Projections — Turn event streams into query-optimized read models reliably.
- Eventual Consistency in the UI — Keep users from seeing stale data right after they act.
- Replaying and Rebuilding Projections — Create new read models from history and fix bugs by replay.
- Snapshots — Speed up loading long-lived aggregates.
3. Evolution and Compliance
Versioning events, GDPR, integration events and technology choices.
- Event Versioning and Upcasting — Change event schemas without rewriting history.
- Personal Data, GDPR and Crypto-Shredding — Honor deletion requests in an append-only store.
- Domain Events vs Integration Events — What stays inside a service and what you publish to others.
- Event-Sourcing Technology Landscape — Frameworks and stores by stack.
4. Event Sourcing in Practice
Testing, process managers, auditing and performance.
- Testing Event-Sourced Systems — Given-when-then tests for aggregates and projections.
- Process Managers and Policies — React to events and coordinate long-running processes.
- Auditing, Debugging and Temporal Queries — Use history to answer 'what happened and why'.
- Performance and Scaling — Stream sizes, projection throughput and storage growth.
5. Capstone
Design an event-sourced ledger and evaluate whether to adopt event sourcing.
- Capstone: Event-Sourced Wallet Ledger — Design an event-sourced digital wallet with audit-grade history.
- Capstone: Should We Event-Source It? — Evaluate event sourcing for three systems and justify each decision.