How does Kafka achieve high throughput, and how does it preserve message ordering?
HardConceptMessage Queues & Event Streaming
Answer
Kafka stores each topic as an append-only log split into partitions spread across brokers. Throughput comes from sequential disk writes, batching, compression, zero-copy transfer and parallelism across partitions; ordering is guaranteed only within a single partition.
- Keys: messages with the same key, such as a user or order ID, go to the same partition, so events for that entity stay in order.
- Consumer groups: each partition is read by one consumer in a group, so the partition count caps a group's parallelism.
- Offsets: consumers track their position and can replay old messages, because data is retained for a configured period instead of being deleted on consumption.
- Durability: partitions are replicated, and with
acks=alla write is acknowledged only after all in-sync replicas have it.
More in Message Queues & Event Streaming
| # | Problem | Platform | Difficulty | Open | 1st1st Visit | 2nd2nd Visit | RevRevise |
|---|---|---|---|---|---|---|---|
| 1 | What is a message queue, and why would you use one? | Concept | Easy | Read the answer to What is a message queue, and why would you use one? | |||
| 2 | What is the difference between a message queue and a publish-subscribe system? | Concept | Medium | Read the answer to What is the difference between a message queue and a publish-subscribe system? | |||
| 3 | What do at-most-once, at-least-once and exactly-once delivery mean? | Concept | Medium | Read the answer to What do at-most-once, at-least-once and exactly-once delivery mean? | |||
| 4 | How does Kafka achieve high throughput, and how does it preserve message ordering? | Concept | Hard | Read the answer to How does Kafka achieve high throughput, and how does it preserve message ordering? |