Kafka interview questions: partitions, consumer groups and delivery semantics
Kafka interview questions test how well you understand Kafka as a replicated, partitioned log: how topics split into partitions, how consumer groups share them, how offsets record progress, and which producer and consumer settings give at-most-once, at-least-once or exactly-once behavior. Expect follow-ups on ordering, replication and acks, retention versus log compaction, rebalancing, consumer lag and the move from ZooKeeper to KRaft. Good answers tie every setting to a failure you are protecting against.
By Evin JohnPublished 9 min read
Where Kafka questions show up
Kafka comes up in backend, data engineering, platform and SRE interviews, and as a component in system design rounds whenever events, logs or streams appear. Conceptual questions check the vocabulary. Configuration questions check whether you know what acks, enable.idempotence, max.poll.interval.ms or cleanup.policy actually change. Scenario questions are where most of the signal is: duplicates after a deploy, lag that keeps growing, messages out of order, a consumer group that keeps rebalancing. Interviewers also like to ask when Kafka is the wrong choice.
Core concepts
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What is Kafka, in one sentence? | Mental model | A distributed, replicated, append-only log: producers append records to topics, records are kept for a retention period, and any number of consumers read at their own pace by offset. |
| Topic, partition, offset? | Vocabulary | A topic is a named stream. It is split into partitions, each an ordered log stored on brokers. An offset is a record's position within one partition. |
| What is a broker and a cluster? | Architecture | A broker is one Kafka server storing partitions and serving clients. A cluster is several brokers, with partitions spread and replicated across them. |
| How does a producer choose a partition? | Partitioning | With a key, the default partitioner hashes it, so the same key always lands on the same partition while the partition count stays fixed. Without a key, newer clients fill a batch for one partition before moving on (the sticky partitioner) instead of strict round robin. |
| How is Kafka different from a traditional queue? | Comparison | Reading does not delete. Records stay until retention removes them, many independent groups can read the same data, and consumers can rewind to reprocess. A classic queue removes a message once one consumer acknowledges it. |
| Kafka versus RabbitMQ? | Judgment | Kafka suits high-throughput event streams, replay and many consumers of the same data. RabbitMQ suits task queues with per-message acknowledgment, flexible routing and priorities. The choice follows the access pattern. |
| Why is Kafka fast? | Internals | Sequential appends to segment files, heavy use of the OS page cache, batching and compression on the producer, and zero-copy transfer from file to socket when serving consumers. |
| What is a consumer group? | Scaling reads | Consumers sharing a group.id split a topic's partitions among them; each partition goes to one consumer in the group. Different groups each receive every record. |
Replication and durability
- How does replication work? Each partition has one leader replica and some followers on other brokers. Producers and (by default) consumers talk to the leader; followers fetch from it to stay in sync.
- What is the ISR? The in-sync replica set: replicas that have caught up with the leader recently. Only ISR members can be elected leader in a clean election.
- What do acks=0, acks=1 and acks=all mean? 0: the producer does not wait, so data can vanish silently. 1: the leader wrote it, but it is lost if the leader dies before followers copy it. all: every in-sync replica has it.
- Why pair acks=all with `min.insync.replicas`? If the ISR shrinks to just the leader, acks=all degenerates to acks=1. With replication factor 3 and
min.insync.replicas=2, writes fail rather than accept data that only one broker holds. - What is unclean leader election? Allowing an out-of-sync replica to become leader when no in-sync one survives. It restores availability but loses the records it never received. It is off by default.
- What is the high watermark? The offset up to which records are replicated to the whole ISR. Consumers only see records below it, so they never read data that could disappear in a failover.
Producers: batching, idempotence and transactions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| How does the producer batch records? | Throughput | Records for the same partition collect into a batch until batch.size fills or linger.ms passes. A small linger trades a few milliseconds of latency for much larger, better-compressed batches. |
| Why can retries create duplicates? | Failure modes | The broker writes the batch but the acknowledgment is lost; the producer retries and the batch is written twice. |
| What does the idempotent producer do? | Deduplication | The broker tracks a producer id and per-partition sequence numbers and drops duplicate batches from retries. It has been on by default since Kafka 3.0 when the other settings are compatible (acks=all is required). |
| Can retries reorder records? | Ordering | Without idempotence, yes, when several requests are in flight and an earlier one fails and is retried. With idempotence, order is kept with up to five in-flight requests per connection. |
| What are Kafka transactions for? | Atomic writes | Writing to several partitions and committing consumer offsets atomically, using a transactional.id. Consumers with isolation.level=read_committed skip records from aborted transactions. |
What happens if two producers use the same transactional.id? | Fencing | The newer one bumps the epoch and the older one is fenced off, so a zombie instance from before a restart cannot write. |
| Which compression codec would you choose? | Trade-offs | lz4 or zstd are common choices; zstd usually compresses better, lz4 is lighter on CPU. Compression works per batch, so it pays off with batching. |
Properties props = new Properties();
props.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "broker1:9092,broker2:9092");
props.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, StringSerializer.class.getName());
props.put(ProducerConfig.ACKS_CONFIG, "all"); // wait for the in-sync replicas
props.put(ProducerConfig.ENABLE_IDEMPOTENCE_CONFIG, true); // no duplicates from retries
props.put(ProducerConfig.LINGER_MS_CONFIG, 10); // small wait for bigger batches
props.put(ProducerConfig.COMPRESSION_TYPE_CONFIG, "zstd");
try (KafkaProducer<String, String> producer = new KafkaProducer<>(props)) {
String customerId = "c-1042";
producer.send(new ProducerRecord<>("orders", customerId, "{\"event\":\"created\"}"),
(metadata, error) -> {
if (error != null) log.error("send failed", error); // retries are exhausted here
});
}Consumers, offsets and rebalancing
- Where are consumer offsets stored? In the internal
__consumer_offsetstopic, keyed by group, topic and partition. A committed offset is the next record to read, not the last one processed. - Auto commit or manual commit? Auto commit saves offsets on a timer, which can mark records done before your code finishes them (loss on a crash) or after (duplicates). Manual commit after processing gives at-least-once behavior you control.
- What triggers a rebalance? A consumer joining or leaving, a consumer missing heartbeats (
session.timeout.ms), a consumer taking longer thanmax.poll.interval.msbetween polls, or partitions being added to a subscribed topic. - Why do rebalances hurt, and how do you reduce them? With the older eager protocol, every consumer stops and gives up all partitions. Cooperative incremental rebalancing moves only the partitions that change, static membership (
group.instance.id) avoids rebalances on quick restarts, and Kafka 4.0 made a new broker-driven consumer group protocol generally available. - What happens with more consumers than partitions? The extra consumers sit idle. Partition count is the upper limit on parallelism inside one group.
- How do you handle a message that always fails (a poison pill)? Catch the error, retry a limited number of times, then send the record to a dead letter topic with the error details and move on, so one record does not block its whole partition.
- What is consumer lag and how do you monitor it? The gap between the latest offset in a partition and the group's committed offset. Track it per partition; growing lag means consumers are too slow, stuck or too few.
props.put(ConsumerConfig.GROUP_ID_CONFIG, "billing-service");
props.put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, false);
props.put(ConsumerConfig.AUTO_OFFSET_RESET_CONFIG, "earliest"); // only when the group has no offset
try (KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props)) {
consumer.subscribe(List.of("orders"));
while (running) {
ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(500));
for (ConsumerRecord<String, String> record : records) {
billing.applyOnce(record.key(), record.offset(), record.value()); // idempotent handler
}
if (!records.isEmpty()) {
consumer.commitSync(); // commit only after the whole batch is processed
}
}
}def assign(partitions, consumers):
consumers = sorted(consumers)
per, extra = divmod(partitions, len(consumers))
out, start = {}, 0
for i, c in enumerate(consumers):
count = per + (1 if i < extra else 0)
out[c] = list(range(start, start + count))
start += count
return out
print(assign(6, ["c1", "c2", "c3", "c4"]))
# {'c1': [0, 1], 'c2': [2, 3], 'c3': [4], 'c4': [5]}
print(assign(3, ["c1", "c2", "c3", "c4"]))
# {'c1': [0], 'c2': [1], 'c3': [2], 'c4': []} <- c4 is idleDelivery semantics and ordering
| Question | What it tests | What a strong answer shows |
|---|---|---|
| Explain at-most-once, at-least-once and exactly-once. | Core concept | At-most-once commits before processing and can lose records. At-least-once processes before committing and can repeat them. Exactly-once means each record's effect happens once. |
| Does Kafka give exactly-once? | Precision | Within Kafka, yes: idempotent producers plus transactions make read-process-write pipelines exactly-once, as Kafka Streams does with processing.guarantee=exactly_once_v2. Side effects outside Kafka (an email, a payment API call) need idempotent handling or an outbox on your side. |
| How do you make a consumer idempotent? | Practical | Use a business key or the topic, partition and offset as a deduplication id, store it in the same database transaction as the effect, and skip records already applied. |
| How do you keep events for one customer in order? | Ordering | Use the customer id as the key so all its events go to one partition, keep the idempotent producer on, and process each partition sequentially on the consumer side. |
| What breaks key ordering? | Pitfalls | Adding partitions to the topic changes which partition a key hashes to, so old and new events for a key can sit in different partitions. Processing one partition's records in parallel threads also breaks it. |
| How would you publish an event when a database row changes, without losing either? | Dual writes | The transactional outbox: write the row and an outbox record in one database transaction, then relay the outbox to Kafka, often with change data capture. Writing to the database and Kafka separately can lose one of them on a crash. |
Retention, compaction and storage
- How does retention work? Each partition is a series of segment files. When a closed segment is older than
retention.msor the partition exceedsretention.bytes, whole segments are deleted. Retention is not based on whether anyone has read the data. - What is log compaction? With
cleanup.policy=compact, Kafka keeps at least the latest record for each key and removes older ones in the background. It turns a topic into a durable changelog of current state, used for things like configuration and Kafka Streams state stores. - How do you delete a key from a compacted topic? Produce a tombstone: the key with a null value. Compaction removes earlier values, and the tombstone itself is removed after
delete.retention.ms. - Can you combine delete and compact? Yes,
cleanup.policy=compact,deletekeeps the latest value per key but also drops anything older than the retention period. - How many partitions should a topic have? Enough for the consumer parallelism and throughput you expect, with headroom, since adding partitions later breaks key placement. Too many costs broker memory, file handles and longer leader elections.
- What is tiered storage? Keeping older segments in object storage instead of on broker disks, so retention can grow without bigger brokers. It arrived as early access in Kafka 3.6 and was declared production ready in 3.9.
KRaft, ZooKeeper and the ecosystem
| Question | What it tests | What a strong answer shows |
|---|---|---|
| What did ZooKeeper do for Kafka? | History | Stored cluster metadata (brokers, topics, partition leaders, configs) and elected the controller. Running a second distributed system was an operational burden and limited how many partitions a cluster could handle well. |
| What is KRaft? | Current architecture | Kafka's own Raft-based metadata quorum: a set of controller nodes keeps the metadata log inside Kafka itself. It became production ready in Kafka 3.3, and Kafka 4.0 (released in 2025) removed ZooKeeper mode entirely. |
| How do you migrate a ZooKeeper cluster? | Operations | Upgrade to a 3.x release that supports the migration path, run the ZooKeeper-to-KRaft migration with dual-write controllers, move brokers to KRaft mode, then upgrade to 4.x. You cannot jump straight from a ZooKeeper cluster to 4.0. |
| What are Kafka Connect and Kafka Streams? | Ecosystem | Connect runs source and sink connectors that move data between Kafka and other systems without custom code. Streams is a Java library for stateful stream processing (joins, windows, aggregations) that runs inside your application. |
| What is a schema registry for? | Data contracts | Producers register Avro, Protobuf or JSON schemas and send a schema id with each record; compatibility rules stop a producer from breaking consumers. It is a separate service, not part of Apache Kafka itself. |
bin/kafka-consumer-groups.sh --bootstrap-server broker1:9092 \
--describe --group billing-service
# Columns include TOPIC, PARTITION, CURRENT-OFFSET, LOG-END-OFFSET and LAG.
# A partition whose LAG keeps growing while others stay flat points to a
# hot key or a stuck consumer, not to a slow group overall.Senior and scenario questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| Lag on one partition grows while the others are near zero. | Hot partitions | A hot key sends most traffic to one partition, or one consumer is stuck on a slow record. Check per-key volume and that consumer's processing time; fix with a better key or by splitting the hot key's work. |
| The consumer group rebalances every few minutes. | Group stability | Processing a poll's records takes longer than max.poll.interval.ms. Lower max.poll.records, speed up processing or raise the interval, and look for long pauses such as garbage collection. |
| A broker died. What happens, and what do you check? | Failover | The controller moves leadership of its partitions to in-sync followers. Check for under-replicated partitions, whether any partition went offline, and producer errors from min.insync.replicas. |
| Disk usage on brokers keeps climbing. | Retention | Look for topics with long or unlimited retention, compacted topics whose keys never repeat, and lagging consumers you have been asked to keep data for. Retention, not consumption, frees disk. |
| You need to reprocess yesterday's events after fixing a bug. | Replay | Reset the group's offsets to a timestamp with the consumer groups tool while the group is stopped, or replay into a new group, and make sure processing is idempotent first. |
| How would you move a busy topic to more partitions safely? | Repartitioning | Adding partitions breaks key placement, so for ordered keyed data create a new topic with the target count, dual-write or mirror into it, and switch consumers once they catch up. |
Fictional example
- Interviewer
- Our billing consumer reads order events and creates invoices. Every deploy, a handful of customers get two invoices. What is happening?
- Candidate
- That is at-least-once delivery doing exactly what it promises. During a deploy, consumers shut down and the group rebalances. Records that were processed but whose offsets were not yet committed get handed to another consumer, which processes them again. If the old instance is killed rather than closed cleanly, the window is bigger, and auto commit makes it unpredictable. I would fix the effect, not the delivery: make invoice creation idempotent by storing the order id, or the topic, partition and offset, in a unique column in the same database transaction as the invoice, and skip anything already present. Then I would reduce how often it happens: commit after each processed batch, close consumers cleanly on shutdown so they commit and leave the group, and use cooperative rebalancing or static membership so a rolling deploy does not shuffle every partition. Exactly-once transactions would not help here on their own, because the invoice is written to our database, not to Kafka.
How to prepare for Kafka interview questions
- Run a local clusterStart a single-node KRaft broker in Docker, create a topic with a few partitions, and use the console producer and consumer. Watch what happens to a group when you start a second and third consumer.
- Learn the settings by failureFor acks, min.insync.replicas, idempotence, auto commit, max.poll.interval.ms and cleanup.policy, say which failure each one protects against.
- Draw the semanticsSketch where the commit happens for at-most-once and at-least-once, and what a crash at each point does. Then add transactions and say what they do and do not cover.
- Practice scenario answersDuplicates, growing lag, out-of-order events, constant rebalancing and a lost broker. Each answer should name the cause, how you would confirm it and the fix.
- Know where Kafka fits in a designEvent-driven services, the outbox pattern, change data capture and stream processing. Also know when a simple queue or a database table would do.
Kafka usually appears alongside other topics. Spring Boot interview questions covers the framework many Kafka consumers run in, computer networks interview questions explains the TCP and TLS underneath the client protocol, and the data engineer interview questions page covers streaming pipelines from the data side. In design rounds, Kafka often sits inside a notification system.
Kafka scenario answers improve when you hear yourself give them. Natively, an AI interview assistant for Mac and Windows, transcribes your mock streaming round, can suggest an answer to compare with yours, and reads a config file, consumer code or a lag table from a screenshot. With Pro or the free trial it also uses the résumé and job description you add, and the transcript and notes from each practice session are kept so you can review them.
Questions people ask
What are the most common Kafka interview questions?
Topics, partitions and offsets, consumer groups, replication and acks, delivery semantics, ordering guarantees, idempotent producers and transactions, retention and log compaction, and KRaft versus ZooKeeper.
Does Kafka guarantee message order?
Only within a partition. Records with the same key go to the same partition, so per-key order holds while the partition count stays the same and each partition is processed sequentially.
How does Kafka achieve exactly-once?
Idempotent producers remove duplicates from retries, and transactions make writes to several partitions plus consumer offset commits atomic. Effects outside Kafka still need idempotent handling.
Does Kafka still need ZooKeeper?
No. KRaft, Kafka's built-in Raft metadata quorum, became production ready in Kafka 3.3, and Kafka 4.0 removed ZooKeeper mode.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
