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.

Start the course

1. Event Sourcing Concepts

Events as the source of truth, modeling, aggregates and event stores.

  1. What Event Sourcing Is — Store every change as an immutable event and derive state from them.
  2. Modeling Domain Events — Discover events with Event Storming and name them well.
  3. Aggregates and Consistency Boundaries — Where invariants are enforced and how commands become events.
  4. Event Store Design — Streams, global ordering, subscriptions and implementing a store on Postgres.
  5. 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.

  1. CQRS Explained — Separate the write model from read models — with or without event sourcing.
  2. Building Projections — Turn event streams into query-optimized read models reliably.
  3. Eventual Consistency in the UI — Keep users from seeing stale data right after they act.
  4. Replaying and Rebuilding Projections — Create new read models from history and fix bugs by replay.
  5. Snapshots — Speed up loading long-lived aggregates.

3. Evolution and Compliance

Versioning events, GDPR, integration events and technology choices.

  1. Event Versioning and Upcasting — Change event schemas without rewriting history.
  2. Personal Data, GDPR and Crypto-Shredding — Honor deletion requests in an append-only store.
  3. Domain Events vs Integration Events — What stays inside a service and what you publish to others.
  4. Event-Sourcing Technology Landscape — Frameworks and stores by stack.

4. Event Sourcing in Practice

Testing, process managers, auditing and performance.

  1. Testing Event-Sourced Systems — Given-when-then tests for aggregates and projections.
  2. Process Managers and Policies — React to events and coordinate long-running processes.
  3. Auditing, Debugging and Temporal Queries — Use history to answer 'what happened and why'.
  4. Performance and Scaling — Stream sizes, projection throughput and storage growth.

5. Capstone

Design an event-sourced ledger and evaluate whether to adopt event sourcing.

  1. Capstone: Event-Sourced Wallet Ledger — Design an event-sourced digital wallet with audit-grade history.
  2. Capstone: Should We Event-Source It? — Evaluate event sourcing for three systems and justify each decision.