Kafka Interview Questions: Partitions, Ordering and Delivery

Answer the Kafka questions that come up most with a three-part shape, worked partition and consumer-group numbers, and the cost you accepted for each choice.

By AI Interview AssistantPublished 9 min read

A woman holding a marker explains partition diagrams and consumer groups on a whiteboard while a man listens beside two open laptops.

Kafka interview questions test whether you can reason about partitions, ordering, delivery semantics and consumer groups as trade-offs, not recite definitions. For each question, define the concept in one sentence, show how it works with a concrete number or small example, then name the cost of the choice you made. That three-part shape carries you through the five questions below, and through the follow-ups that decide the interview.

Why Kafka interview questions are trade-off questions

A topic is a named stream of records; a partition is a slice of it. Anyone can say that. A strong answer shows that you can pick a partition count, a delivery mode and a consumer strategy for a stated workload, and say what you gave up.

Use the same shape every time:

  1. Definition in one sentence. Say what the thing is and what it bounds.
  2. A worked example with numbers. State your assumptions out loud, then do the arithmetic.
  3. The cost you accepted. Name what gets harder, slower or more expensive because of your choice.

Here is the contrast, once. A weak answer lists features: "Kafka is distributed, durable, scalable and fast." A strong answer names what breaks at scale: "At an assumed 12,000 messages per second I would use 12 partitions, which means key-based ordering is per partition and recovery after a broker failure touches 12 leaders instead of one." The second answer shows how you think about operating a cluster, not just how you describe its features.

Partitions: how many, and what it costs you

A partition is the unit of parallelism and ordering. Records inside one partition keep their order; across partitions, they do not.

A woman points to partition diagrams and charts on a whiteboard while a man listens beside two laptops in a sunlit office.

Assume 12,000 messages per second arrive, and assume one consumer handles 1,000 messages per second. Both are labelled assumptions — say so before you divide.

Incoming rate:        12,000 messages/second   (assumption)
Per-consumer rate:     1,000 messages/second   (assumption)
Partitions needed:    12,000 / 1,000 = 12

Twelve partitions is the floor, not the target. If traffic doubles you want headroom, so you might plan 24. The cost of over-partitioning is real: each partition is a set of files with open handles, so more partitions mean more file handles per broker. Leader election after a broker failure has more leaders to move, which lengthens the window where the cluster is recovering. Rebalances also take longer, because more partitions have to be reassigned. Fewer partitions cap your consumer parallelism at the partition count, so a topic with 4 partitions can never have more than 4 active consumers in a group.

Expect the follow-up: "What happens if you add partitions to a live topic?" The mapping from key to partition uses a hash of the key modulo the partition count. Change the count and existing keys land on different partitions, so ordering by key is no longer preserved for records written before and after the change. If key ordering matters, plan the partition count up front or accept a migration.

Ordering versus throughput: the answer that holds up

The rule: Kafka preserves order per partition. Ordering and parallelism pull against each other, because one partition is read by one consumer at a time.

Worked example. You have an order-events topic with 12 partitions, keyed by order ID, and a consumer group of 4 consumers. Every event for order 4471 hashes to one partition, so its created, paid and shipped events stay in order. Events for order 4472 land on a different partition and can be processed before, after or at the same time as 4471's — which is fine, because they are different orders. What you do not get is a global order across all orders. If a downstream report needs every event in one sequence, you would need a single partition, and that caps throughput at one consumer. For the stated volume, say you rejected that.

The mistake to fix: claiming Kafka "preserves ordering" without the per-partition qualifier. Without the qualifier, a follow-up about cross-partition ordering exposes the gap.

Delivery semantics in Kafka interview questions

Define each by producer retries and consumer commit timing:

  • At-most-once: the consumer commits the offset before processing, so a crash loses the message.
  • At-least-once: the consumer processes, then commits, so a crash between the two replays the message.
  • Exactly-once: transactional producers and consumers with isolation configured, so a message is processed once even across retries.

Here is the example to have ready. A consumer reads a payment event, charges the card, then commits the offset. If the process crashes after the charge and before the commit, the message is replayed on restart and the card is charged again.

Before: charge, crash, restart, replay, charge again — two charges for one event.

After: the handler derives an idempotency key from the event, for example the order ID plus the event ID, and checks a store before charging. On replay, the key is already present, so the handler skips the charge and commits. One charge, one commit.

Exactly-once would also prevent the double charge, but it needs transactional producers and consumer isolation, which adds latency and operational complexity. The honest close: "For this workload I would choose at-least-once plus an idempotent consumer, because it is simpler to operate and the idempotency key is useful anyway."

Consumer groups and rebalances without hand-waving

A consumer group splits partitions across its members. One partition is read by at most one consumer in the group, which is what stops two members processing the same record.

With 12 partitions and 4 consumers, each member owns 3 partitions. Add a fifth consumer and the group rebalances to 3, 3, 2, 2, 2 — all five are active but slightly unevenly loaded. A consumer only sits idle when there are more members than partitions: with 4 partitions and 5 consumers, four members own one partition each and the fifth waits until a partition frees up or you add partitions.

A rebalance is triggered when a member joins, leaves or is presumed dead, or when the partition count changes. During the rebalance, assignment pauses. Long processing times make it worse, because the group coordinator may decide a slow member has died and reassign its partitions, which pauses everyone again. The fixes are shorter batches and cooperative assignment, which moves only the partitions that need to move instead of revoking all of them.

Follow-up: "What if one consumer is slow?" It keeps its partitions and becomes the lag source for those partitions. Check per-partition lag, not just group lag, or the average will hide the problem.

Kafka versus a message queue: answer the comparison

AttributeKafka (log)Classic message queue
RetentionKeeps messages after consumption for a configured periodRemoves a message once acknowledged
Consumer modelPull, with a stored offset per groupPush, with per-message acknowledgement
Ordering scopePer partitionPer queue, or per message group
Operational weightBrokers, partitions, consumer groups to tuneLighter to run for simple task distribution

Recommendation rule: choose the log when several consumers need the same events or you need replay — for example an audit consumer and a billing consumer reading the same order events. Choose the queue for one-off task distribution with per-message acknowledgement, such as sending emails from a work queue. The mistake to fix is calling Kafka "just a faster queue": the retention model changes the design, because consumers can rewind and reprocess.

For the wider reasoning behind these choices, the message queues system design reasoning guide and the event-driven architecture interview walkthrough go deeper. If you want the same shape applied outside streaming, the distributed systems trade-off answers and data engineering trade-off answers cover the neighbouring questions.

End every Kafka answer with its cost

End every Kafka answer with the cost of your choice and the workload assumption behind it. "Twelve partitions at an assumed 12,000 messages per second, accepting that key ordering is per partition and that recovery touches more leaders" is an engineering answer. If you do not know a configuration detail, say what you would check in the documentation rather than inventing a default — a bounded answer is safer than a confident wrong one. Any AI tool that suggests talking points can be wrong; check its output and answer in your own words.

Frequently asked questions

How do I answer a Kafka question when I have only used it through a managed service?

Say so plainly, then reason from the concepts: partitions, offsets, consumer groups and delivery guarantees behave the same way whether you run the brokers or rent them. Describe what you configured and what you observed, such as lag or rebalances, and name what you would check in the broker settings if you owned the cluster. That reasoning is worth showing even if you have no hands-on cluster work.

What if the interviewer asks about Kafka Streams or ksqlDB and I have not used them?

Answer at the level you can defend: both build on the same log and consumer-group model, so state that and describe how you would approach a stream-processing task with the tools you know. Then say what you would read before committing to either. Rather than guessing at API details, name your boundary.

Should I mention log compaction in an interview, and when does it matter?

Mention it when the question involves keeping the latest state per key, such as a table of current customer settings. Compaction retains the most recent record for each key rather than every record, which is useful for rebuilds. If the topic is plain event history, say compaction is not what you want and explain why.

How do I choose a partition key when the obvious key is not there?

Start from what must stay in order. If all events for one entity must be processed in sequence, key on that entity's ID; if nothing needs ordering, spread records with a round-robin or random key to balance load. Then name the cost: a hot key concentrates traffic on one partition, so check that no single key dominates the volume.

Practising Kafka answers? See how AI Interview assistant works.

Clear industrial pipes and valves feeding a glowing reservoir inside a clean facility

12 min read

Data Engineering Interview Questions: Trade-Off Answers

Answer data engineering interview questions by naming the concept, the decision, the trade-off and one honest example, so you can defend your choices when pushed.

  • Data engineering interview questions
  • Data engineering interview answers
A wall of pigeonhole shelves sorted into separate sections by wooden dividers, with a hand placing a folder into one section

12 min read

Data Partitioning System Design Interview: Choosing a Key

A spoken structure for choosing a partition key in interviews: start from the access pattern, name the trade-off you accept, and handle the follow-up questions.

  • Data partitioning system design interview
  • Data partitioning interview explanation
A wall of identical mailbox cubbies with envelopes sliding into some slots in a warm post room

11 min read

Email Delivery Service System Design Interview

Narrate an email delivery service system design interview out loud: requirements, the send pipeline, retries, idempotency and the trade-offs you have to defend.

  • Email delivery service system design interview
  • Design email delivery service
Kafka Interview Questions: Defend Your Choices