00:00

Apache Kafka Interview Questions and Answers

Last updated:

This page collects the Kafka questions that come up most often in interviews for Java developers, backend engineers and tech leads, with short answers that are correct for Kafka 4.x. Each answer explains the idea in a few sentences, so you can repeat it in your own words and go deeper if the interviewer asks.

Questions are grouped by topic and move from basic to advanced. Each section links to the detailed tutorial on that topic. For problem-solving questions, continue with Kafka Scenario-Based Interview Questions.

Preparation tip: Interviewers often check whether your knowledge is current. Mention that Kafka 4.0 removed ZooKeeper (KRaft only), that the idempotent producer and acks=all are defaults since 3.0, and that a new consumer group protocol (KIP-848) is available.

1. Fundamentals

1.1 In one sentence, what is Apache Kafka?

Kafka is a distributed, durable, partitioned commit log used for publishing, storing and processing streams of events in real time. Unlike a classic queue, it keeps records after they are read, so many independent consumers can read the same data at their own pace. See Introduction to Apache Kafka.

1.2 How is data organised in Kafka?

Records are written to topics. Each topic is split into partitions, which are ordered, append-only logs stored on brokers. Each record in a partition has an increasing offset. A record has a key, a value, a timestamp and optional headers. See Kafka Partition.

1.3 What role does the record key play?

The default partitioner hashes the key to choose the partition, so all records with the same key go to the same partition and keep their order. Records without a key are spread across partitions in batches (the sticky partitioner). Keys are also used by log compaction.

1.4 What are record headers used for?

Headers are key-value pairs with byte-array values attached to a record, separate from the key and value. They carry metadata such as a trace ID, the event type, the schema version or the source system, so that consumers and tools can route or inspect records without deserializing the payload. Frameworks use them too; for example Spring Kafka stores type information and dead-letter error details in headers.

1.5 Is Kafka push-based or pull-based?

Pull-based. Consumers fetch records from brokers at their own pace, which lets slow consumers fall behind without affecting the broker or other consumers, and makes batching efficient. Long polling avoids busy loops when there is no new data.

2. Producers

2.1 What does a producer callback tell you?

The callback passed to send() runs once the record's fate is known. On success it receives RecordMetadata with the topic, partition, offset and timestamp; on failure it receives the exception, after the client's own retries have ended. Callbacks run on the producer's I/O thread, so they should be quick and must not block; hand slow work to another thread.

2.2 What are the default producer reliability settings in Kafka 4.x?

acks=all, enable.idempotence=true, effectively unlimited retries bounded by delivery.timeout.ms (2 minutes), and max.in.flight.requests.per.connection=5. Together they give durable, ordered, duplicate-free writes per partition within a producer session. See Kafka Producer Acknowledgements.

2.3 How do batching and compression improve throughput?

Sending many records in one request reduces network round trips and per-request overhead. Compression (compression.type such as lz4 or zstd) is applied per batch, so larger batches compress better. A slightly higher linger.ms trades a few milliseconds of latency for much higher throughput.

3. Consumers

3.1 How do consumers in a group share work?

Each partition is assigned to exactly one consumer in the group, so the number of useful consumers is limited by the partition count. Different groups read independently and each gets every record. See Kafka Consumer Groups.

3.2 What are at-most-once, at-least-once and exactly-once delivery?

At-most-once: offsets are committed before processing, so a crash can skip records but never repeats them. At-least-once: offsets are committed after processing, so a crash can repeat records but never skips them; this is the usual choice, combined with idempotent processing. Exactly-once: results written to Kafka and the consumed offsets are committed in one transaction. See Kafka Offset Management.

3.3 What does isolation.level=read_committed do on a consumer?

It makes the consumer return only records from committed transactions, and skip records from aborted ones. The consumer reads up to the last stable offset, the first offset that still belongs to an open transaction, so an open transaction delays visibility of later records in that partition. The default, read_uncommitted, returns all records, including those from transactions that are later aborted.

3.4 What is the difference between subscribe() and assign()?

subscribe() joins the consumer group given by group.id; the group coordinator assigns partitions and moves them when members join or leave. assign() gives the consumer a fixed list of partitions chosen by your code, with no group membership and no rebalancing; you can still commit offsets under a group.id, but you must handle failover yourself. assign() suits tools, replays and single-instance readers that need specific partitions.

4. Storage and Retention

4.1 How is topic retention different from offset retention?

Topic retention (retention.ms, 7 days by default) decides how long records stay in a topic. Offset retention (offsets.retention.minutes, also 7 days by default) decides how long the committed offsets of a consumer group are kept after the group becomes empty. They are independent: a group can lose its offsets while the data still exists, or keep offsets that point to data that has already been deleted, in which case auto.offset.reset applies.

4.2 What is the difference between retention and compaction?

With cleanup.policy=delete (the default), whole segments are removed when they are older than retention.ms (7 days by default) or the partition exceeds retention.bytes. With cleanup.policy=compact, Kafka keeps at least the latest record for each key and removes older ones, which is ideal for changelogs and current-state topics.

5. Reliability

5.1 How does Kafka avoid losing data when a broker fails?

Partitions are replicated to several brokers. Writes go to the leader and are copied by followers; with acks=all, the leader acknowledges only after all in-sync replicas have the record, and min.insync.replicas sets the minimum ISR size for accepting writes. When a leader fails, a new leader is elected from the ISR. See Replication in Apache Kafka.

5.2 What does exactly-once mean in Kafka?

It means that the effects of processing, written to Kafka topics, happen once even if steps are retried. It combines the idempotent producer, transactions that write output records and consumer offsets atomically, and consumers using isolation.level=read_committed. It does not automatically cover external databases. See Kafka Offset Management for the consumer side.

6. KRaft and Operations

6.1 Can one Kafka 4.x node act as both broker and controller?

Yes. With process.roles=broker,controller a node runs in combined mode, which is convenient for local development and small test clusters. For production, the documentation recommends dedicated controller nodes (process.roles=controller), usually three or five, so that broker load cannot slow down metadata handling and controllers can be maintained separately. See Kafka KRaft.

6.2 What is the Admin API used for?

The Java Admin client manages a cluster from code: creating and deleting topics, adding partitions, changing configurations, describing consumer groups and their offsets, resetting offsets, managing ACLs and triggering leader elections. The command-line tools are built on the same API, so anything you do with kafka-topics.sh or kafka-consumer-groups.sh can be automated in Java.

6.3 What is stored in the __consumer_offsets topic?

It is an internal, compacted topic (50 partitions by default) where group coordinators store committed offsets and consumer group metadata. Each group is mapped to one of its partitions, and the leader of that partition acts as the group's coordinator. Because it is compacted, only the latest committed offset per group, topic and partition is kept.

7. Ecosystem

7.1 What are Kafka Connect and Kafka Streams used for?

Kafka Connect moves data between Kafka and external systems with reusable source and sink connectors, configured rather than coded. Kafka Streams is a Java library for processing data from Kafka topics into other topics, with state stores and exactly-once support. See Kafka Connect and Kafka Streams.

7.2 What are share groups?

Share groups (KIP-932), introduced in Kafka 4.x, let several consumers read from the same partition cooperatively, with per-record acknowledgement, which gives queue-like semantics on top of Kafka topics. Unlike consumer groups, the number of consumers is not limited by the partition count, but per-partition ordering is not guaranteed. Check your Kafka version's release notes for the feature's current status.

7.3 How does Kafka compare with a traditional message broker such as RabbitMQ?

Kafka is a log: records stay for a retention period, consumers track their own offsets, and many consumer groups can replay data. Traditional brokers usually remove messages once acknowledged and offer rich routing per message. Kafka favours throughput, retention and replay; see Kafka vs RabbitMQ.

8. Conclusion

Strong Kafka answers connect a feature to its trade-off: partitions give parallelism but limit ordering, acks=all gives durability at some latency, and rebalances provide elasticity but pause work. Keep your knowledge current with Kafka 4.x (KRaft only, new consumer protocol, share groups), and practise explaining each concept with a real example from your own projects.

9. References