Build Kafka
13 scenes · ~91 min · build the primitive

Build your own Kafka

A partitioned, replicated, append-only log. The log is the database — internalize that, and a dozen product designs get easier.

Scenes
13 interactive scenes
Time
about 91 minutes
Topic
Queues, Pub/Sub & Event Streaming

What you are building, and why

You are designing a distributed log: producers append messages, consumers read them in order, the system survives machine failures. This is the canonical "log is the database" system — once you have built it, you understand why partitions matter for ordering, why exactly-once is hard, what ISR means when a broker dies, and why log compaction has the trade-offs it does.

Resist the urge to "describe Kafka." Make decisions yourself, defend them, and let the AI push back. The point isn't to recreate Kafka byte-for-byte — it's to make every choice that the Kafka authors made, and feel why they made it.

What you will be able to explain afterwards

  • append-only log
  • partitioning
  • replication
  • ISR & quorum
  • log compaction
  • exactly-once semantics
  • controller / KRaft
  1. 01
  2. 01a
  3. 02
  4. 02a
  5. 03
  6. 04
  7. 04a
  8. 05
  9. 05a
  10. 06
  11. 07
  12. 08
  13. 09

Why a log?

Orientation — the log is the database, not a queue.

  1. 01
    Foundations — what Kafka is, words you'll hear
    Why Kafka exists and the seven core nouns (producer, broker, topic, partition, record, offset, consumer). Orientation before you touch anything.
    ~7 min
  2. 01a
    Hello Kafka — topic, brokers, records
    Foundations: what's a topic vs a partition, what's a broker, what does the producer/consumer code actually look like.
    ~7 min
  3. 02
    The log is the database — per-consumer offsets on an append-only log
    Why a log isn't a queue, and why that one fact unlocks the rest.
    ~7 min
  4. 02a
    Offsets, retention, and where bookmarks live
    Read and commit are separate ack channels; retention, not consumers, ages records out.
    ~7 min

Write side

Partitioning, replication, and durability knobs.

  1. 03
    Partitions — splitting the log
    Parallelism by sharding ordering. Hot partitions, key skew.
    ~7 min
  2. 04
    Replication — ISR is not a quorum
    Why a write commits when the in-sync set fetches it, not a majority.
    ~7 min
  3. 04a
    Cluster, controller, and metadata
    One controller per cluster; KRaft made the metadata itself a Raft log.
    ~7 min
  4. 05
    Durability is four knobs, not one — acks=all, min.insync.replicas and unclean.leader.election
    acks, min.insync.replicas, RF, unclean — and how 'all' silently means one.
    ~7 min
  5. 05a
    Log compaction — keep the last value per key
    Compact-retention turns the log into a state store; tombstones propagate deletes.
    ~7 min

Consensus

Leader epoch is the vector clock that fixes truncation.

  1. 06
    Leader epoch — the vector clock that fixes truncation
    Why HW-based truncation could silently lose acked writes, and how KIP-101 closed the gap.
    ~7 min

Scale

Rebalancing without halting every consumer.

  1. 07
    Rebalance — stop-the-world vs. cooperative
    Eager revokes everyone; cooperative-sticky only the lanes that move.
    ~7 min

Guarantees

Three monotonic counters; one design canvas.

  1. 08
    Exactly-once — three monotonic counters
    PID, epoch, group-generation — three independent fences against zombies.
    ~7 min
  2. 09
    Design canvas — pick the knobs
    Capstone: apply scenes 2-8 to a fresh problem and articulate the trade-off you took.
    ~7 min

Where you'll use this

Product designs whose trade-offs turn on what this curriculum teaches.

More in Queues, Pub/Sub & Event Streaming

Moving events between services without losing them: logs, work queues, fanout, change data capture, stream processing, and the delivery systems built on top.

Prefer to design it yourself?

The same subject as a staged workspace: draw the architecture, and a simulator traces requests through the boxes you drew.

Open the Build Kafka workspace