System design interview

Event Sourcing vs State-Based Storage

MediumLocked55 min read

Compare event sourcing (store every state change) vs storing current state only; when the complexity is worth it.

system-designevent-sourcingarchitecture-patternsaudit

Start here

The problem in plain words

A support agent asks a simple question: "What was this customer's balance last Tuesday, before the adjustment?" If your database only stores "balance = 120", you cannot answer honestly. The old number was overwritten the moment the new one was saved.

There are two ways to store things. The usual way keeps only the current state: one row per account, updated in place. The other way keeps every change as a permanent fact: account opened, 100 deposited, 30 withdrawn, 5 adjusted. The balance is then worked out by adding the facts up.

The second way is called event sourcing. It answers "what was true last Tuesday?" easily, but it asks more of the engineers who run it. The skill here is knowing when that extra effort is worth it.

Words you will meet

State-based storage (CRUD)
Keeping only the current values in rows. An update overwrites the old value.
Event
A fact that something happened, such as "Deposited 100". Events are never edited or deleted after they are saved.
Event sourcing
Storing the ordered list of events as the source of truth. The current state is calculated from them.
Aggregate
One thing the events belong to, such as a single account or order. Its events form one story.
Replay / fold
Reading the events from the start, in order, and applying each one to rebuild the state at any chosen moment.
Projection (read model)
A ready-made table built from events, shaped for fast reading, such as the current balance per account.
CQRS
Separating how you write (append events) from how you read (query projections). It is the usual companion of event sourcing.
Audit trail
A trustworthy record of who did what and when.
Idempotent append
Saving the same event twice does not create two events, usually because each event has a unique id.
What state-only storage cannot tell you
asks120Support agentasks about lastTuesdayAccount rowbalance = 120Answer?no history, only aguess
Press Play to watch it move

Each arrow is one thing happening. Play it step by step, or read the list below.

  1. 1.The agent asks what the balance was on Tuesday, before the adjustment.
  2. 2.The row only holds today's value. The earlier value was overwritten when the balance changed. Unless someone kept a history table, the honest answer is "we cannot know".

The numbers, as things you can picture

  • A mid-size transactional domainThink orders or a ledger for one company, not a global social network. That keeps event volumes manageable.

What the interviewer wants

Compare the two styles with a concrete example, show how current state is derived from events, name the costs, and give a clear rule for when event sourcing is worth it.

Interview framing

The interviewer asks you to compare event sourcing (store every state-changing event) with traditional state-based storage (current state only). They want criteria for when the complexity is worth it, especially for financial systems, audit trails, and time travel.

Background from first principles

Most applications store rows that mean "what is true now."

accounts(account_id, balance, updated_at)

An update sets balance = 120. The previous balance is gone unless you built separate audit tables.

That model is simple and fast for "show me the account." It fails a different question: "What was the balance last Tuesday before the adjustment, and which operations produced it?"

Event sourcing answers by storing facts about what happened, not only the latest summary.

Events: FundsDeposited(+50), FundsWithdrawn(-20), Adjustment(+5)
Current balance = fold(events)

You need this distinction before arguing tools. Event sourcing is not "we use Kafka." Kafka can carry messages for many architectures. Event sourcing is a persistence model: the append-only event log is the source of truth for an aggregate, and current state is derived.

Full problem statement

Contrast event-sourced vs state-based designs for a mid-size transactional domain (orders or ledger). Cover:

  • How to derive current state from events.
  • Audit and time-travel benefits.
  • Operational costs: replay, event schema evolution, storage growth.
  • Consistency and idempotency of appends.
  • Consumer rebuild lag for projections.
  • A recommendation framework for when event sourcing is worth it.

What "good" looks like

You start with a support or audit question that current-state rows cannot answer. You define both models. You show a small ledger example. You introduce projections/read models and snapshots. You discuss compensating events instead of rewriting history. You give clear "when not" criteria. You handle GDPR as a thoughtful follow-up, not a shrug.

Clarifying questions

  • Do regulators or finance require reconstructable history?
  • Is current-state read latency critical for user-facing paths?
  • How many event types evolve per year?
  • Is the team ready to own replay tooling and versioned events?
  • Do we need multiple read models from one fact stream?

Scale prompts

  • Estimate events per account per year and storage vs overwrite-in-place rows.
  • Replay time without snapshots for hot aggregates.
  • Projection lag SLOs for user-facing reads.

Out of scope

  • Turning every CRUD entity into events "for purity."
  • Equating any message bus with event sourcing.
  • Designing a global social graph event store unless the domain needs it.

Expanded domain story

Imagine a payments company. Accounts hold balances. Ops adjusts fees. Support investigates disputes. Auditors ask for reconstructable histories. Product wants a mobile balance that feels instant.

If you only store current balance, dispute investigations become archaeology across incomplete logs. If you event-source every profile font-color preference, you drown in ceremony.

Your interview answer must separate aggregates that need forensic history (ledger, reservations) from entities that need boring CRUD (display preferences).

Constraints to assume if not given

  • Mid-size transactional domain, not a global social graph.
  • Read latency for current balance matters for mobile.
  • Some regulatory reconstructability is likely for money movement.
  • Team has not operated an event store before; mention ramp cost.

What to write on the board early

1. Questions only events can answer. 2. Questions current state answers fine. 3. Recommendation per aggregate type, not one hammer for the whole company.

Background concepts the interviewer expects you to teach

Before naming patterns, explain:

1. Current state rows answer "what is true now?" 2. Event logs answer "what happened, in order?" 3. Derived read models answer "how do we show this quickly?"

Many candidates jump to Kafka. Strong candidates explain that the source of truth choice drives everything else: auditing, GDPR tension, replay tooling, and team complexity.

Full prompt restatement you can use

"We need to choose persistence for money movement and related workflows. Compare storing only current state versus storing every state change as events. Recommend when the complexity of event sourcing is justified, and explain projections, snapshots, corrections, and erasure pressures."

Good vs weak answers

Weak: "Event sourcing is always better for microservices."

Good: "Event sourcing pays for reconstructable history on ledger aggregates. CRUD remains right for simple profile state. Here is how projections keep reads fast, and here is how we correct errors without rewriting history."

Estimation prompts to volunteer

  • Events per aggregate per year.
  • Replay time with and without snapshots.
  • Projection lag SLO for mobile balance reads.
  • Storage growth vs operational benefit for audit.

Explicit out of scope

  • Rewriting the entire company data model in one quarter.
  • Exactly-once claims without idempotency design.
  • Using the analytics lake as the only operational event store without durability and ordering guarantees per aggregate.