Skip to content
Kafka Is Fun

IntermediateInternals

What is Kafka's RecordAccumulator and how does it buffer messages?

Reference answer

The RecordAccumulator is the producer-side in-memory buffer that queues records into batches before they are sent. It keeps a deque of ProducerBatch objects per topic-partition, and incoming records are appended to the current batch of their partition. A batch is ready to send when it is full (batch.size) or linger.ms has elapsed, or in a few other cases such as flush() or an exhausted buffer; the background Sender thread then drains the ready batches for each leader broker and sends them in ProduceRequests. Memory is bounded by buffer.memory (default 32 MB): when it is exhausted, send() blocks for up to max.block.ms, after which the producer returns a failed future with BufferExhaustedException (a subclass of TimeoutException). The producer metric buffer-available-bytes shows how much buffer memory is unused, which helps to spot buffer pressure.

Expected key concepts: RecordAccumulator, buffer, ProducerBatch, topic-partition, batch.size, linger.ms, Sender thread, buffer.memory, max.block.ms, BufferExhaustedException

How did that feel?

Your own verdict, not the score. It shows up next to this question in the list, so you can come back to the shaky ones.