CQRS at Rung 4: Asynchronous Read Models

CQRS at Rung 4: Asynchronous Read Models An architecture diagram generated by Archify. Client · commands and queries · Architecture component Client commands and queries Command API · intent, not rows · Architecture component Command API intent, not rows Write Model · upholds invariants · Architecture component · domain entities Write Model upholds invariants domain entities Write Store · normalised for writes · Architecture component · the truth Write Store normalised for writes the truth Projection Pipeline · lag lives here · Architecture component Projection Pipeline lag lives here Denormalised Read Tables · Architecture component Denormalised Read Tables Search Index · Architecture component Search Index OLAP / Reporting · Architecture component OLAP / Reporting Query API · hand-written SQL, no ORM graph · Architecture component Query API hand-written SQL, no ORM graph command commit change events query response, possibly stale Legend Backend Database Message bus External

Write side

  • • Commands carry intent and uphold invariants
  • • The write store is the single answer to "which store is the truth"
  • • Fully consistent up to the moment of commit

The dashed edges

  • • Eventual consistency enters the product here
  • • Read-your-own-writes breaks first: return the write result instead of re-reading
  • • Rebuild is an operational procedure, not a button

Read side

  • • Queries bypass the domain model for the shape the screen needs
  • • Every new field must be added to every projection
  • • Below this rung, a read replica or rung 2 code split is the right answer