Kafka · Core Concepts

Topic vs Partition and ordering guarantees

Easytopicpartitionorderingpartition key

Interview question

What is the difference between a topic and a partition? What ordering does Kafka guarantee?

How to answer

Topic

A logical category of events: orders, payments, user_events.

Partition

A physical, append-only log that is a shard of the topic. Topics have one or more .

Ordering guarantee (critical interview line)

Kafka guarantees order within a partition, not across the whole topic.

If message A lands in partition 0 and message B in partition 1, consumers may see B before A (or A before B). There is no global topic order.

Use a partition key so related records go to the same partition.

Example: key = order_id or customer_id.

Trade-off

  • 1 partition: total order for the topic, but no parallel consumers in a group.
  • Many partitions: high throughput and parallelism, but only per-key / per-partition order.

Interview tip: Always say "ordering is per partition." Then explain keys as the way to keep related events ordered.