VAYULearn
Colour theme
Investigate a failure
VAYU Learn

Kafka & Streaming

Event Sourcing Explained

What It Is, What It Isn’t, and When It Actually Works (With Real Examples)

Kafka & StreamingData Architecture & Reliability

TL;DR

  • Event Sourcing means events are the source of truth, not tables
  • State is derived, not stored as primary truth
  • You trade write simplicity for read complexity
  • Event Sourcing is powerful for auditability, replay, and correctness
  • It is not a default architecture — misuse causes permanent pain

If you don’t need replay, audit, or temporal correctness, do not use Event Sourcing.


Introduction - Why Event Sourcing Is So Often Misunderstood

Event Sourcing is usually introduced like this:

“Instead of storing state, store events.”

That explanation is technically true — and practically useless.

Because the real shift is not what you store, but how you reason about time, truth, and change.

Most failed Event Sourcing systems fail because:

  • teams wanted “Kafka everywhere”
  • databases were blamed for modeling problems
  • replay was promised but never exercised
  • read models were an afterthought

Event Sourcing is not a data engineering trick.
It’s a system design decision with irreversible consequences.

So let’s get precise.

Audience note:
This article assumes familiarity with distributed systems, immutable logs, and asynchronous processing.
If concepts like eventual consistency, idempotency, or replay semantics are unfamiliar, Event Sourcing is premature — and this post is a warning, not a tutorial.

1. What Event Sourcing Actually Means

Definition (engineering-grade):

Event Sourcing is a pattern where all state changes are captured as immutable, append-only events, and current state is derived by replaying those events.

Key implications:

  • Events are facts (“OrderPlaced”, not “OrderStatus=PLACED”)
  • Events are immutable
  • State is reconstructable
  • Time is a first-class concept

You don’t “update” data.
You record what happened.


2. Events vs State (The Core Mental Shift)

Traditional State-Based System

orders table
-------------
order_id
status
amount
updated_at

You overwrite truth.

You lose:

  • how you got here
  • intermediate states
  • intent

Event-Sourced System

OrderCreated
ItemAdded
ItemAdded
PaymentAuthorized
OrderShipped

You never lose history.

State is just a projection.

This is the fundamental difference.


3. What Event Sourcing Buys You (Real Benefits)

Event Sourcing is expensive.
You only pay that cost if you need these benefits:

✅ Auditability

You can answer:

  • who changed what
  • when
  • why

Without triggers. Without CDC hacks.

🔁 Replayability

You can:

  • rebuild state after bugs
  • backfill new projections
  • simulate alternate logic

Replay is not optional — if you don’t test replay, your system is lying.

⏱️ Temporal Queries

You can answer:

  • “What did we believe on March 3rd?”
  • “What was the balance before the correction?”

State-based systems cannot do this reliably.


4. What Event Sourcing Does NOT Give You

Let’s kill myths.

Event Sourcing does not:

  • make systems simpler
  • remove the need for schemas
  • eliminate migrations
  • improve performance by default
  • replace databases

In fact:

  • reads become harder
  • debugging moves from SQL to timelines
  • mistakes are permanent

If you want CRUD with Kafka flavor — walk away.

Event Sourcing vs CDC vs Log-Based Systems

Table 1 - Event Sourcing, CDC, and Log-Based Systems Solve Different Problems
Although these patterns all involve logs or events, they differ fundamentally in what they treat as truth, whether intent is preserved, and how safely state can be replayed in production systems.

Key takeaway:
CDC captures what changed.
Event Sourcing captures why it changed.

If intent matters, CDC is insufficient.

Even when enriched or paired with outbox patterns, CDC reflects database side effects, not first-class domain intent — which limits safe replay for business logic.


5. The Canonical Event Sourcing Architecture

Command
↓
Validation / Business Logic
↓
Event Store (Append-only)
↓
Event Consumers
↓
Read Models / Projections

Key rules:

  • Commands express intent
  • Events express facts
  • Read models are disposable
  • Event store is sacred

Never let queries touch the event store directly.

Clarification:
The event store must never be used as a business query surface.
Operational reads (debugging, tooling, forensic analysis) are acceptable — but application logic must never depend on querying raw events.
If production correctness depends on querying the event log directly, your projections are incomplete or wrong.

6. Real-World Example: Order Management System

Domain

E-commerce orders with audit and refunds.

Events

OrderCreated
ItemAdded
ItemRemoved
PaymentAuthorized
PaymentFailed
OrderCancelled
OrderShipped
RefundIssued

Event Store (Logical View)

{
"order_id": "123",
"event_type": "ItemAdded",
"payload": {
"sku": "SKU-42",
"quantity": 2
},
"timestamp": "2026-02-01T10:12:00Z"
}

Append-only. No updates. Ever.


7. Building State via Projections

Projection: Order Summary

order_id
current_status
item_count
total_amount
last_updated

Derived by replaying events in order.

If projection logic is wrong:

  • delete projection
  • fix code
  • replay events

If you can’t do this safely, your Event Sourcing implementation is broken.


8. Event Versioning (Where Systems Go to Die)

Events live forever.
That means schemas must evolve without breaking history.

Rules:

  • never delete fields
  • only add optional fields
  • never change meaning
  • version explicitly when semantics change

Bad:

"status": "SHIPPED"

Good:

"shipment": {
"carrier": "UPS",
"shipped_at": "..."
}

Event versioning is forever work.

Event Store Storage Reality

Event stores are:

  • append-heavy
  • write-optimized
  • read-cold
  • retention-sensitive

Common choices:

  • Kafka (with compaction + tiered storage)
  • Pulsar (long-term retention)
  • Purpose-built stores (EventStoreDB)

Anti-pattern:

  • Treating OLTP databases as infinite event logs

If your event store can’t sustain replay years later, it is not a real event store.


9. The Hard Problems Nobody Mentions

❌ Debugging

You debug timelines, not rows.

❌ Read Amplification

One write → many projections → many stores.

❌ Storage Growth

Events never die. You must plan compaction or snapshots.

❌ Cognitive Load

New engineers struggle — a lot.

Event Sourcing increases organizational complexity, not just system complexity.

9.1 Cross-Aggregate Workflows (Where Pain Multiplies)

Event Sourcing is easiest within a single aggregate.
It becomes dangerous across multiple aggregates.

Problems you cannot avoid:

  • no atomic transactions across aggregates
  • eventual consistency is mandatory
  • “exactly-once” guarantees are illusions
  • failures become state machines, not errors

Real systems require:

  • process managers / sagas
  • explicit compensation events
  • replayable workflow state

Process managers are event-sourced systems themselves.
If they can’t be replayed deterministically, your workflow correctness is accidental.

If your domain requires strong cross-aggregate invariants, Event Sourcing will increase complexity — not reduce it.

9.2 A Real Failure Pattern (Seen in Production)

A common failure mode:

  • Teams store events
  • Build projections
  • Never rehearse replay
  • Schema evolves silently
  • Six months later, replay is impossible

What happens next:

  • Snapshots become “temporary truth”
  • Old events become unreadable
  • Event store turns into write-only history
  • Event Sourcing collapses into expensive logging

Lesson:
If replay is not routinely exercised, your system is not event-sourced — it is event-archived.

Production Failure Example:

A team introduced a new optional field to an event without versioning.
Old consumers silently ignored it.
New projections assumed it existed.

Six months later, a full replay was required.
Half the projections failed.
The other half produced inconsistent state.

Result:

  • replay was abandoned
  • snapshots were promoted to truth
  • Event Sourcing degraded into append-only logging

The system never recovered.


10. Snapshots (Performance Escape Hatch)

To avoid replaying millions of events:

Snapshot @ Event #50000
+
Events 50001 → now

Rules:

  • snapshots are optimizations
  • snapshots are disposable
  • event log is still truth

Never treat snapshots as authoritative.

Snapshot Safety Rules (Non-Negotiable):

  • snapshots must be rebuildable from genesis
  • snapshot schema version must be explicitly stored
  • snapshot + replay must produce identical projections
  • snapshots must never contain derived business logic

If you cannot delete all snapshots and safely replay from the event log, snapshots have become shadow truth — and your system is already broken.

How Event-Sourced Systems Should Be Tested

Traditional testing:

  • assert final state

Event Sourcing testing:

  • assert event sequences
  • assert idempotency
  • assert projection determinism

Recommended tests:

  • Given events → expect new events
  • Replay from genesis → same projections
  • Versioned event compatibility tests
  • Snapshot + replay equivalence tests

If you only test projections, you are testing symptoms — not truth.


11. When Event Sourcing Is the Right Choice

Use Event Sourcing when:

  • correctness > convenience
  • auditability is mandatory
  • state reconstruction matters
  • workflows are long-lived
  • business logic evolves often

Industries that benefit:

  • finance
  • payments
  • trading
  • logistics
  • compliance-heavy domains

12. When You Should NOT Use Event Sourcing

Do not use Event Sourcing when:

  • CRUD is enough
  • state is simple
  • latency is critical and reads dominate
  • team lacks distributed systems maturity
  • replay has no business value

Event Sourcing is a scalpel.
Most systems need a screwdriver.


Mental Model to Lock In

  • Events = facts
  • State = opinion
  • Projections = convenience
  • Replay = truth test

If replay scares you, you’re not ready.


Event Sourcing Readiness Checklist

Before choosing Event Sourcing, answer yes to all:

  • Do we need full audit history?
  • Do we need temporal correctness?
  • Can we support replay operationally?
  • Can we version schemas forever?
  • Can we tolerate complex reads?

If any answer is “no” — don’t do it.


Conclusion — Event Sourcing Is a Commitment

Event Sourcing is not an optimization.
It’s not a streaming pattern.
It’s not “Kafka-first architecture”.

It is a commitment to never forgetting.

When done right:

  • bugs are survivable
  • audits are trivial
  • correctness compounds

When done wrong:

  • systems ossify
  • complexity explodes
  • teams drown in history they can’t reason about

One rule to remember:

Event Sourcing doesn’t make systems faster — it makes them honest.
If your domain can’t tolerate forgetting, it may be worth the cost.

Event Sourcing does not forgive architectural laziness — it preserves it forever.


Next in Series

Schema Evolution in Streaming Pipelines — Avro, Protobuf, JSON Schema

We’ll cover:

  • why schema evolution breaks production systems
  • forward vs backward compatibility
  • real failure stories
  • how streaming systems survive change

This is where Event Sourcing meets reality.