Skip to main content
Intermediatehow it works

Why is Kafka fast?

Source: Apache Kafka documentation: introduction and design

Quick answer

It appends to partition logs sequentially and relies on the operating system page cache. Producers batch records and compress whole batches, and brokers store and send those batches as they are.

It appends to partition logs sequentially and relies on the operating system page cache. Producers batch records and compress whole batches, and brokers store and send those batches as they are. For consumers, data can go from the page cache to the network socket with zero-copy (sendfile) instead of being copied through the application; this does not apply when TLS encryption is on. Partitions spread the load across brokers and consumers.

Animated explanation
  1. Producerbatches and compresses records
  2. Brokersequential appends to the log
  3. Page cachethe OS keeps hot data in memory
  4. Zero-copysendfile to the socket (not with TLS)
  5. Partitionsspread load across brokers
Kafka is fast because it does less work per record, not because of one trick.

Key points

  • sequential I/O
  • page cache
  • batching + compression
  • zero-copy (not with TLS)
  • partitions

References

Discussion