What Is Event Sourcing?
Event sourcing is an architectural pattern where every change in application state is stored as an immutable event, and the current state is derived by replaying these events.
When to Use
Event sourcing is used in systems requiring an audit trail, financial transactions, e-commerce order tracking, and distributed systems where microservices must stay consistent through shared events.
Example
Instead of saving just a bank account balance, each deposit or withdrawal is stored as an event, and the balance is calculated by replaying them.
Want to strengthen your interview prep?
Explore Grokking System Design Fundamentals, Grokking the System Design Interview, Grokking Database Fundamentals for Tech Interviews, or Mock Interviews with ex-FAANG engineers.
Why Is It Important
It guarantees a complete history of changes, enabling debugging, compliance, and the ability to rebuild past states or run time-based queries.
Interview Tips
Explain event sourcing with a simple analogy (like a ledger).
Highlight its main benefit (auditability) and main challenge (complexity). Be ready to contrast it with CRUD-based storage.
Trade-offs
You gain reproducibility and history, but pay in higher storage, complexity, and potential performance issues when replaying long event streams. Snapshots are often used to optimize.
Pitfalls
Common mistakes include confusing event sourcing with event-driven messaging, treating it as simple logging, and ignoring schema evolution or replay performance costs.
GET YOUR FREE
Coding Questions Catalog
$197

$78
$78