LearnThatStack Ace your next interview
Apache Kafka · question
Question 2 of 41

What is a Kafka topic and how does partitioning work?

beginner
← All Apache Kafka questions
Re-explain
Visual ↓

A topic is a named stream that producers send messages to and consumers read from. Kafka calls each message a record, and divides each topic into partitions, which are ordered logs spread across brokers.

The producer picks each record's partition. A keyed record goes to a partition chosen by hashing its key, so one key maps to one partition while the partition count is unchanged. A record without a key goes to a sticky partition, which changes once at least batch.size bytes have gone to it.

Partitions bring these benefits:

  • Several consumers can read a topic in parallel.
  • Records spread across brokers.
  • Order holds within each partition, though not across partitions.
  • A topic scales out as you add partitions and brokers.

For example, a topic user-events with 3 partitions stores records in partitions 0, 1 and 2.

Rewriting in plainer words…

This answer doesn't lend itself to a diagram - it reads best . No credits were charged.

Why there's no diagram: “”

The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓

The diagram below the answer is the concept . Jump to it ↓

Tailored explanation · switch back to · ·
What should the new diagram focus on?
See it - interactive diagram
How keyed records land in user-events partitions
Partition 0cell number = offset
empty
Partition 1
user-7 login
Partition 2
empty
Consumer readread order
empty
1step

The producer hashes key user-7 and picks partition 1. The record, Kafka's word for a message, takes offset 0, the first slot.

1 / 7

Every user-7 record hashes to partition 1, so its order holds there, but the topic as a whole has no single order across partitions.

© LearnThatStack - diagrams may not be republished without permission.

Other questions have diagrams like this too. Sign in to ask for one where it's missing - it's free.

Create a free account
How well did you know this?
AI:

Saved in this browser - sign in to keep your review list.

How should your speech become text?

Listening… your words appear above as you speak - tap Stop when you're done.

Recording · cr - tap Stop & transcribe when you're done.

Transcribing with AI…

Voice:

Keep going - a few more words and AI can grade it.

Interview lens

Likely follow-ups, what you can say, and the weak answers to avoid.

Sign in free to open it Free account - the lens opens as soon as you're back.

Want a quick review of the fundamentals? See the Apache Kafka cheatsheet.

← Back to all Apache Kafka questions
Pro · $10/mo

36 of 41 Apache Kafka answers are in Pro.

Full answers, code samples, and AI explanations that go simpler or deeper. Cancel anytime.

  • Full answers + code
  • AI explanations, simpler or deeper
  • 1,000 AI credits / month
  • Cancel anytime