Skip to content
>_ StartupJobList_

Interview questions · Worked answers

Apache Kafka interview questions and production answers

A strong Kafka answer follows a record from key and partition through producer acknowledgement, consumer assignment, processing, offset commit and any external side effect. It states the delivery boundary and the recovery behavior at each step.

For: Data and backend engineers building Kafka producers, consumers and event-driven services

Guide scope and versions

Apache Kafka 4.3 producer, consumer and broker semantics. The worked example runs against a disposable single-broker KRaft cluster using KafkaJS; it proves committed versus aborted Kafka records only, not exactly-once effects in an external database or production-cluster availability.

Question 1 of 9

What ordering does Kafka provide, and how do keys affect it?

Kafka preserves record order within a partition. A key can route related records to the same partition so one consumer processes them in order; Kafka does not provide total order across partitions.

An account balance stream keyed by account ID keeps updates for one account together under a stable partitioning scheme. Adding partitions or changing the partitioner can remap keys, so ordering assumptions across the topology change need an explicit migration plan.

A hot key concentrates work on one partition and cannot be parallelized by adding consumers. If one entity needs more throughput, redesign the work or sequence boundary carefully; splitting a key may sacrifice per-entity order.

Follow-up: Does one consumer group process one partition in parallel?

A partition is assigned to at most one active consumer in a group at a time, so parallel work within that partition requires application-level concurrency that preserves any required ordering. More consumers than partitions leave some consumers idle.

Read the source: Apache Kafka: Design and partition ordering · Apache Kafka 4.3: Producer configuration

↑ Back to questions

Question 2 of 9

What happens to work when a consumer group rebalances?

A rebalance changes partition ownership as members join, leave or miss liveness/progress limits. Consumers must stop or fence work for revoked partitions, finish or abandon in-flight records safely, and resume from committed offsets under the new assignment.

A consumer spends longer processing one poll batch than max.poll.interval.ms. The group can treat it as failed and reassign the partition while the old process is still finishing. If both instances perform side effects, duplicates or out-of-order updates can result.

Keep poll progress within configured bounds, control batch size and processing concurrency, and use cooperative assignment when it fits the clients and upgrade path. Measure rebalance frequency and duration instead of masking a slow handler with arbitrary larger timeouts.

Follow-up: How do you handle partition revocation with asynchronous work?

Stop accepting new work for revoked partitions, drain or cancel work within a bound, commit only offsets whose side effects are durable, and prevent late completion from the old owner from mutating state after reassignment.

Read the source: Apache Kafka 4.3: Consumer configuration · Apache Kafka: Consumer group design

↑ Back to questions

Question 3 of 9

When should a consumer commit its offset relative to a database write?

For at-least-once processing, commit after the durable side effect. A crash after the write but before the commit can replay the record, so the side effect must be idempotent or deduplicated using a stable event identity.

If an offset commits before the database transaction, a process crash can lose the update permanently because Kafka will resume after that record. If the database commits first and Kafka offset commit fails, the record is delivered again. Store an event ID or use a unique constraint so replay does not duplicate the business change.

Kafka transactions can atomically publish Kafka output and commit consumed offsets as one Kafka transaction. They cannot include an arbitrary relational database transaction. For a database plus event, use an outbox or another explicit coordination design and describe its recovery semantics.

Follow-up: Can the consumer commit the highest offset completed when work runs concurrently?

Only if all earlier offsets in that partition are complete. Track a contiguous completed prefix; committing past an unfinished earlier record can skip it permanently after recovery.

Read the source: Apache Kafka: Message delivery semantics · Apache Kafka 4.3: Consumer configuration

↑ Back to questions

Question 4 of 9

What do Kafka producer transactions actually guarantee?

An idempotent producer prevents duplicate writes from retrying producer requests within Kafka's producer protocol. Transactions can atomically write to Kafka partitions and include consumed offsets; read_committed consumers hide aborted transactional records.

A producer writes two related records, then aborts. A read_committed consumer should see neither record from that transaction, while a later committed transaction becomes visible. The example below runs this boundary on a real local broker with synthetic messages.

A transaction does not make an email send, payment request or arbitrary database commit atomic with Kafka. Keep the guarantee scoped to Kafka records and offsets, then use an outbox, idempotency key or saga for external effects.

JavaScript / KafkaJS · Worked example
import assert from 'node:assert/strict';
import { Kafka } from 'kafkajs';

const kafka = new Kafka({ clientId: 'interview-guide', brokers: ['kafka:9092'] });
const topic = 'transaction-proof';
const admin = kafka.admin();
await admin.connect();
await admin.createTopics({ waitForLeaders: true, topics: [{ topic, numPartitions: 1, replicationFactor: 1 }] });
const producer = kafka.producer({ transactionalId: 'guide-producer-1', idempotent: true, maxInFlightRequests: 1 });
await producer.connect();
const aborted = await producer.transaction();
await aborted.send({ topic, messages: [{ key: 'order-7', value: 'must-not-appear' }] });
await aborted.abort();
const committed = await producer.transaction();
await committed.send({ topic, messages: [{ key: 'order-7', value: 'committed' }] });
await committed.commit();
const consumer = kafka.consumer({ groupId: 'guide-read-committed', readUncommitted: false });
await consumer.connect();
await consumer.subscribe({ topic, fromBeginning: true });
const received = [];
let resolveFirst;
const firstRecord = new Promise(resolve => { resolveFirst = resolve; });
await consumer.run({ eachMessage: async ({ message }) => { received.push(message.value?.toString()); resolveFirst(); } });
await Promise.race([firstRecord, new Promise((_, reject) => setTimeout(() => reject(new Error('record timeout')), 15000))]);
await new Promise(resolve => setTimeout(resolve, 500));
assert.deepEqual(received, ['committed']);
await consumer.stop();
await consumer.disconnect();
await producer.disconnect();
await admin.deleteTopics({ topics: [topic] });
await admin.disconnect();
console.log('read_committed exposes the committed record and hides the aborted record');

Run with KafkaJS 2.2.4 on a disposable Apache Kafka 4.3.1 single-broker KRaft cluster. Synthetic topic and records only; the test does not cover external databases or broker failover.

Executed with KafkaJS 2.2.4 against Apache Kafka 4.3.1 single-node KRaft on a Docker internal network; aborted/committed visibility asserted.

Follow-up: Does idempotence protect against application-level duplicate events?

No. It prevents protocol retry duplicates for a producer identity and sequence. If application code creates the same business event twice, use a domain event ID or idempotent sink.

Read the source: Apache Kafka: Message delivery semantics · Apache Kafka 4.3: Producer configuration

↑ Back to questions

Question 5 of 9

How do acknowledgements, idempotence and replication affect producer durability?

A producer acknowledgement policy controls when a write is considered successful. With acks=all, the leader waits for all current in-sync replicas. min.insync.replicas sets the minimum in-sync replica count at which the broker accepts that write; it is an availability threshold, not a count that acks=all waits for. Idempotence constrains retries to avoid duplicate protocol writes.

A topic with replication factor three and min.insync.replicas two can reject an acks=all write when fewer than two in-sync replicas remain, even if the leader is reachable. When it succeeds, acks=all waits for every replica currently in the ISR, which may be more than two. That failure preserves the configured minimum instead of silently accepting a weaker write.

Retries, delivery timeout, batching and in-flight limits work together. Inspect effective producer config and broker/topic settings; a single flag cannot establish end-to-end business durability.

Follow-up: Can a producer retry indefinitely?

Retries are bounded by delivery.timeout.ms in the current client behavior. Choose a bound that fits the request deadline and make the caller handle a final ambiguous failure safely.

Read the source: Apache Kafka 4.3: Producer configuration · Apache Kafka: Replication design

↑ Back to questions

Question 6 of 9

How do you change an event schema without breaking old consumers?

Define compatibility policy and ownership before producers and consumers evolve independently. Prefer additive optional fields with safe defaults when that matches the domain, and test old-reader/new-writer and new-reader/old-writer combinations required by the rollout.

A new producer adds an enum value, but an old consumer uses an exhaustive switch and crashes. Structural schema compatibility may not capture every application's semantic assumption. Test actual consumer behavior and use a staged producer/consumer rollout.

Schema Registry is an adjacent service that enforces configured compatibility rules; Kafka itself stores bytes and does not infer the meaning of the payload. Validate the selected registry policy, serializer behavior and subject naming strategy separately.

Follow-up: How should consumers handle an unknown field or enum?

Ignore unknown optional fields where safe, define an explicit unknown enum behavior and alert on values that cannot be interpreted. Avoid silently mapping a new business state to an unrelated old state.

Read the source: Apache Kafka: Schema evolution and data formats · Confluent Schema Evolution

↑ Back to questions

Question 7 of 9

When do retention and log compaction change what a replay can recover?

Time/size retention removes old log segments; compaction retains the latest value per key over time while tombstones mark deletion for a bounded interval. Neither policy is a substitute for an independent backup or immutable event archive.

A consumer is offline longer than the topic's retention window and resumes at an offset that no longer exists. It must detect the out-of-range position and follow a documented rebuild path, such as loading a snapshot and replaying the remaining log.

A compacted topic can rebuild current keyed state if the key and tombstone semantics are correct, but it is not a complete history of every update. Set retention and compaction based on the recovery contract and storage budget.

Follow-up: Does a tombstone delete the key immediately everywhere?

No. Compaction and tombstone retention are asynchronous. Consumers and recovery tooling must handle the deletion marker and the documented cleanup window.

Read the source: Apache Kafka: Log compaction · Apache Kafka: Topic configuration

↑ Back to questions

Question 8 of 9

How do you distinguish consumer lag from a broken consumer?

Lag measures distance behind the log end, not why the consumer is slow or whether user-visible work is failing. Combine offset lag with processing latency, poll progress, rebalance rate, error counts, downstream saturation and oldest-record age.

A consumer group has rising lag while records process successfully at a steady rate. The input rate may simply exceed capacity. If adding consumers does not help because there are fewer partitions, increase partition-level capacity only after evaluating ordering and storage effects.

If poll intervals expire, the group may rebalance repeatedly and throughput can collapse. Bound per-record work, tune batch size from measured processing time, and apply backpressure to producers or downstream writes rather than buffering without limit.

Follow-up: What does low lag prove?

Only that committed offsets are near the current end at the measurement point. It does not prove the application performed the intended external side effect or that the event was correct.

Read the source: Apache Kafka 4.3: Consumer configuration · Apache Kafka: Monitoring

↑ Back to questions

Question 9 of 9

How do you recover from a poison record without losing order or hiding data loss?

Classify deterministic input failures separately from transient dependencies. Use bounded retries, preserve the original event and failure context, and make dead-letter routing observable; advancing the offset is an explicit data-loss or deferral decision.

A malformed record blocks a partition. Retrying it forever prevents later records on that partition from progressing. A bounded retry can route the original payload and metadata to a dead-letter topic, then continue only if the domain permits the gap and operators can repair/replay it.

If order is essential for an entity, moving one record aside and processing later events may corrupt state. Pause that partition or key, alert with the offset and event ID, and define a repair path that restores order before resuming.

Follow-up: Should every exception go to a dead-letter topic?

No. Transient infrastructure failures should usually retry within a bounded budget. Route only records that are deterministically invalid or require a human/domain repair, and retain enough safe context to reproduce the decision.

Read the source: Apache Kafka: Message delivery semantics · Apache Kafka: Consumer configuration

↑ Back to questions

Salary context

Advertised salaries for these skills

These are Hacker News job posts that mention these technologies, not employee earnings or a measure of what a skill adds to pay. The amounts summarize annualized advertised minimums in approximate USD. Groups can overlap and differ in roles, locations and dates.

Kafka posts

35 posts · 35 usable advertised salary amounts

2024-07-01 to 2026-11-02

$150,000

Median advertised minimum, approximate USD/year

Middle 50%: $120,000–$176,000

Explore Kafka salaries → Browse matching job posts →
Currency and calculation basis

Approximate USD using ECB daily reference rates as of 2026-10-30. Original currencies and offer ranges remain on the source listings. These figures cover posts tagged Kafka, rather than every job in the broader technology family.

↑ Back to questions

Keep exploring