Kafka Message Queue

A durable, append-only log in the Kafka style: producers batch records per partition, the leader appends through the page cache, the ISR replicates, and consumer groups pull and resume from stored offsets.

  • Throughput: millions of messages/sec
  • Publish ack: sub-10 ms broker-stage target
  • batch.size: 16 KB default
  • linger.ms: 0 default · 5–10 ms recommended
  • buffer.memory: 32 MB · max.block.ms 60,000 ms
  • Limits: max.message.bytes 1 MB · 5 in flight

Producer

The application thread calls send(). It serializes the record, asks the partitioner for a partition, and appends it to that partition's batch queue; it does not touch the network.

Partitioner

Runs inside send() before the record is appended: murmur2(key) % numPartitions picks the partition, so the same key always lands in the same partition and stays ordered.

RecordAccumulator

Holds one queue of batches per partition. A batch ships when it reaches batch.size (16 KB) or when linger.ms expires, whichever comes first.

BufferPool

A fixed-size pool (buffer.memory, 32 MB) that hands out batch.size (16 KB) blocks and takes them back after the ack. It is the bound on producer memory.

Sender thread

A background thread that drains ready batches, groups them by the leader broker of each partition, and sends one request per broker over its socket channel.

Partition leader

One broker leads each partition. It appends batches to the log, tracks which followers are in sync, and serves reads up to the high watermark.

OS page cache

Appends go into the OS page cache and are flushed by the OS; reads for recent data come from memory and are sent to the socket with zero-copy sendfile.

ISR + high watermark

Followers that are caught up form the ISR. The high watermark is the offset every ISR member has; consumers read only up to it.

KRaft controller

A quorum of controllers that stores cluster metadata and elects partition leaders from the ISR. Off the per-record path.

Consumer group

Members split a topic's partitions and pull from them; heartbeats prove membership; a missing member triggers a rebalance that hands its partitions to the others.

Stored offsets

The group's committed position in each partition, stored durably in the cluster so a new owner knows where to resume.