Kafka fundamentals

Topics, partitions as the unit of parallelism, consumer groups, offsets, keys and ordering guarantees, retention & compaction. Partition-count choices haunt you for years.

About 24 min read3-question knowledge check

The mental model

Kafka is a distributed, append-only commit log that producers write to and consumers read from at their own pace. It is not a queue that deletes messages on read — it is a ledger with bookmarks.

The analogy that sticks: a supermarket with numbered checkout lanes. A topic is the store, a partition is one lane, and every customer with the same loyalty card (key) is routed to the same lane, so their purchases are always processed in order relative to each other. A consumer group is a shift of cashiers: each lane is worked by exactly one cashier from the shift, so adding cashiers speeds you up only until you have one per lane — the ninth cashier on an eight-lane store stands idle. An offset is the cashier's bookmark: "I have processed everything in lane 3 up to receipt 41,205." Cashiers can quit and be replaced; the bookmark, not the cashier, holds the progress.

Why Kafka exists: without a durable log between systems, every producer must know every consumer (point-to-point spaghetti), a slow consumer back-pressures the producer, and a consumer outage means data loss. Kafka absorbs bursts, decouples teams (the clickstream producer does not know or care that fraud, recommendations, and the warehouse all read the same topic), and — because messages are retained, not deleted on read — lets you replay: rewind a bug-fixed consumer to yesterday's offset and reprocess. Replay is the feature batch people underestimate most.

The decision that haunts you for years: partition count. It caps consumer parallelism, fixes the key-to-partition mapping, and is painful to change on a keyed topic.

The full lesson continues with 15 more sections
  • Deep dive
  • Internal architecture
  • Real-world use cases
  • Best practices
  • Common mistakes
  • Performance
  • Security
  • Production troubleshooting
  • Advantages & disadvantages
  • Alternatives
  • Interview expectations
  • Interview questions
  • Facts to remember
  • Cheat sheet
  • Quick revision