Scrivio Interview library
ConceptIntermediate6 min read · updated 12 November 2026

What does event sourcing mean, and how do snapshots, projections and upcasting work in an event-sourced service?

Event sourcing stores an entity's state as the ordered sequence of events that happened to it, and rebuilds current state by replaying them. Snapshots save the state at some point so replay starts there instead of at the first event, projections build read models from the stream and can be rebuilt by replaying, and upcasting converts old event versions into the current shape when they are read, because stored events are never changed. It gives a complete audit history but makes schema evolution, deletion and ad hoc queries harder.

Why this question is asked

Most systems store only the latest state: the account table says the balance is 150, and how it got there is lost unless we keep a separate audit log. Event sourcing turns that around and keeps the history as the source of truth. Interviewers ask about it because it changes how a service is built in every part, from writes and reads to schema changes, and the follow-up terms, snapshots, projections and upcasting, show whether we have worked with it or only read about it. In this answer, we will recap the idea with a bank account, see how state is rebuilt, then go through snapshots, projections and upcasting, and finish with what event sourcing costs.

1A Quick Recap of Event Sourcing

In event sourcing, every change is recorded as an event, a fact in the past tense: AccountOpened, MoneyDeposited, MoneyWithdrawn. The events for one account form its stream, stored in order in an event store, which can be a dedicated product or a table with stream id, version and payload. Events are only ever appended; they are not updated or deleted.

The current state is not stored as the source of truth. To get it, we load the stream and apply each event in order to an empty object. To change state, we load the aggregate this way, check the business rules, and append new events with the expected version, so two writers cannot both append version 4.

Java
record MoneyDeposited(UUID accountId, long cents) {}
record MoneyWithdrawn(UUID accountId, long cents) {}
class Account {
long balance; long version;
void apply(Object e) {
switch (e) {
case MoneyDeposited d -> balance += d.cents();
case MoneyWithdrawn w -> balance -= w.cents();
default -> {}
}
version++;
}
}
Account a = new Account();
for (Object e : store.load(accountId)) a.apply(e); // deposit 100, deposit 80, withdraw 30
System.out.println(a.balance); // 150
System.out.println(a.version); // 3
store.append(accountId, 3, List.of(new MoneyWithdrawn(accountId, 50))); // expected version 3
// a concurrent writer that also expected version 3 now fails with a conflict

Notice that the balance of 150 exists only in memory. What is stored are three facts, and we can always ask what the balance was after the second one.

2Snapshots: Not Replaying Ten Thousand Events

An account with ten years of card payments might have fifty thousand events. Replaying all of them on every command is slow. A snapshot is the aggregate's state saved at a particular version, for example every 500 events. To load the account, we read the latest snapshot and then only the events after its version.

Java
Snapshot s = snapshots.latest(accountId); // balance 9_420, version 49_500
Account a = Account.from(s);
for (Object e : store.loadAfter(accountId, s.version())) a.apply(e); // only 120 events
System.out.println(a.version); // 49_620
Step throughLoading an event-sourced aggregate
  1. Latest snapshotstate at version 49,500
  2. Events after the snapshotversions 49,501 to 49,620
  3. Upcastersconvert old event versions on read
  4. Apply in orderrebuild current state in memory
  5. Run the commandcheck rules, append new events

5 layers, from the top down. Step through them one at a time.

A snapshot is a cache, not a source of truth. If its format changes or it has a bug, we delete it and rebuild it from events. That is why snapshots should be optional: the code must still work, just more slowly, with no snapshot at all.

3Projections: Read Models Built From the Stream

Because the event store holds streams per aggregate, it is poor at questions like 'all accounts with a balance over 10,000'. Projections answer them. A projection subscribes to the events, all of them or a category, and maintains a read model such as an account_balance table or a search index. Each projection tracks the position up to which it has processed events.

The powerful part is that a projection can be rebuilt. If we need a new report, or we find a bug in an existing projection, we create a fresh read model and replay the whole history into it. The new report then contains data from years before it existed, which is impossible with state-based storage. The cost is the rebuild time, which grows with history.

4Upcasting: Changing Events That Cannot Change

Business changes, so event shapes change. Suppose MoneyDeposited version 1 had a single amount field in euros, and version 2 has cents and currency. We cannot rewrite the stored version 1 events, because the history is meant to be immutable and may already be copied to other systems. Instead, an upcaster converts old versions into the current shape as they are read, so the rest of the code only knows version 2.

Java
// stored: {"type":"MoneyDeposited","v":1,"amount":12.5}
JsonNode upcast(JsonNode e) {
if (e.path("type").asText().equals("MoneyDeposited") && e.path("v").asInt() == 1) {
ObjectNode n = ((ObjectNode) e.deepCopy());
n.put("cents", Math.round(e.path("amount").asDouble() * 100)); // 1250
n.put("currency", "EUR"); // the only currency in v1
n.remove("amount");
n.put("v", 2);
return n;
}
return e;
}
// read as: {"type":"MoneyDeposited","v":2,"cents":1250,"currency":"EUR"}

Upcasters can be chained, v1 to v2 to v3, and they must stay in the codebase for as long as old events exist, which for a ledger may be forever. That is a long-term cost of every event change.

5What Event Sourcing Gives and What It Costs

The benefits are a complete audit history by construction, the ability to answer temporal questions ('what was the balance on 31 March?'), new projections built from the full past, and a natural fit with publishing events to other services.

The costs are just as concrete. Schema changes need upcasters forever. Deleting personal data conflicts with immutable events, so we need techniques like crypto-shredding. Ad hoc queries need projections first, and rebuilding them takes time. And fewer developers have real experience with it, so mistakes in aggregate boundaries or event design are common and expensive to undo because the events are kept.

6Follow-up questions

How often should we take snapshots?

Only as often as load time requires. Many aggregates have a few dozen events and never need one. When we measure that loading is slow, we snapshot every few hundred events or on a schedule, and we keep the code working without snapshots so they can be dropped and rebuilt after a change.

Can we fix a wrong event that was stored?

We do not edit it. We append a correcting event, such as a reversal, so the history shows both the mistake and the correction, exactly as an accountant would. For a bug in how events were interpreted, we fix the projection or upcaster and rebuild.

Is Kafka a good event store?

Kafka is good for distributing events, but as the source of truth for aggregates it lacks efficient loading of one entity's stream and an atomic check of the expected version on append. Most teams use a database table or a dedicated event store for the aggregates and publish to Kafka for other consumers.

7Conclusion

In this answer, we saw that event sourcing keeps the sequence of events as the source of truth and rebuilds state by replaying them, with an expected version on append to prevent conflicting writes. Snapshots shorten replay by saving state at a version, projections build rebuildable read models from the stream, and upcasters convert old event versions when reading because stored events never change. It gives full history and temporal queries, at the price of harder schema evolution, deletion and querying.

What to say in the interviewAbout 80 seconds aloud

Open with

In event sourcing we store every change as an event in an append-only stream per aggregate, like MoneyDeposited and MoneyWithdrawn for an account, and we get the current state by loading the stream and applying the events in order.

Then, if they want more

When we write, we append new events with the expected version, so concurrent writers conflict instead of overwriting each other. Snapshots are an optimisation: we save the state at, say, version 49,500 and on load replay only the events after it. They are a cache we can always throw away and rebuild.

Projections subscribe to the events and build read models for queries, and because the history is kept, we can rebuild any projection or create a new one from the full past.

Upcasting handles schema change: stored events are immutable, so when an event's shape changes, an upcaster converts old versions to the current shape as they are read, and those upcasters stay as long as the old events do. The big benefit is a complete audit trail and temporal queries.

The costs are schema evolution forever, difficulty deleting personal data, needing projections for every query, and a smaller pool of people who know the pattern well.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does event sourcing mean, and how do snapshots, projections and upcasting work in...": https://scrivio-interview-library.netlify.app/spring-boot/event-driven-patterns/17041a1055/