Skip to content
RED SAGSkills

Kafka interview questions and answers

Kafka interview questions cover how topics, partitions and consumer groups work, and what delivery guarantees you actually get in production.

Below are 60 Kafka questions with the correct answer and a short explanation, grouped from fresher to experienced level. Try each one before you open the answer.

What Kafka interviews usually check

  • ✓Topics, partitions, offsets and retention
  • ✓Producers, acks and idempotence
  • ✓Consumer groups and rebalancing
  • ✓At-least-once vs exactly-once delivery
  • ✓Ordering, lag and stream processing

Kafka interview questions for freshers easy

1. Kafka message keys

Payments for each customer must be processed in order in Kafka. What should the producer do?

  1. A.Leave the key empty so load spreads evenly
  2. B.Use a random UUID as the key for each message
  3. C.Use the customer ID as the message key
  4. D.Create a separate topic for every customer
Show answer

Answer: C. Use the customer ID as the message key

The default partitioner hashes the key, so all messages with the same customer ID land in the same partition, and Kafka keeps order within a partition. Null or random keys spread one customer's messages across partitions and lose ordering. A topic per customer does not scale.

2. What MessageGroupId does

In an SQS FIFO queue, what does the MessageGroupId control?

  1. A.All messages in the queue share one strict global order
  2. B.Which consumer process is allowed to read the message
  3. C.Messages in one group are delivered in order, one batch at a time
  4. D.How long the message waits before it is visible
Show answer

Answer: C. Messages in one group are delivered in order, one batch at a time

Ordering in FIFO queues is per message group. Messages with the same group ID are delivered in order, and SQS will not hand out the next ones in that group while earlier ones are in flight. Different groups can be processed in parallel, so use a key like order ID or customer ID.

3. When streaming is needed

Which use case most clearly needs stream processing rather than a daily batch job?

  1. A.A monthly finance report
  2. B.Detecting card fraud within seconds of a transaction
  3. C.A weekly marketing email list
  4. D.Yearly tax summaries
Show answer

Answer: B. Detecting card fraud within seconds of a transaction

Fraud detection must react within seconds, so events must be processed continuously as they arrive. Monthly, weekly and yearly reports are fine with batch processing, which is simpler and cheaper.

4. Where Avro fits

Why is Avro a popular choice for messages in Kafka pipelines?

  1. A.It is a columnar format that is ideal for scanning one column
  2. B.It is a compact row-based binary format with a schema that supports evolution, often managed by a schema registry
  3. C.It stores data as human-readable text
  4. D.It automatically deduplicates messages
Show answer

Answer: B. It is a compact row-based binary format with a schema that supports evolution, often managed by a schema registry

Avro encodes each record compactly in binary and is defined by a schema. Writers and readers can use different but compatible schema versions, which suits long-lived event streams. A schema registry stores those versions and checks compatibility rules.

5. Kafka consumer groups

Within a single Kafka consumer group, how are the partitions of a topic shared?

  1. A.Every consumer reads every partition
  2. B.Only the oldest consumer reads, the others wait
  3. C.Each partition is assigned to exactly one consumer in the group at a time
  4. D.Messages are shared randomly one by one between consumers
Show answer

Answer: C. Each partition is assigned to exactly one consumer in the group at a time

Kafka assigns each partition to one consumer in the group, so the group splits the work and each message is processed once by the group. Different consumer groups each get their own full copy of the stream.

6. Topics and partitions

A Kafka topic called orders is created with 12 partitions. What is a partition?

  1. A.An ordered, append-only log that holds part of the topic's records
  2. B.A copy of the whole topic kept on a different broker for safety
  3. C.A filter that decides which consumers may read a record
  4. D.A time window that groups records arriving in the same minute
Show answer

Answer: A. An ordered, append-only log that holds part of the topic's records

A topic is split into partitions, and each partition is an ordered, append-only log stored on a broker. Partitions are the unit of parallelism: different partitions can live on different brokers and be read by different consumers at the same time. Copies for safety are replicas, which is a separate idea.

7. Replication factor of three

A topic is created with replication factor 3. What does that mean?

  1. A.Each record is sent to three consumer groups
  2. B.Each producer retries a failed send three times
  3. C.Each partition is stored on three different brokers
  4. D.The topic is split into three partitions
Show answer

Answer: C. Each partition is stored on three different brokers

Replication factor is the number of copies of each partition, each on a different broker. With 3 copies, the partition survives the loss of up to two brokers without losing data that all replicas had received. It has nothing to do with the number of partitions or consumer groups.

8. Producer with acks=0

A producer is configured with acks=0. What does it wait for before treating a send as done?

  1. A.Nothing; it does not wait for any broker reply
  2. B.A reply from the leader after it writes the record
  3. C.Replies from every in-sync replica
  4. D.A reply from the consumer that reads the record
Show answer

Answer: A. Nothing; it does not wait for any broker reply

With acks=0 the producer sends and moves on without any acknowledgement, so it gets the highest throughput but can silently lose records. acks=1 waits for the leader only, and acks=all waits for all in-sync replicas. Consumers never acknowledge to producers.

9. Total lag over three partitions

A group reads a topic with three partitions. Log end offsets are 1,250, 900 and 2,000. Committed offsets are 1,000, 900 and 1,700. What is the total lag?

  1. A.300
  2. B.250
  3. C.550
  4. D.1,550
Show answer

Answer: C. 550

Lag per partition is log end offset minus committed offset: 1,250 − 1,000 = 250, 900 − 900 = 0 and 2,000 − 1,700 = 300. The total is 550. Look at per-partition lag too, because one stuck partition can hide behind a small total.

10. Why use a schema registry

Your team adds a schema registry next to Kafka for Avro events. What problem does it solve?

  1. A.It stores the events so brokers need less disk
  2. B.It routes events to the right consumer group
  3. C.It stores versioned schemas and blocks incompatible changes
  4. D.It replaces the need for topics
Show answer

Answer: C. It stores versioned schemas and blocks incompatible changes

A schema registry stores each schema version under a subject and gives it an ID that is written into each message. Producers and consumers fetch schemas by ID, and the registry checks compatibility rules before accepting a new version, so one team cannot break readers by accident.

11. Kafka compared with a classic queue

Compared with a classic message queue that deletes a message once it is acknowledged, what can Kafka do that the queue usually cannot?

  1. A.Guarantee global order across all partitions
  2. B.Send each message to exactly one consumer in the world
  3. C.Delete messages as soon as they are read
  4. D.Let many groups read the same data and replay it from an older offset
Show answer

Answer: D. Let many groups read the same data and replay it from an older offset

Kafka keeps records for the retention period whatever consumers do. Each group tracks its own offset, so several applications can read the same stream, and any group can rewind to reprocess. Ordering is only per partition.

12. Event time and processing time

A delivery app's phone sends a GPS ping stamped 10:02, but it reaches the stream job at 10:09 after the phone regains network. Which statement is right?

  1. A.Event time is 10:02 and processing time is 10:09
  2. B.Event time is 10:09 and processing time is 10:02
  3. C.Both times are 10:09, since that is when Kafka got it
  4. D.Both times are 10:02, since the phone set them
Show answer

Answer: A. Event time is 10:02 and processing time is 10:09

Event time is when the thing happened, usually stamped by the source. Processing time is when the system handles it. Grouping by event time gives correct business answers even when data arrives late, but it needs watermarks to decide when a window is complete.

13. What a Flink checkpoint is

A Flink job has checkpointing every 60 seconds. What does a checkpoint contain?

  1. A.A copy of every input record from the last minute
  2. B.A consistent snapshot of operator state and source offsets
  3. C.Only the job's configuration and JAR file
  4. D.Log lines for debugging failures
Show answer

Answer: B. A consistent snapshot of operator state and source offsets

A checkpoint is a consistent snapshot of all operator state together with the source positions, such as Kafka offsets. After a failure, Flink restores the latest checkpoint and rewinds the sources to match, so state is exactly as if each record was processed once.

14. How Spark Structured Streaming runs

By default, how does Spark Structured Streaming process a Kafka stream?

  1. A.As small batch jobs, one per trigger
  2. B.One record at a time, as each one arrives
  3. C.Once a day, as a nightly batch
  4. D.Only when a user runs a query
Show answer

Answer: A. As small batch jobs, one per trigger

The default engine runs micro-batches: on each trigger it reads the new offsets, processes them as a small batch and updates state and sinks. Latency is usually from a few hundred milliseconds to seconds, which suits most pipelines. Record-at-a-time engines like Flink can go lower.

15. Spotting a sequence of events

A bank wants to flag a card when three failed PIN attempts are followed by a successful cash withdrawal within 5 minutes. What kind of stream processing is this?

  1. A.A simple tumbling count
  2. B.Complex event processing
  3. C.A batch join run each night
  4. D.Log compaction
Show answer

Answer: B. Complex event processing

Complex event processing detects ordered patterns of events within time limits. Flink CEP and SQL MATCH_RECOGNIZE express rules like 'three failures, then a success, within 5 minutes' per key. A simple count would ignore order.

16. Encrypting traffic to brokers

Security asks that card data sent between producers and Kafka brokers cannot be read on the network. What do you enable?

  1. A.TLS on the broker listeners and clients
  2. B.Producer compression with zstd
  3. C.Log compaction on the topic
  4. D.A higher replication factor
Show answer

Answer: A. TLS on the broker listeners and clients

TLS (often shown as SSL in Kafka settings) encrypts data in transit between clients and brokers, and between brokers. Compression only shrinks data and anyone can decompress it. For data at rest, use disk or volume encryption, or encrypt fields in the application.

17. Only one service may write

Only the payments service should be able to write to the payments topic, while several teams may read it. Which Kafka feature enforces this?

  1. A.Consumer group IDs
  2. B.ACLs tied to authenticated principals
  3. C.Topic retention settings
  4. D.Schema Registry compatibility rules
Show answer

Answer: B. ACLs tied to authenticated principals

With authentication on (SASL or mTLS), each client has a principal, and ACLs grant operations like Write or Read on topics to specific principals. You grant Write on payments to the payments service only and Read to the consumer teams. Group IDs are not a security control.

18. Not running brokers yourself

A small team wants Kafka without patching and scaling brokers. Which option fits?

  1. A.Run Kafka on a single laptop
  2. B.Use a relational database as the broker
  3. C.Copy the topic files to S3 each night
  4. D.A managed service such as Amazon MSK
Show answer

Answer: D. A managed service such as Amazon MSK

Managed Kafka services run the brokers, upgrades, storage and monitoring for you, and you connect with normal Kafka clients. Azure Event Hubs and others also offer Kafka-compatible endpoints. You still own topic design, partition counts and client settings.

19. Typos that create topics

A developer's producer has a typo, orderz instead of orders, and a new topic appears with default settings. Which broker setting prevents this?

  1. A.unclean.leader.election.enable=false
  2. B.auto.create.topics.enable=false
  3. C.log.retention.hours=1
  4. D.num.partitions=1
Show answer

Answer: B. auto.create.topics.enable=false

With auto-creation on, any produce or metadata request for an unknown topic makes one with default partitions and settings. Turning it off makes typos fail loudly, and topics are created on purpose with the right partitions, replication and retention.

20. Where to put a trace ID

You want a trace ID carried with each event so logs across services can be linked, without changing the event's Avro schema. Where can it go?

  1. A.In the partition number
  2. B.In the consumer group name
  3. C.In a record header
  4. D.In the topic name
Show answer

Answer: C. In a record header

Kafka records can carry headers: key-value pairs separate from the key and value. They suit metadata like trace IDs, source system or content type. OpenTelemetry instrumentation for Kafka uses headers to pass trace context.

Kafka intermediate interview questions medium

21. Moving average over a stream

A service computes a moving average of the last 100 response times from an endless stream. What data structure keeps memory fixed?

  1. A.An array that grows with every reading
  2. B.A sorted list of all readings
  3. C.A circular buffer of size 100 plus a running sum
  4. D.A hash map from time to reading
Show answer

Answer: C. A circular buffer of size 100 plus a running sum

A ring buffer overwrites the oldest slot with the newest reading. Subtract the overwritten value from the running sum and add the new one, so each update is O(1) and memory never grows.

22. Committing offsets too early

A Kafka consumer uses auto-commit and hands records to a background thread pool. The process crashes. Some records were never processed but are not reread on restart. Why?

  1. A.Kafka deletes records once any consumer reads them
  2. B.The crash reset the group to the latest offset
  3. C.Auto-commit only works with a single partition
  4. D.Offsets were committed before the work had finished
Show answer

Answer: D. Offsets were committed before the work had finished

Auto-commit commits the offsets returned by poll on a timer, regardless of whether a separate thread finished the work. After a crash the group resumes from the committed offset and skips the unfinished records. Commit manually after processing to get at-least-once behaviour.

23. Order lost with more workers

A single queue holds account events. The team scales from 1 to 5 consumers and now "AccountClosed" is sometimes handled before "AccountUpdated". Why?

  1. A.Parallel consumers finish messages in different orders
  2. B.The broker shuffles messages when consumers join
  3. C.Each consumer receives a full copy of the queue
  4. D.Acknowledgements reverse the delivery order
Show answer

Answer: A. Parallel consumers finish messages in different orders

The queue still delivers in order, but five consumers work in parallel and a later message can finish first. Strict per-entity order needs partitioning by key, such as Kafka keys or SQS FIFO message groups, so one entity's events go to one consumer at a time.

24. Message order guarantee in Kafka

A Kafka topic has 6 partitions. You need all events for one customer to be processed in order. What should you do?

  1. A.Use one consumer group per event type
  2. B.Use the customer id as the message key
  3. C.Send with no key, so messages are spread evenly
  4. D.Increase the partition count to 60
Show answer

Answer: B. Use the customer id as the message key

Kafka only guarantees order within a partition. Messages with the same key always go to the same partition, so one customer's events stay in order. With no key, events spread across partitions and can be read out of order.

25. Ordering in Kafka

You need all events for the same order_id to be processed in order. How should you produce to Kafka?

  1. A.Use a random partition for each message to balance load
  2. B.Create one topic per order
  3. C.Use one consumer group per message
  4. D.Use order_id as the message key so all its events go to the same partition
Show answer

Answer: D. Use order_id as the message key so all its events go to the same partition

Kafka only guarantees ordering within a partition. With order_id as the key, the default partitioner hashes it to the same partition every time, so one consumer reads those events in order.

26. Duplicates from at-least-once delivery

A consumer has at-least-once delivery from Kafka and writes to a warehouse. After a restart you see some duplicate rows. What is the right fix?

  1. A.Switch to at-most-once so nothing is ever repeated
  2. B.Reduce the number of partitions to 1
  3. C.Delete duplicates by hand each morning
  4. D.Make the write idempotent, for example MERGE on a unique event_id instead of a plain INSERT
Show answer

Answer: D. Make the write idempotent, for example MERGE on a unique event_id instead of a plain INSERT

At-least-once means messages may be redelivered after a failure, so duplicates are expected. Writing with an upsert or dedup on a stable event key makes repeats harmless. At-most-once would avoid duplicates but loses data instead.

27. Keeping changes to one row in order

CDC events go to a Kafka topic with 12 partitions. Updates to the same order must be applied in order. How should events be keyed?

  1. A.Randomly, to balance the partitions
  2. B.By the order's primary key
  3. C.By event timestamp
  4. D.By the table name only
Show answer

Answer: B. By the order's primary key

Kafka keeps order only within a partition, and the key decides the partition. Keying by primary key sends every change for one order to the same partition, so consumers see them in commit order. Random keys spread one order's changes across partitions.

28. One bad message blocks a stream

A stream consumer crashes on one malformed message, restarts, reads the same message and crashes again, so nothing moves. What is the standard pattern?

  1. A.Delete the topic and start over from zero
  2. B.After a few tries, send it to a dead-letter queue
  3. C.Lower the number of partitions in the topic
  4. D.Turn off offset commits for the consumer
Show answer

Answer: B. After a few tries, send it to a dead-letter queue

A message that always fails is a "poison pill". After limited retries, the consumer writes it to a dead-letter queue with the error and moves on, so the rest of the stream keeps flowing. The team then inspects, fixes and replays the dead letters.

29. acks=all with one broker down

A topic has replication factor 3 and min.insync.replicas=2. Producers use acks=all. One of the three brokers holding a partition goes down. What happens to writes to that partition?

  1. A.They fail until the broker comes back
  2. B.They succeed but are no longer replicated at all
  3. C.They keep succeeding, because two replicas are still in sync
  4. D.They succeed only if the leader was not the broker that died
Show answer

Answer: C. They keep succeeding, because two replicas are still in sync

With acks=all, a write needs acknowledgement from all current ISR members, and the ISR must have at least min.insync.replicas members. After one broker fails, two replicas remain in the ISR, which meets the minimum of 2, so writes continue. If the failed broker was the leader, a new leader is elected first.

30. Deleting a key from a compacted topic

You want a customer removed from a compacted topic so that new readers never see them. What do you produce?

  1. A.A record with the key and an empty string value
  2. B.A record with a header named delete=true
  3. C.A record with a new key and the old value
  4. D.A record with the key and a null value
Show answer

Answer: D. A record with the key and a null value

A record with a null value is a tombstone. Compaction removes earlier records for that key, and the tombstone itself is removed after delete.retention.ms. An empty string is still a real value, so it would be kept as the latest state.

31. Duplicates from producer retries

A producer sends a record, the broker writes it, but the acknowledgement is lost and the producer retries. Which setting stops the retry from creating a duplicate in the log?

  1. A.auto.offset.reset=earliest
  2. B.linger.ms=0
  3. C.compression.type=none
  4. D.enable.idempotence=true
Show answer

Answer: D. enable.idempotence=true

An idempotent producer gets a producer ID and attaches a sequence number to each batch per partition. The broker sees the retried batch has a sequence it already wrote and discards it. Idempotence is on by default in modern clients, but it only covers retries within one producer session.

32. Partitions for a throughput target

A topic must handle 600 MB/s at peak. Tests show one consumer can process 20 MB/s from a partition, and producers are not the bottleneck. What is the minimum partition count so consumers keep up?

  1. A.6
  2. B.12
  3. C.20
  4. D.30
Show answer

Answer: D. 30

Within one group, each partition is read by at most one consumer, so total read speed is limited by partitions × per-partition speed. 600 ÷ 20 = 30 partitions. In practice add headroom for growth, because adding partitions later changes key-to-partition mapping.

33. One record that always fails

A consumer crashes on one malformed record, restarts, reads the same record and crashes again, so the partition is stuck. What is the standard fix?

  1. A.Delete the topic and recreate it
  2. B.Raise session.timeout.ms so the crash is ignored
  3. C.Switch the producer to acks=0
  4. D.Send the record to a dead letter topic and move on
Show answer

Answer: D. Send the record to a dead letter topic and move on

A record that can never be processed is a poison pill. Catching the failure, writing the record with error details to a dead letter topic, and committing past it keeps the partition moving. Someone can then inspect and replay the dead letters after a fix.

34. How the outbox pattern works

Which approach implements the transactional outbox pattern?

  1. A.Publish to Kafka first, then write to the database
  2. B.Write to Kafka and the database in parallel threads
  3. C.Let consumers read the orders table directly over JDBC
  4. D.Write the event to an outbox table in the same DB transaction
Show answer

Answer: D. Write the event to an outbox table in the same DB transaction

The order row and the outbox row commit together in one local transaction, so they cannot disagree. A separate relay, often Debezium reading the outbox via CDC, publishes those rows to Kafka. Delivery is at-least-once, so consumers should be idempotent.

35. Unique visitors per minute at scale

A stream job must report unique visitors per minute for a site with 50 million users, and a 1–2% error is fine. What keeps state small?

  1. A.A HyperLogLog sketch per window
  2. B.A set of all user IDs per window
  3. C.Sorting user IDs and counting changes
  4. D.Counting every event as a new user
Show answer

Answer: A. A HyperLogLog sketch per window

HyperLogLog estimates distinct counts with a fixed size of a few kilobytes, regardless of how many users there are, with roughly 1–2% error. Sketches can also be merged across windows or partitions. An exact set per window would need gigabytes.

36. Key for order lifecycle events

Order events (created, paid, packed, shipped) must be processed in order for each order. Customers can have many orders. Which key fits best?

  1. A.A random UUID per event
  2. B.No key, for even spread
  3. C.order_id
  4. D.The event type, such as paid
Show answer

Answer: C. order_id

Kafka keeps order within a partition, and a key pins all its events to one partition. Keying by order_id keeps each order's events in order while spreading many orders evenly. customer_id would also keep order, but large customers could make hot partitions.

37. When a producer gives up

During a broker outage, a producer with default retries keeps retrying a batch. Which setting decides when it stops and reports the send as failed?

  1. A.linger.ms
  2. B.delivery.timeout.ms
  3. C.session.timeout.ms
  4. D.max.poll.interval.ms
Show answer

Answer: B. delivery.timeout.ms

Modern producers retry almost without limit, and delivery.timeout.ms (2 minutes by default) caps the total time from send() to success or failure. After that the callback gets an error, and the app must decide whether to log, buffer or alert. Silent loss happens when apps ignore that callback.

38. One client slows the cluster

A reporting job re-reads a large topic at full speed every hour and slows production traffic for everyone. Which feature limits it without blocking it?

  1. A.Client quotas on bytes per second
  2. B.Log compaction on the topic
  3. C.Deleting its consumer group
  4. D.A lower replication factor
Show answer

Answer: A. Client quotas on bytes per second

Kafka quotas cap produce and fetch rates per user or client ID. A client over its quota is slowed by throttling, not cut off, so critical clients get their share. Request-rate quotas can also cap CPU time spent on a client.

39. The target database is down

A consumer writes to a database that is down for 10 minutes. Retrying each record in a tight loop risks max.poll.interval.ms and a rebalance. What is a better approach?

  1. A.Commit offsets and skip records until the database returns
  2. B.Raise session.timeout.ms to one hour
  3. C.Pause the partitions, keep polling, and resume when it recovers
  4. D.Close the consumer and start it again from earliest
Show answer

Answer: C. Pause the partitions, keep polling, and resume when it recovers

consumer.pause() stops fetching records for chosen partitions while poll() keeps the consumer alive in the group. When the database is back, resume() continues from the same position. Skipping records would lose data.

40. Which timestamp a record carries

A topic sets message.timestamp.type=LogAppendTime. What timestamp do records on it carry?

  1. A.The time the consumer read the record
  2. B.The time the broker appended the record to the log
  3. C.The time the producer created the record
  4. D.The time the segment was rolled
Show answer

Answer: B. The time the broker appended the record to the log

With the default CreateTime, the record keeps the timestamp set by the producer, usually the event time. With LogAppendTime, the broker overwrites it with its own clock when it writes the record. That is useful when client clocks cannot be trusted, but it loses the original event time.

Kafka interview questions for experienced candidates hard

41. Account events processed out of order

An "account debited" event is sometimes processed before the "account opened" event for the same account. The producer sends messages without a key to a 12-partition topic. What is the fix?

  1. A.Create a separate consumer group for each account
  2. B.Increase the number of partitions to 48
  3. C.Have each consumer buffer messages for a few seconds and sort them by producer timestamp before processing
  4. D.Use the account id as the message key so all of an account's events go to the same partition
Show answer

Answer: D. Use the account id as the message key so all of an account's events go to the same partition

Kafka guarantees order only within a partition. Without a key, events for one account spread across partitions and are consumed in parallel. Keying by account id sends them to one partition, in order, while different accounts still scale across partitions. Sorting by timestamp in the consumer cannot fix events that arrive in different partitions.

42. Calculating consumer lag

A Kafka partition's log-end offset is 10,500. The consumer group's committed offset is 10,200 and the consumer processes 50 records per second while producers write 20 per second. What is the lag, and how long to catch up?

  1. A.300 records, about 6 seconds
  2. B.10,200 records, about 3 minutes
  3. C.300 records, about 10 seconds
  4. D.10,500 records, about 3.5 minutes
Show answer

Answer: C. 300 records, about 10 seconds

Lag is log-end offset minus committed offset: 10,500 - 10,200 = 300. The consumer gains on the producer at 50 - 20 = 30 records per second, so 300 / 30 = 10 seconds. Dividing by 50 alone ignores the records still being produced.

43. Duplicates from producer retries

A Kafka producer times out waiting for an ack and retries, and the topic ends up with duplicate records. What setting addresses this?

  1. A.enable.idempotence=true on the producer
  2. B.acks=0 so the producer never waits
  3. C.auto.offset.reset=earliest on consumers
  4. D.A larger linger.ms to batch records
Show answer

Answer: A. enable.idempotence=true on the producer

With idempotence the producer gets an ID and sends sequence numbers, so the broker discards a retried batch it already wrote. It is on by default in modern Kafka clients unless conflicting settings disable it. acks=0 hides the problem by risking data loss instead.

44. Adding partitions to a keyed topic

A keyed Kafka topic is increased from 6 to 12 partitions to handle more load. What risk does this create for per-key ordering?

  1. A.Kafka rewrites old records into the new partitions
  2. B.Consumers must be restarted with new group IDs
  3. C.Each key will now be split across 12 partitions
  4. D.Keys can map to a new partition while old events wait
Show answer

Answer: D. Keys can map to a new partition while old events wait

The default partitioner is hash(key) mod partition count, so changing the count moves many keys to different partitions. New events for a key can be read from the new partition before older ones in the old partition are consumed. Plan partition counts ahead, or drain and switch carefully.

45. Streaming counts that run high

A streaming job counts purchases per user for a real-time feature. After a consumer restart, some counts are higher than the source data. What is the cause and fix?

  1. A.Clock skew; switch every server to UTC
  2. B.The model needs retraining
  3. C.The feature store is too slow; add caching
  4. D.Messages were redelivered under at-least-once delivery; deduplicate by event ID or make updates idempotent
Show answer

Answer: D. Messages were redelivered under at-least-once delivery; deduplicate by event ID or make updates idempotent

Most streaming systems guarantee at-least-once delivery, so after a failure some events are processed twice. Counters that just increment then double count. Use event IDs for deduplication, idempotent upserts or exactly-once features of the stream processor, and reconcile against batch counts.

46. Late events missing from counts

A Flink job computes 10-minute counts with a watermark 2 minutes behind the latest event time. Mobile events often arrive 5 minutes late. What happens to them?

  1. A.They are added to the next window automatically instead
  2. B.They make the streaming job crash with an error
  3. C.Their window has closed, so they are dropped or side-output
  4. D.They are counted twice so that nothing is lost
Show answer

Answer: C. Their window has closed, so they are dropped or side-output

The watermark tells the engine when a window is complete. Events with timestamps older than the watermark are late; unless you set allowed lateness or a side output, they are discarded, and features undercount.

47. Showing JSON while it streams

You stream a structured JSON reply to a UI to show fields as they arrive. JSON.parse fails on every chunk until the end. What is the right approach?

  1. A.Use an incremental JSON parser that accepts partial input
  2. B.Retry the stream until the first chunk is valid JSON
  3. C.Set temperature to 0 so each chunk is complete JSON
  4. D.Ask the model to send the closing brace first
Show answer

Answer: A. Use an incremental JSON parser that accepts partial input

A partial stream is not valid JSON, so normal parsers fail. Incremental or partial JSON parsers (or SDK helpers that emit partial objects) let you render fields as they appear, while you still validate the final full object.

48. Adding partitions to a keyed topic

A topic keyed by order_id has 12 partitions, and consumers rely on all events for an order being in order. You increase it to 24 partitions. What is the risk?

  1. A.Old messages are deleted
  2. B.New events for an existing order_id may go to a different partition than its earlier events, so per-key ordering can break during the transition
  3. C.Kafka rejects keyed messages after the change
  4. D.Consumers can no longer use consumer groups
Show answer

Answer: B. New events for an existing order_id may go to a different partition than its earlier events, so per-key ordering can break during the transition

The default partitioner maps a key with hash(key) mod number of partitions. Changing the count changes the mapping, so a key that used to land in partition 3 may now land elsewhere while old events are still being consumed from partition 3. Plan partition counts ahead, or create a new topic and migrate consumers carefully.

49. Rows missed by a strict watermark

An incremental job loads WHERE updated_at > MAX(updated_at) in the target. Replication from the source sometimes commits rows a few minutes late with older updated_at values, and those rows never appear. What is a robust fix?

  1. A.Run the job less often
  2. B.Re-read a lookback window (for example updated_at > max - 3 hours) and MERGE on the primary key, so overlap is safe
  3. C.Use updated_at >= instead of >
  4. D.Switch from MERGE to INSERT for speed
Show answer

Answer: B. Re-read a lookback window (for example updated_at > max - 3 hours) and MERGE on the primary key, so overlap is safe

A strict watermark assumes rows arrive in updated_at order, which replication lag and long transactions break. Reprocessing an overlapping window catches late commits, and an idempotent MERGE on the key prevents duplicates from the overlap. Log-based CDC avoids the problem by reading commit order directly.

50. Adding consumers to cut lag

A Kafka topic has 12 partitions and consumer lag keeps growing. The team scales the consumer group from 12 to 20 instances. What happens?

  1. A.Throughput rises by about two thirds
  2. B.Each partition is shared by about 1.7 consumers
  3. C.The topic gains 8 new partitions
  4. D.Only 12 consumers get partitions; 8 sit idle
Show answer

Answer: D. Only 12 consumers get partitions; 8 sit idle

Within a consumer group, each partition is read by one consumer at a time, so parallelism is capped by the partition count. To go wider, add partitions (which changes key-to-partition mapping) or make each consumer faster, for example with batching.

51. Risk of unclean leader election

All in-sync replicas of a partition are down, and only an out-of-sync follower is alive. If unclean.leader.election.enable=true, what is the trade-off?

  1. A.It comes back online sooner, but some committed records may be lost
  2. B.The partition stays offline until a clean replica returns
  3. C.Producers must switch to acks=0 until the ISR recovers
  4. D.Consumers reread the partition from offset zero
Show answer

Answer: A. It comes back online sooner, but some committed records may be lost

Unclean leader election lets a replica that was not in sync become leader. The partition becomes available again, but any records the old leader had committed that this follower never copied are gone. The default is false, which keeps data safe at the cost of the partition staying unavailable.

52. Why cooperative rebalancing

With the classic eager protocol, every rebalance makes all consumers drop all partitions. What does the CooperativeStickyAssignor change?

  1. A.It removes the need for a group coordinator
  2. B.It assigns every partition to every consumer
  3. C.It moves partitions only at night to avoid busy hours
  4. D.Only partitions changing owner are paused; others keep running
Show answer

Answer: D. Only partitions changing owner are paused; others keep running

Eager rebalancing is stop-the-world: everyone revokes everything, then gets a new assignment. Cooperative incremental rebalancing revokes only the partitions that change owner, so most consumers keep processing. Sticky assignment also tries to keep partitions where they were, which preserves local caches and state.

53. Producers upgrade before consumers

Producers will move to a new schema before consumers are updated, so old consumers must read new data. Which compatibility mode protects this rollout order?

  1. A.FORWARD
  2. B.BACKWARD
  3. C.NONE
  4. D.It does not matter, Avro handles any change
Show answer

Answer: A. FORWARD

FORWARD compatibility means data written with the new schema can be read by the previous schema. That is what you need when producers upgrade first. BACKWARD suits the opposite order, where consumers upgrade first. FULL checks both ways.

54. Consumers and aborted transactions

A transactional producer writes records and then aborts the transaction. A consumer uses isolation.level=read_committed. What does it see?

  1. A.It does not see the aborted records
  2. B.It sees them with a header marking them aborted
  3. C.It sees them once the producer retries
  4. D.It sees them only if it uses acks=all
Show answer

Answer: A. It does not see the aborted records

With read_committed, the consumer only returns records from committed transactions and skips aborted ones. It also stops at the last stable offset, so it waits behind open transactions. The default read_uncommitted returns everything, including aborted records.

55. Two copies of the same producer

A stream app instance freezes, a replacement starts with the same transactional.id, and then the old one wakes up and tries to commit. What does Kafka do?

  1. A.It accepts both commits, creating duplicates
  2. B.It fences the old producer, so its writes fail
  3. C.It merges the two transactions into one
  4. D.It lets whichever commits first win, then aborts the other
Show answer

Answer: B. It fences the old producer, so its writes fail

When the new instance calls initTransactions with the same transactional.id, the coordinator bumps the producer epoch. The old zombie still has the old epoch, so its writes and commit are rejected with a fencing error. This is how Kafka prevents duplicate output from a revived instance.

56. Which window Spark has emitted

A Spark query uses withWatermark("ts", "10 minutes"), 5-minute tumbling windows and append output mode. The highest event time seen so far is 12:20. Which window has been written to the sink?

  1. A.[12:15, 12:20)
  2. B.[12:10, 12:15)
  3. C.[12:05, 12:10)
  4. D.No window, since append mode waits for the query to stop
Show answer

Answer: C. [12:05, 12:10)

The watermark is 12:20 − 10 minutes = 12:10. In append mode, a window is written only once the watermark passes its end, so [12:05, 12:10) is final and emitted. [12:10, 12:15) could still get late data, so it waits.

57. Duplicate rows from foreachBatch

A Spark query uses foreachBatch to append each micro-batch into a warehouse table. After a crash, one batch appears twice. What is the standard fix?

  1. A.Make the write idempotent using the batchId, e.g. a MERGE
  2. B.Switch the trigger to run once per hour instead
  3. C.Remove the checkpointLocation
  4. D.Set the Kafka source to startingOffsets=latest
Show answer

Answer: A. Make the write idempotent using the batchId, e.g. a MERGE

Spark may re-run the last batch after a failure, so foreachBatch gives at-least-once by default. Each call gets a batchId that is the same on replay. Recording processed batch IDs in the target, or using a MERGE on a unique key, makes the replay harmless.

58. Memory for hopping window state

A job tracks 2 million active users in 1-hour hopping windows that advance every 10 minutes. Each window aggregate takes about 100 bytes. Roughly how much state is held at once?

  1. A.About 200 MB
  2. B.About 12 GB
  3. C.About 20 MB
  4. D.About 1.2 GB
Show answer

Answer: D. About 1.2 GB

Each user is in 60 ÷ 10 = 6 open windows at a time. 2,000,000 × 6 × 100 bytes = 1.2 billion bytes, about 1.2 GB, before store overhead and grace periods. Overlapping windows multiply state, which is why window design affects cost.

59. Cost of salting a hot key

To spread the big merchant's load, you change its key to merchant_id + '-' + (order_id % 8). What do you give up?

  1. A.Nothing; ordering is still kept for every order
  2. B.One ordered stream for all of that merchant's events
  3. C.Replication for all of that merchant's records
  4. D.The ability to compress those records
Show answer

Answer: B. One ordered stream for all of that merchant's events

Salting spreads one key over several partitions, so throughput improves, but events for that merchant no longer have one order. Events for a single order still share a partition, since order_id picks the salt. Any per-merchant aggregate now needs a second step to combine the 8 parts.

60. Disk cap from retention.bytes

A topic has 24 partitions, replication factor 3 and retention.bytes = 10 GB. Ignoring the active segment, what is the most the topic can use across the cluster?

  1. A.10 GB
  2. B.30 GB
  3. C.720 GB
  4. D.240 GB
Show answer

Answer: C. 720 GB

retention.bytes applies to each partition, not the whole topic. 24 partitions × 10 GB = 240 GB for one copy, and each replica keeps its own, so × 3 = 720 GB. Many teams set this expecting a topic-wide cap and are surprised.

Ready to test yourself?

Take a 15-question Kafka MCQ test with a score at the end, or practise the full Kafka question bank and earn points on the leaderboard.