6.5. Event Sourcing and CQRS
Event sourcing stores not the current state but the full sequence of changes that produced it — an append-only log of facts from which any past state can be reconstructed and any new view can be derived. Paired with CQRS, which splits the write model from the read model, it enables audit, replay, and independently scalable reads. The cost is real: eventual consistency between write and read sides, event schema evolution, and the operational weight of an ever-growing log. This chapter covers the pattern, its projections and snapshots, and when the power is worth the complexity.
Topics Covered
Section titled “Topics Covered”- 6.5.1. Event Sourcing: The Event Chain Instead of State: Introduces event sourcing, storing the full sequence of state changes instead of just the current state.
- 6.5.2. Event Store Design: The Append-Only Log: Covers designing the append-only event store and its optimistic-concurrency and streaming guarantees.
- 6.5.3. CQRS: Separating Read and Write Models: Explains CQRS, separating the write model from independently scalable, query-optimized read models.
- 6.5.4. Projections: Building Read Models from Events: Covers projections that build read models by replaying the event stream into query-friendly shapes.
- 6.5.5. Event Versioning and Schema Evolution: Explains event schema evolution and upcasting strategies for a log that must be readable forever.
- 6.5.6. Snapshots: Optimizing Long Event Chains: Covers snapshots that bound the replay cost of long event chains without losing the full history.