CQRS (Command Query Responsibility Segregation) 00:00:01 The ticket printer and the departures board At a travel desk the clerk accepts or rejects a booking under business rules. A departures board answers many simple questions about accepted bookings. Command Query Responsibility Segregation gives those jobs distinct models. An incoming command asks the order owner to create an order with two items and a total of one hundred fifty. It applies the business rules and returns an event. OrderCreated for ORD-001 is saved with a version check. The command is done. The projection writes a row that is ready to show. This example stores events and projects them into a display. CQRS itself only separates command and query responsibilities. It can be implemented without event sourcing or separate physical databases. 00:00:49 Give the board the shape readers need A traveler wants one complete order. Instead of reconstructing every decision at query time, the read model stores the relevant display fields together under the order identifier. GetOrderById for ORD-001. The order page has its own read model. One lookup by key. Id, status, total and items A and B come back in one piece. A second screen can have a different projection. Budget the storage, write amplification and operational burden of building and repairing each view before adding one for every conceivable query. 00:01:26 The customer looks up the booking immediately The ticket printer hands back a position that proves how far the write side has reached. If the board has processed only the preceding position, the new order may temporarily be absent. The user receives position 42. Show my order, at least as of 42. The new order is in the list. If the projection is stuck, the page shows "processing" instead of nothing. Pass a minimum acceptable position when read-your-own-write matters. The query can wait within a deadline, read an authoritative path, or explicitly report that processing is still in progress. 00:02:02 Count the same sale after a missing acknowledgment A projection adds the order to revenue and saves its input position. The broker delivers the same event again after losing an acknowledgment. Updating an unguarded counter would double the displayed total. It adds 150 to the revenue. Revenue 150 and position 7 are saved together. The acknowledgement was lost, so the broker sends it once more. Revenue stays at 150. Without the check it would be 300. Keep the progress marker and the derived state together, or use an equivalent idempotent update. For multiple input partitions, the progress boundary must represent all relevant positions. 00:02:42 Rebuild a better board while the old one runs The old projection accidentally counted cancellations. A corrected projection reads the retained event history into a separate store, catches up, and replaces the serving view after validation. The view counted cancelled orders. The events are still right. A fixed projection reads all events from the first one. The new view reaches the latest event. Queries use the new view. The old one is deleted. Check totals and domain invariants at the same input position. Command correctness, view freshness and rebuildability are separate promises, and a complete CQRS design states all three.