Real-World Production Deep Dives: Event Sourcing and CQRS

โš ๏ธ Not yet source-checked. These case studies summarize public engineering posts and talks, and some details may be simplified or wrong. Before you repeat a specific number or design in an interview, check it against the company's own write-up. Found an error, or a source that confirms a section? Add it to the tracking issue. Sourced fixes are the most welcome contribution here.

Deep-dive architectural dissections of how Uber and Netflix implement Event Sourcing and Command Query Responsibility Segregation (CQRS) to manage complex entity lifecycles, auditing, and high-performance queries.


๐Ÿš™ Deep Dive 1: How Uber Uses Event Sourcing & CQRS (The Trip Lifecycle Engine)

1. Production Context & Scale

2. The Core Problem at Uber Scale

3. Uber's Architecture: Immutable Trip Event Sourcing

[ Rider App / Driver App / GPS / Payments ]
                     โ”‚
                     โ–ผ
             [ Command Handler ]
  โ”œโ”€โ”€ Validates Business Invariants
  โ””โ”€โ”€ Rejects Invalid Commands (e.g. Cannot complete unstarted trip)
                     โ”‚
                     โ–ผ (Appends Immutable Event)
        [ Immutable Event Store (MySQL / Schemaless) ]
  โ”œโ”€โ”€ Event 1: TripRequestedEvent   (Timestamp: 10:00:01)
  โ”œโ”€โ”€ Event 2: DriverAssignedEvent  (Timestamp: 10:01:15)
  โ”œโ”€โ”€ Event 3: DriverArrivedEvent   (Timestamp: 10:04:22)
  โ”œโ”€โ”€ Event 4: TripStartedEvent     (Timestamp: 10:05:01)
  โ””โ”€โ”€ Event 5: TripCompletedEvent   (Timestamp: 10:28:44)
                     โ”‚
         CDC Pipeline via Apache Kafka
                     โ”‚
     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
     โ–ผ                               โ–ผ
[ Driver Payout Projection ]    [ Real-Time Active Trips Projection ]
(Aggregated for Accounting)     (Optimized in Redis for Map Rendering)

A. The Immutable Event Stream

B. CQRS: Decoupling Writes from Reads

Writing an event stream is fast, but querying "Find all active rides in Manhattan where driver rating > 4.8" by scanning millions of event streams is impossibly slow.


๐ŸŽฌ Deep Dive 2: How Netflix Uses Event Sourcing & CQRS (Studio Production & Asset Pipelines)

1. Production Context & Scale

2. The Core Problem

3. Netflix's Architecture: Keystone CQRS Asset Graph

[ Studio Asset Mutation ]
            โ”‚
            โ–ผ
[ Asset Command Service ]
            โ”‚ (Append Event: SubtitleUpdatedEvent)
            โ–ผ
[ Keystone Event Store ]
            โ”‚
            โ–ผ (Kafka Event Stream)
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ CQRS Projection Engine                        โ”‚
โ”‚                                               โ”‚
โ”‚  [ Title Asset Graph (Neo4j / Graph DB) ]     โ”‚
โ”‚  โ””โ”€โ”€ Recomputes Dependency Invalidation Tree โ”‚
โ”‚                                               โ”‚
โ”‚  [ Media Catalog Read Model (ElasticSearch) ] โ”‚
โ”‚  โ””โ”€โ”€ Powers Studio Search & UI Dashboards     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

A. Snapshotting for Fast State Reconstruction

B. Schema Evolution & Versioning


โš–๏ธ Comparative Architecture Matrix

Architectural Dimension Traditional CRUD Architecture Event Sourcing + CQRS
Data Storage Mutable current state (UPDATE/DELETE) Immutable append-only log of historical events
Write Performance Slower; row-level locks & index maintenance Maximum throughput; sequential disk appends
Auditability Zero audit trail unless custom tables added 100% native audit log and temporal replay
Query Complexity Simple SQL joins on tables Requires dedicated materialized read projections
Consistency Strong ACID consistency across reads/writes Eventual consistency between Command and Query sides

๐ŸŽฏ System Design Interview Takeaways

  1. When to Propose Event Sourcing: Propose Event Sourcing for systems where historical audit trails and state transitions are legally or operationally critical (Fintech ledgers, E-commerce order tracking, Ridesharing trips, Collaborative document editing).
  2. Always Pair Event Sourcing with CQRS: Explain to interviewers that Event Sourcing requires CQRS because querying an event stream directly for complex reports is prohibitively expensive. Materialized read views solve the query problem.
  3. Mention Snapshotting & Upcasting: Address the two real-world operational challenges of Event Sourcing: use Snapshots to prevent long replay times, and use Upcasters to handle event schema evolution over time.

๐Ÿข Deep Dive 3: How Google Uses Event Sourcing (Google Docs Real-Time Collaboration)

1. Production Context & Scale

2. Architecture: Immutable Mutation Logs & Operational Transformation (OT)