SteelReed

Search

Search posts, questions…

Messaging & KafkaQuestion 8 / 21

Middle

Why does Kafka achieve such high throughput even though it writes everything to disk?

Short answer

Kafka turns writing into sequential appends to a log, relies on the OS page cache, batches and compresses end to end, and pushes data to the socket with zero-copy; partitions spread the work over many disks and brokers.

sendfile, zero-copyProducer: batch +compressSequential append to logOS page cacheSocket to consumerConsumer decompressesbatch

3 points to say:

  1. Sequential, append-only writes, using the page cache instead of a cache inside the JVM.
  2. End-to-end batching + compression, zero-copy sendfile (lost once TLS is on), partitions for parallelism.
  3. Trade-offs: per-message latency isn't the lowest, it needs spare RAM for the page cache; consumers reading old data cause disk reads.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.