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.
    TermDescription
    MirrorMaker 2Cluster-to-cluster replication.
    RPO/RTORecovery point/time objectives.
    Event sourcingState from event replay.
    CQRSSeparate write and read models.

    Visual explanation

    Pipeline view:

    text
    Region A Kafka
    ↓ replicate selected topics
    Region B Kafka
    local consumers + DR plan
    Trade-off: latency, cost, consistency

    Step-by-step explanation

    1. Design — Clusters, topics, mapping.
    2. Replicate — MM2 or cluster link.
    3. Failover — Test DR runbooks.
    4. Govern — Schema and ownership.

    Informative example

    Example:

    bash
    kafka-topics --bootstrap-server localhost:9092 --create --topic event-sourcing --partitions 6 --replication-factor 3
    kafka-console-producer --bootstrap-server localhost:9092 --topic event-sourcing
    kafka-console-consumer --bootstrap-server localhost:9092 --topic event-sourcing --from-beginning
    kafka-consumer-groups --bootstrap-server localhost:9092 --describe --group event-sourcing-service

    Execution workflow

    1Event Sourcing workflow
    1 / 4

    Design

    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.