DISTRIBUTED SYSTEMS & ARCHITECTURE · SUBTOPIC
Kafka Partitions, Consumer Groups & Ordering
Scale parallel consumption while preserving per-key event ordering.
IntermediatePart of Message Queues & Event Streaming
Subtopics in Message Queues & Event Streaming (2)
In plain words
A Kafka topic is a highway with P lanes (partitions). Cars for the same user_id always stay in the same lane so they arrive in order, and each lane can have its own toll booth (consumer) running in parallel.
Think of it like…
Grocery store with 6 checkout lanes: keeping one family’s items in one lane preserves order while 6 lanes run in parallel.
Loading interactive diagram
Loading interactive exercise
Theory & how it works
Ordering is per-partition, NOT global
Kafka guarantees strict order *within a single partition*, not across partitions. Always use an entity ID like order_id or user_id as the partition key so OrderCreated and OrderCancelled land on the same partition in exact order.
Key points & practical guide
Summary checklist
- Ordering holds within each partition, not across the whole topic
- Max active consumers in a group = partition count
- Different consumer groups track independent offsets (can replay history)
When to use it
- Event-driven microservices, CDC, activity feeds, real-time pipelines
Watch out for
- Adding 10 consumers to a 2-partition topic - 8 consumers will sit completely idle!
Quick check
Loading quiz