Imad Muratspahic - CQRS + Event Sourcing
CQRS + Event Sourcing
A Practitioner's Handbook: Separate Write/Read Models for Library, Entitlements, and Reading History — With a Full Audit Trail for Purchases and DRM
Imad Muratspahic
Description
Most systems don't fail because of bad code — they fail because one database table ends up doing five jobs at once: fast checkout, flexible search, historical reporting, and an audit trail nobody actually trusts. This handbook shows you how to stop that from happening, using two patterns that pair naturally: CQRS (separating the model that accepts writes from the models that serve reads) and event sourcing (recording every fact as it happened, instead of only the latest snapshot).Built around one running example — Bindery, a digital reading platform — this isn't a survey of abstract patterns. You'll design bounded contexts and aggregates, build a real event store on PostgreSQL, write idempotent projections feeding Postgres, Elasticsearch, and Redis, and coordinate a multi-step purchase workflow with sagas and compensating actions. Then it goes further than most books on this topic: a tamper-evident, hash-chained audit trail that holds up in a payment dispute; DRM and device-limit enforcement modeled as events; crypto-shredding to reconcile immutable logs with the right to erasure; and a deliberate, incremental path for adopting this architecture inside a system you can't rewrite from scratch.Written for engineers who already know backend development and want to design — not just implement — systems where money changes hands, access rights matter, and someone, someday, will ask you to prove what happened.Inside: CQRS and event sourcing from first principles (including when not to use either one); a complete write model — commands, aggregates, event schemas built to survive years of change; read models done right — idempotent projections, safe rebuilds, polyglot read stores; a full purchase-to-access saga with timeouts and compensation; and the production concerns most books skip entirely — audit trails, DRM, eventual consistency in the UI, testing, observability, snapshotting, and the anti-patterns that show up eighteen months in.
