Design an event-sourced order management system for an e-commerce platform
cs-sys-002
Your answer
Answer as you would in a real interview — explain your thinking, not just the conclusion.
Model answer
Event sourcing stores the full history of domain events — OrderPlaced, PaymentAuthorized, ItemShipped — rather than current state. The Order aggregate rebuilds itself by replaying its event stream from EventStoreDB or Kafka. Read models (order status, inventory counts) are maintained by projections that consume events asynchronously — this gives eventual consistency. Key benefits: complete audit trail, ability to rewind to any past state, and new projections added without schema migration. Challenges: event versioning (events are immutable, use upcasters for schema evolution), snapshot performance (rebuilding from scratch is slow for high-frequency aggregates), and UI complexity around eventual consistency.
Follow-up
How do you handle a saga — for example, reserving inventory atomically with placing an order when the inventory service is separate?