Apache Kafka Tutorial 0/111 lessons ~6 min read Lesson 78
Event Sourcing
What is Event Sourcing?
Course progress0%
Focus
9 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
What is Event Sourcing? Event sourcing persists state changes as events and rebuilds current state by replaying them.
Understanding the topic
What happens — Event Sourcing:
- Define RPO/RTO and data sovereignty.
- Replicate selected topics cross-cluster.
- Plan failover and conflict handling.
- Capacity-plan for peak + replay.
| Term | Description |
|---|---|
| MirrorMaker 2 | Cluster-to-cluster replication. |
| RPO/RTO | Recovery point/time objectives. |
| Event sourcing | State from event replay. |
| CQRS | Separate write and read models. |
Visual explanation
Pipeline view:
text
Region A Kafka↓ replicate selected topicsRegion B Kafka↓local consumers + DR planTrade-off: latency, cost, consistency
Step-by-step explanation
- Design — Clusters, topics, mapping.
- Replicate — MM2 or cluster link.
- Failover — Test DR runbooks.
- Govern — Schema and ownership.
Informative example
Example:
bash
kafka-topics --bootstrap-server localhost:9092 --create --topic event-sourcing --partitions 6 --replication-factor 3kafka-console-producer --bootstrap-server localhost:9092 --topic event-sourcingkafka-console-consumer --bootstrap-server localhost:9092 --topic event-sourcing --from-beginningkafka-consumer-groups --bootstrap-server localhost:9092 --describe --group event-sourcing-service
Execution workflow
1Event Sourcing workflow
1 / 4Design
Clusters, topics, mapping.
Best practices
- Define RPO/RTO before choosing replication design.
- Replicate only topics with clear ownership and purpose.
- Document failover and failback procedures.
- Model event sourcing around immutable business facts.
Common mistakes
- Bi-directional replication without loop/conflict strategy.
- Event sourcing every table instead of meaningful domain events.
- Ignoring replay cost during capacity planning.
Summary
Event Sourcing — Make trade-offs explicit: RPO/RTO, ordering, sovereignty, replay cost, schema governance, and operational ownership.
Ready to mark this lesson complete?Track your journey across the entire course.