System Design Problem

Design an Event Sourcing System

Commonly Asked By:StripeSquareUberNetflix

  • Append events: Persist all application state changes as an immutable, ordered stream of events rather than direct updates.
  • Rebuild state: Reconstruct the current state of any domain aggregate at runtime by replaying its complete sequence of events.
  • Event replay: Replay events dynamically to repair corrupt projections, bootstrap new read-optimized views, or fix application bugs.
  • Materialized snapshots: Periodically cache aggregate states to optimize read paths and avoid replaying millions of events.
  • Dynamic projections: Build and update multiple independent, read-optimized projection stores from the single unified write stream.
  • Temporal queries: Enable seamless time-travel capability to query the exact state of any aggregate at any past timestamp.
  • Schema evolution: Support robust schema versioning strategies to upcast historical event structures smoothly.
  • Pub/Sub streaming: Allow downstream microservices to subscribe to aggregate streams reactively.

The write path handles incoming commands by validating them against the current domain aggregate state (assembled using snapshots and events). Validated commands write immutable events to the Event Store (PostgreSQL). Change Data Capture (CDC via Debezium) forwards events to Kafka to push them down to projection engines, maintaining eventual consistency in read databases.

Loading...