Search DistillSys

Find a concept

Type at least two characters to search lessons, designs, papers, and interview prep.

Messagingintermediate7 min read

Kafka & Distributed Logs

Use partitioned append-only logs for durable event streams, replay, and independent consumer progress.

2–5 minute refresher
Mental model

Append to a partition → replicate → advance offset → consumers replay independently

30second
refresher
A distributed log stores immutable records in ordered partitions. Producers append records, brokers replicate them, and consumer groups track offsets. Retention decouples consumption from production, enabling replay and multiple independent views of the same events.

How it works

A record key selects a partition. One consumer in a group owns each partition at a time, which preserves partition order while spreading work. Acknowledgement policy determines how many replicas must persist an append before success.

Decision guide

Key trade-offs

ChoiceWhat you gainWhat it costs
More partitionsMore parallel producers and consumersMore metadata, files, rebalances, and no cross-partition order
Long retentionReplay, audit, and new consumersStorage and recovery duration
At-least-onceAvoid silent loss after crashesConsumers must be idempotent
What happens if?

A consumer processes an event then crashes before committing its offset

The event is delivered again after restart. The handler needs an idempotency key, deduplication record, or transactional output-and-offset commit.
What happens if?

One key produces 80% of traffic

All records for that key land on one partition to preserve order. Adding consumers does not help; the design must split the key, relax ordering, or isolate the hot workload.
Senior interview modeDoes Kafka guarantee global ordering within a topic?Show answer
No. Kafka preserves order within each partition. Global order would require routing through one ordering boundary, which limits parallelism.
#kafka#distributed-log#streaming#partitions