Bird
Raised Fist0
HLDsystem_design~3 mins

Why Event sourcing in HLD? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if you could rewind time and see every step your system took to reach its current state?

The Scenario

Imagine you run a busy store and keep track of every sale by writing it down on paper. When you want to know how much money you made, you have to add up all those notes manually.

The Problem

This manual way is slow and mistakes happen easily. If you lose a paper or forget to write something, your records are wrong. Also, fixing errors means digging through piles of notes, which is frustrating and time-consuming.

The Solution

Event sourcing changes this by saving every action (or event) as it happens in a clear, ordered list. Instead of just the final result, you keep the full story. This makes it easy to check, fix, or replay events to understand exactly what happened.

Before vs After
Before
balance = 0
for sale in sales:
    balance += sale.amount
After
events = []
for event in event_stream:
    apply(event, state)
What It Enables

With event sourcing, you can rebuild your system's state anytime and track every change, making your data reliable and easy to audit.

Real Life Example

Think of a bank that records every deposit and withdrawal as an event. If there's a dispute, they can replay all events to see exactly how the balance changed over time.

Key Takeaways

Manual record-keeping is slow and error-prone.

Event sourcing stores every change as an event, preserving history.

This approach improves reliability, debugging, and auditing.