Sample questions
Question 1Easy
Which role does a Kafka producer play?
- It writes records to topics
- It reads records from topics
- It elects the partition leader
- It stores partitions on disk
Answer: A. It writes records to topics
Explanation
Producers publish; brokers store; consumers read.
Step-by-step solution
- A producer is the client that publishes records to a topic.
- Brokers store the partitions, and consumers read the records.
- Electing a partition leader is done inside the Kafka cluster, not by a producer.
- The correct answer is 0: a producer writes records to topics.
Why the other options are wrong
- B. Reading records is the consumer's role.
- C. Leader election is handled inside the Kafka cluster, not by producers.
- D. Brokers store partitions on disk; a producer only sends records.
Tip: Producers write, brokers store, consumers read.
Question 2Easy
A Kafka consumer group rebalance happens when:
- A producer sends a message without a key
- The topic's retention period expires
- Consumers join or leave, or partitions change
- A message is larger than one kilobyte
Answer: C. Consumers join or leave, or partitions change
Explanation
Partitions are reassigned among the current members.
Step-by-step solution
- A consumer group shares a topic's partitions among its current members.
- A rebalance reassigns partitions when a consumer joins or leaves, or when partitions change.
- Message keys, message size and retention do not change group membership.
- The correct answer is option C: consumers join or leave, or partitions change.
Why the other options are wrong
- A. A missing key changes how a message is routed, but it does not trigger a rebalance.
- B. Retention deletes old messages; it does not reassign consumers.
- D. Message size does not affect group membership.
Tip: A rebalance follows a membership or partition change; plan for it in consumers.
Question 3Easy
Within one consumer group, each partition is read by:
- No consumer until a rebalance happens
- Only the consumer with the lowest ID
- Exactly one consumer at a time
- Every consumer in the group at once
Answer: C. Exactly one consumer at a time
Explanation
Partitions are divided among the group's consumers; this is how a group shares the work.
Step-by-step solution
- Each partition is assigned to one consumer in the group.
- A single consumer reads data from its assigned partition.
- Only one consumer can read a partition at any time.
- If a consumer leaves, the partition is reassigned, but only one reads it at once.
- Exactly one consumer at a time reads each partition.
Why the other options are wrong
- A. Consumers in a group are assigned partitions straight away, not only after a rebalance happens.
- B. The lowest consumer ID does not decide who reads a partition; the group coordinator assigns partitions.
- D. Every consumer reading a partition at once is wrong within one group; each partition has one reader.
Question 4Easy
Kafka retention settings control:
- Which users may create new topics
- How messages are encrypted in transit
- How many consumers may join a group
- How long or how much data is kept
Answer: D. How long or how much data is kept
Explanation
Data is deleted by age or size limits (or compacted), independent of consumption.
Step-by-step solution
- Kafka retention settings decide when data is removed.
- Data is deleted based on time or storage limits.
- This controls the amount of data kept in the system.
- Retention settings do not affect message encryption.
- Retention settings do not control consumer group size.
- Retention settings determine how long or how much data is stored.
Why the other options are wrong
- A. Topic creation rights are access control settings, not retention settings.
- B. Encryption in transit is set by TLS settings, not by retention settings.
- C. How many consumers can join a group is about group membership, not how long data is kept.
Question 5Medium
Why do producers often set the message key to the customer ID?
- Kafka rejects any message that does not carry a key, so a key is always required
- All events for that customer go to one partition, keeping their order
- Keys make every message smaller after compression on disk
- Keys allow consumers to skip reading other partitions
Answer: B. All events for that customer go to one partition, keeping their order
Explanation
The default partitioner hashes the key, so the same key always maps to the same partition.
Step-by-step solution
- Producers use customer ID as message key to ensure all events go to one partition.
- Same key always maps to same partition, keeping event order intact.
- This avoids out-of-order processing in stream applications.
- Partitioning by customer ID groups related data together.
- All events for a customer are stored in one place for efficient retrieval.
Why the other options are wrong
- A. Kafka does not require a key on every message; messages without keys are accepted.
- C. Keys do not make messages smaller after compression; their purpose is routing to partitions.
- D. Keys do not let consumers skip partitions; consumers still read their assigned partitions.
Tip: Use the same key for related messages so Kafka puts them in one partition.
Question 6Medium
A consumer group reads 3 partitions with lags of 1,200, 0 and 3,400. What is the group's total lag?
- 4,600
- 1,200
- 3,400
- 1,533
Answer: A. 4,600
Explanation
Total lag is the sum over partitions: 1,200 + 0 + 3,400 = 4,600.
Step-by-step solution
- Total lag adds partition lags.
- 1,200 + 0 + 3,400.
- The total is 4,600.
Why the other options are wrong
- B. 1,200 is one partition.
- C. 3,400 is one partition.
- D. 1,533 is an average.
Tip: Total lag = sum.
Question 7Medium
Log compaction on a Kafka topic keeps:
- Every record forever with no deletion
- At least the latest record for each key
- Only the first record ever written
- Only records newer than seven days
Answer: B. At least the latest record for each key
Explanation
Compacted topics act like a changelog snapshot, useful for state and CDC tables.
Step-by-step solution
- Log compaction removes older records that have the same key as a newer record.
- The latest record for each key is always kept.
- So compaction keeps at least the latest record per key.
- The correct answer is option B: at least the latest record for each key.
Why the other options are wrong
- A. Compaction removes older records, so not every record is kept forever.
- C. The first record is the oldest; compaction keeps the newest value for each key.
- D. Compaction works by key, not by a seven-day age window.
Tip: A compacted topic keeps the latest value per key, like a changelog snapshot.
Question 8Medium
A consumer commits its offset before processing each batch, then crashes mid-batch. On restart, what delivery semantics did it get?
- No delivery: the whole topic is read again
- Exactly-once: every message is processed one time, thanks to the commit
- At-most-once: the unprocessed messages are skipped
- At-least-once: the messages are processed twice
Answer: C. At-most-once: the unprocessed messages are skipped
Explanation
The committed offset is already past the lost messages, so they are never processed.
Step-by-step solution
- The consumer commits its offset before it processes the batch.
- It crashes mid-batch, so the messages in that batch were never processed.
- On restart it resumes after the committed offset, so those messages are skipped.
- The correct answer is 2: at-most-once, because unprocessed messages are skipped.
Why the other options are wrong
- A. A restart resumes from the committed offset, not from the start of the topic.
- B. Exactly-once needs processing and commit to succeed together; committing first does not give that.
- D. At-least-once needs the commit after processing, so the batch would be read again.
Tip: Commit after processing for at-least-once; commit before processing for at-most-once.
Question 9Hard
Exactly-once processing within Kafka (read from a topic, process, write to another topic) relies on:
- Idempotent producers plus transactions that commit outputs and offsets atomically
- Writing every message twice and deduplicating on read
- Disabling consumer groups so that only a single consumer ever reads the topic at a time
- Setting the replication factor of every topic to exactly one
Answer: A. Idempotent producers plus transactions that commit outputs and offsets atomically
Explanation
The transaction makes the output records and the input offsets visible together or not at all.
Step-by-step solution
- Idempotent producers prevent duplicate writes.
- Transactions ensure both outputs and offsets are committed together.
- This guarantees exactly-once processing.
- No partial commits occur with transactions.
- Final answer: Idempotent producers plus transactions that commit outputs and offsets atomically.
Why the other options are wrong
- B. Writing every message twice and deduplicating is not how Kafka gets exactly-once processing.
- C. Disabling consumer groups does not give exactly-once; it only limits who reads the topic.
- D. Replication factor one reduces durability and does not give exactly-once processing.
Tip: Use transactions with idempotent producers for exactly-once semantics in Kafka.
Question 10Hard
With replication factor 3, min.insync.replicas = 2 and producers using acks=all, how many brokers holding a partition can fail while writes to it still succeed?
- 1
- 3
- 0
- 2
Answer: A. 1
Explanation
Writes need at least 2 in-sync replicas; losing 1 of 3 leaves 2, losing 2 leaves 1 and writes are rejected.
Step-by-step solution
- Replication factor 3 means three brokers hold a copy of each partition.
- min.insync.replicas 2 with acks=all needs two in-sync copies for a write to succeed.
- Losing one broker leaves two in-sync replicas, so writes still succeed.
- Losing two leaves one, which is below the minimum, so the correct answer is 1.
Why the other options are wrong
- B. Losing three brokers leaves no replicas at all, so writes fail.
- C. Zero is too strict; one failure still leaves the minimum of two replicas.
- D. Losing two leaves one in-sync replica, below the minimum of two, so writes stop.
Tip: Failures tolerated = replicas minus min.insync.replicas, here 3 minus 2 = 1.
Practise all 29 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →