Kafka Scenario-Based Interview Questions: 15+ Real-World Kafka Scenarios Explained Simply
If you are preparing for a Kafka interview, knowing only definitions is not enough. Many interviewers now ask scenario-based Kafka interview questions to check whether you really understand how Kafka works in real-world applications.
You may already know terms such as topic, partition, offset, consumer, consumer group, producer, replication, ISR, rebalance, and idempotency. But the real challenge starts when an interviewer gives you a situation and asks, “What will happen now?”
For example:
- What happens if a Kafka consumer crashes while processing a message?
- What happens if the offset is committed before processing?
- Can two consumers consume the same partition?
- What happens when there are more consumers than partitions?
- How does Kafka maintain message ordering?
- What happens when a broker fails?
- How can you prevent duplicate database updates?
- How does Kafka decide which partition receives a message?
This article explains these important Kafka scenario-based interview questions in very simple words. The goal is to help beginners, Java developers, backend developers, and experienced developers understand the practical side of Kafka.
What Is Kafka?
Apache Kafka is a distributed event streaming platform. It is commonly used when applications need to send, receive, and process large amounts of data.
A simple example is an e-commerce application.
Suppose a customer places an order. The order service can publish an event such as:
Order Created
Other services can consume this event:
- Inventory Service
- Payment Service
- Notification Service
- Shipping Service
- Analytics Service
Instead of directly connecting every service with every other service, Kafka can work as a middle layer.
The basic Kafka flow looks like this:
Producer โ Kafka Topic โ Partition โ Consumer
A topic can contain multiple partitions, and partitions allow Kafka to process large amounts of data in parallel.
1. What Happens When a Kafka Consumer Crashes Before Committing the Offset?
This is one of the most common Kafka scenario-based interview questions.
Suppose we have a topic with one partition:
- Offset 0 โ M1
- Offset 1 โ M2
- Offset 2 โ M3
A consumer starts processing M1.
The consumer receives M1, but while processing it, an exception occurs. The application crashes before committing the offset.
What happens when the consumer starts again?
The important point is that Kafka keeps track of consumer progress using the committed offset.
If the consumer did not commit the offset for M1, Kafka still considers the next starting position to be before M1.
Therefore, after restarting, the consumer can receive M1 again.
So:
M1 โ processing starts โ application crashes โ offset not committed โ consumer restarts โ M1 can be processed again
This is why understanding offsets is extremely important in Kafka interviews.
Why does Kafka do this?
Kafka does not assume that a message was successfully processed simply because the consumer fetched it.
Fetching a message and successfully processing a message are two different things.
The consumer may have:
- Received the message.
- Started processing it.
- Updated a database.
- Crashed before committing the offset.
Therefore, the committed offset is an important part of determining where the consumer resumes.
2. What Happens If the Consumer Commits the Offset Before Processing the Message?
Now consider a slightly different situation.
The consumer receives M1.
Before actually processing M1, it commits the offset.
Then the application crashes while processing M1.
What happens after restart?
The consumer sees that the committed position has already moved beyond M1. Therefore, it normally starts from the next offset.
For example:
- M1 โ offset 0
- M2 โ offset 1
- M3 โ offset 2
If the offset for M1 is committed before successful processing, the consumer may restart from M2.
That means M1 was never successfully completed, but the consumer group has already moved past it.
This is the danger of committing an offset before successful processing.
It can result in message loss from the consumer application’s point of view.
The message may still physically exist in Kafka because Kafka retention is independent of the consumer’s committed offset. However, the consumer group will not automatically go back to it.
What delivery behavior does this represent?
This approach is associated with at-most-once style processing.
The basic idea is:
Commit first, process later.
The advantage is that duplicate processing is less likely.
The disadvantage is that a crash can cause a message to be skipped by that consumer group.
For many database-processing applications, committing after successful processing is preferred.
3. Is the Message Permanently Deleted From Kafka?
No.
This is an important interview point.
Suppose M1 was at offset 0 and the consumer committed an offset that moves beyond M1.
M1 does not immediately disappear from Kafka.
Kafka stores records according to the topic’s retention configuration.
For example, a topic may be configured to retain messages for a certain amount of time or according to a storage limit.
Therefore, a consumer can potentially read an older message again by changing its position.
For example, a consumer can use the seek() operation to move to a particular offset.
An administrator can also reset consumer group offsets using Kafka’s consumer-group tools.
However, there is an important difference:
The message still exists in Kafka, but the consumer group’s normal position has moved past it.
That is why offset management is so important.
4. How Can You Consume an Old Kafka Message Again?
Suppose M1 is still available in Kafka, but the consumer group has already moved past offset 0.
There are several ways to read it again.
One approach is to use the consumer API’s seek() method.
For example, conceptually:
consumer.seek(partition, 0)
This tells the consumer to start reading from offset 0 for that partition.
Another approach is resetting the consumer group’s offsets using Kafka administration tools.
This is useful when:
- You need to replay events.
- A bug caused incorrect processing.
- You need to rebuild data.
- You want to reprocess historical events.
- A message was skipped accidentally.
But be careful.
If you reset the offset to an earlier position, the consumer may process messages that it has already processed.
That can create duplicate database operations.
This brings us to one of the most important Kafka concepts: idempotency.
5. How Do You Prevent Duplicate Database Updates?
Consider this scenario.
A consumer receives an order event:
Order ID = 1001
The consumer updates the database successfully.
But immediately after the database update, the consumer crashes.
It crashes before committing the Kafka offset.
When the application restarts, Kafka can deliver the same message again.
The consumer then tries to update the database again.
This is called duplicate processing.
A common solution is to make the processing idempotent.
What Is Idempotency?
An operation is idempotent when performing it multiple times produces the same final result as performing it once.
For example, suppose you receive:
Event ID = EVT1001
The database can store this event ID.
When the event arrives for the first time:
EVT1001 โ process โ save
If the same event arrives again:
EVT1001 โ already processed โ do not process again
This can be implemented using:
- A unique event ID.
- A unique database constraint.
- An upsert operation.
- A processed-events table.
- A business ID such as an order ID, where appropriate.
- Carefully designed database transactions.
The key idea is:
Do not assume that Kafka will always deliver each message only once to your application. Design the consumer so repeated processing is safe.
6. What Is a Kafka Consumer Group?
A consumer group is a group of consumers working together to consume a topic.
Suppose a topic has three partitions:
- P0
- P1
- P2
And the consumer group has three consumers:
- C1
- C2
- C3
Kafka can assign:
- C1 โ P0
- C2 โ P1
- C3 โ P2
This allows the three partitions to be processed in parallel.
The important rule is:
Within a consumer group, a partition is assigned to only one consumer at a time.
This helps Kafka achieve parallel processing while maintaining ordering within each partition.
7. What Happens If There Are More Consumers Than Partitions?
This is another popular Kafka scenario-based interview question.
Suppose we have:
3 partitions
and:
6 consumers
The six consumers cannot all actively consume at the same time because there are only three partitions.
A possible assignment could be:
- C1 โ P0
- C2 โ P1
- C3 โ P2
- C4 โ idle
- C5 โ idle
- C6 โ idle
The extra consumers remain idle.
This does not mean the consumers are useless forever.
If the topic gets additional partitions later, Kafka can rebalance the group and assign those partitions to available consumers.
Important interview point
Adding more consumers does not automatically increase throughput.
You need enough partitions to provide parallelism.
8. What Happens If There Are More Partitions Than Consumers?
Now consider the opposite situation.
Suppose we have:
10 partitions
and:
3 consumers
Kafka can assign multiple partitions to the same consumer.
For example:
- C1 โ 4 partitions
- C2 โ 3 partitions
- C3 โ 3 partitions
The exact assignment depends on the partition assignment strategy.
Yes, a single consumer can consume from multiple partitions.
This is completely normal.
Therefore:
More partitions than consumers โ some consumers handle multiple partitions.
More consumers than partitions โ some consumers remain idle.
9. How Do You Scale Kafka Consumers?
Suppose your application is processing messages too slowly.
You might think:
“Let’s add more consumers.”
That can help, but only when there are enough partitions.
Suppose you have 10 partitions.
You can increase the consumer group size up to around 10 active consumers for partition-level parallelism.
If you add an 11th consumer without increasing the partition count, there is no additional partition for that consumer to own.
So it will remain idle.
If you need more consumer parallelism, you may need to increase the number of partitions.
However, partition count should be planned carefully because changing partition counts can affect ordering and workload distribution.
10. Does Kafka Guarantee Message Ordering?
Yes, but only within a partition.
This is one of the most important Kafka interview questions.
Suppose partition P0 contains:
- M1
- M2
- M3
- M4
Kafka maintains the order of records within that partition.
So a consumer reading P0 can process them in that order.
But suppose the topic has five partitions:
- P0
- P1
- P2
- P3
- P4
Kafka does not provide one global ordering across all five partitions.
For example:
P0: A1 โ A2 โ A3
P1: B1 โ B2 โ B3
Kafka does not promise that consumers will observe:
A1, A2, A3, B1, B2, B3
as one global order.
The messages can be processed independently across partitions.
Therefore, remember this simple rule:
Kafka guarantees ordering within a partition, not across the entire topic.
11. How Do You Keep Related Messages in Order?
Suppose you have an order system.
You want all events related to:
Order ID = 5001
to remain in the same partition.
The producer can use a message key.
For example:
key = OrderID
Kafka’s partitioning logic uses the key to consistently select a partition for records with the same key, subject to the partitioning configuration.
So messages with the same key are routed to the same partition when using the standard keyed partitioning behavior.
For example:
Order 5001 โ P2
Order 5001 โ P2
Order 5001 โ P2
This allows their relative order to be preserved within that partition.
Common keys include:
- Order ID
- User ID
- Account ID
- Product ID
- Customer ID
But choosing a key requires care.
12. What Is a Hot Partition?
A hot partition happens when one partition receives significantly more traffic than the others.
Suppose you choose a key that has poor distribution.
Imagine one customer generates millions of events while thousands of other customers generate very few.
If the partitioning strategy sends all events for that customer to one partition, that partition can become overloaded.
For example:
P0 โ 100 million messages
P1 โ 1 million messages
P2 โ 1 million messages
P3 โ 1 million messages
P0 is now a hot partition.
This can create:
- Uneven workload.
- Consumer bottlenecks.
- Higher latency.
- Poor resource utilization.
Therefore, choosing a message key is a design decision.
Do not blindly choose a key simply because it provides ordering.
You need to consider both:
Ordering + Load distribution
13. How Does Kafka Decide Which Partition Receives a Message?
This is another very common Kafka scenario-based interview question.
The producer can influence partition selection.
If the producer explicitly specifies a partition, the record goes to that partition.
If no partition is explicitly specified but a key is provided, the partitioner uses the key to determine the partition, generally using a hash-based approach.
For example:
Key โ Hash โ Partition
Messages with the same key are therefore consistently directed to the same partition under the same partitioning conditions.
What happens if there is no key?
Kafka’s producer partitioner can distribute records across partitions. Modern Kafka uses a sticky partitioning approach by default, which keeps records on a partition long enough to build efficient batches before switching.
This is an important correction to a common interview misconception:
Do not simply say “Kafka always uses round robin when there is no key.”
For modern Kafka producer behavior, the default partitioner uses sticky partitioning when no key is supplied.
The exact behavior can also depend on the producer configuration and Kafka client version.
14. What Is Consumer Rebalancing?
Imagine a consumer group with:
- P0
- P1
- P2
And two consumers:
- C1
- C2
A possible assignment is:
C1 โ P0, P2
C2 โ P1
Now suppose you deploy another instance of the application.
A new consumer joins:
C3
Kafka needs to redistribute the partitions.
This process is called consumer group rebalancing.
The partitions are reassigned among the members of the group according to the group’s assignment protocol and strategy.
For example, the new assignment might become:
C1 โ P0
C2 โ P1
C3 โ P2
Rebalancing can happen when:
- A new consumer joins.
- A consumer leaves.
- A consumer crashes.
- A consumer stops sending heartbeats.
- Group membership changes.
Modern Kafka supports cooperative rebalancing strategies that can reduce unnecessary disruption compared with older eager approaches.
15. Does Consumer Rebalancing Stop All Processing?
The exact behavior depends on the rebalance protocol and assignment strategy.
With older eager rebalancing behavior, partitions could be revoked broadly and consumers might temporarily stop processing while a new assignment was established.
With cooperative incremental rebalancing, only partitions that need to move can be revoked, reducing disruption.
Therefore, an interview-friendly answer is:
Consumer rebalancing temporarily changes partition ownership, and the amount of processing disruption depends on the rebalance protocol and assignment strategy. Cooperative rebalancing is designed to reduce unnecessary disruption.
This is better than simply saying that every rebalance always stops every consumer.
16. What Happens When a Kafka Broker Fails?
Kafka is designed to continue operating even when individual brokers fail, provided the affected partitions have suitable replicas.
Suppose a partition has:
Leader โ Broker 1
Replica โ Broker 2
Replica โ Broker 3
Now Broker 1 fails.
Kafka can elect another eligible in-sync replica as the new leader.
For example:
Old Leader โ Broker 1
Broker 1 โ Failed
New Leader โ Broker 2
Producers and consumers refresh their metadata and can reconnect to the new leader.
There may be a short period of retrying or increased latency during the failover.
But Kafka can continue operating without a complete application outage if the replication setup is healthy.
17. What Is ISR in Kafka?
ISR means:
In-Sync Replicas
These are replicas that are considered sufficiently caught up with the partition leader according to Kafka’s replication rules.
Suppose:
Leader โ Broker 1
ISR โ Broker 1, Broker 2, Broker 3
If Broker 1 fails, Kafka can select an eligible in-sync replica as the new leader.
This is one reason replication is so important.
If you have only one copy of important data and that broker fails, there may be no replica available to take over.
18. What Happens If No In-Sync Replica Is Available?
This is a more advanced interview scenario.
If no eligible in-sync replica is available, Kafka may have to keep the partition unavailable rather than immediately electing an out-of-sync replica.
The unclean.leader.election.enable configuration controls whether an out-of-sync replica may become leader.
When unclean leader election is disabled, Kafka prioritizes data safety and can leave the partition unavailable until an appropriate replica becomes available.
When it is enabled, Kafka may restore availability by electing an out-of-sync replica, but this can result in loss of records that existed only on the old leader.
Therefore:
Clean election โ better data safety
Unclean election โ potentially better availability but possible data loss
This is a classic availability-versus-data-safety trade-off.
19. What Are Kafka Delivery Semantics?
Kafka discussions commonly include three delivery models:
At-most-once
A message is processed zero or one time.
There can be message loss, but duplicate processing is minimized.
At-least-once
A message is processed one or more times.
The advantage is that messages are less likely to be lost.
The disadvantage is that duplicates can happen.
This is a very common design in Kafka applications.
Exactly-once
The goal is to ensure that the processing result is committed exactly once within the supported transactional processing boundaries.
Kafka provides transactional and exactly-once processing capabilities, but exactly-once is not a magic guarantee for every external system.
For example, simply saying:
“Kafka is exactly once”
is not a good interview answer.
You need to explain the complete processing architecture.
20. Why Is Idempotency Important in Kafka?
Kafka consumers often need to be prepared for duplicate delivery.
Consider:
Kafka message
โ
Consumer
โ
Database update
โ
Consumer crashes
โ
Offset was not committed
โ
Message is delivered again
The database update may happen again.
If your operation is not idempotent, you could create duplicate records or perform the same business action twice.
For example:
Payment Event
Payment Event
If both events result in charging a customer, you could have a serious business problem.
A safer approach is to use a unique event ID or business identifier and make the database operation safe against repeated processing.
This is why idempotent Kafka consumers are such an important real-world design concept.
21. Kafka Scenario-Based Interview Questions: Quick Revision
Before your interview, remember these simple rules.
Offset
Kafka uses committed offsets to remember consumer progress.
Consumer crash
If processing happens but the offset is not committed, the message can be delivered again.
Commit before processing
A crash after the commit but before successful processing can cause the consumer group to skip that record.
Duplicate processing
A database update can happen again if the consumer crashes before committing the offset.
Idempotency
Make repeated processing safe.
More consumers than partitions
Some consumers remain idle.
More partitions than consumers
A consumer can handle multiple partitions.
Message ordering
Kafka guarantees ordering within a partition, not globally across a topic.
Message key
A key can keep related records on the same partition and therefore preserve their relative order.
Hot partition
A poorly distributed key can overload one partition.
Consumer rebalance
Partition ownership changes when group membership changes.
Broker failure
An eligible in-sync replica can become the new leader.
ISR
ISR means In-Sync Replicas.
Unclean leader election
It can improve availability but may cause data loss if an out-of-sync replica becomes leader.
Delivery semantics
Remember:
At-most-once โ possible loss
At-least-once โ possible duplicates
Exactly-once โ stronger processing guarantees within the appropriate transactional design
22. How to Answer Kafka Scenario-Based Interview Questions
When an interviewer gives you a Kafka scenario, do not immediately start talking about every Kafka feature you know.
Follow a simple process.
Step 1: Identify the topic structure
Ask yourself:
- How many partitions?
- How many replicas?
- How many consumers?
Step 2: Check the consumer group
Determine whether the consumers are in the same consumer group.
This matters because partition assignment works differently across different groups.
Step 3: Check the committed offset
Ask:
Was the offset committed before or after processing?
This often determines whether the message can be processed again.
Step 4: Check the partition
Remember that ordering is a partition-level concept.
Step 5: Check the failure
Was the problem:
- Consumer crash?
- Broker crash?
- Database failure?
- Network failure?
- Rebalance?
Step 6: Think about duplicates
If the consumer can process the same event again, ask:
Is the operation idempotent?
Step 7: Explain the solution
Finally, give the interviewer a practical solution.
For example:
“I would process the message successfully first, then commit the offset. Because duplicate delivery can still happen, I would make the database operation idempotent using a unique event ID or business key.”
This type of answer shows that you understand both Kafka theory and real-world application design.
Conclusion
Kafka interview preparation should not stop at learning definitions such as topic, partition, offset, producer, and consumer.
Modern interviews often focus on Kafka scenario-based interview questions because scenarios show whether a developer understands how Kafka behaves when something goes wrong.
The most important concepts to remember are simple:
Offsets tell Kafka where a consumer group has committed its progress.
Partitions provide parallelism.
A partition belongs to only one consumer within a consumer group at a time.
A consumer can handle multiple partitions.
Kafka ordering is guaranteed within a partition, not across the whole topic.
Message keys can keep related events together.
Poor key selection can create hot partitions.
Consumer crashes can cause messages to be processed again when offsets were not committed.
Committing before successful processing can cause messages to be skipped by the consumer group.
Idempotency helps protect your database and business logic from duplicate processing.
Consumer rebalancing changes partition ownership when group membership changes.
Replication and ISR help Kafka survive broker failures.
Unclean leader election can improve availability but may risk data loss.
If you understand these scenarios clearly, you will be in a much stronger position to answer both basic and advanced Kafka interview questions.
The best way to prepare is not to memorize every answer word by word. Instead, understand the flow:
Producer โ Topic โ Partition โ Consumer โ Processing โ Offset Commit
Then ask yourself what happens if something fails at every stage.
That mindset will help you solve many Kafka interview scenariosโeven when the interviewer changes the question or introduces a completely new situation.
Frequently Asked Questions About Kafka Interviews
What is the most important Kafka interview topic?
Partitions, offsets, consumer groups, message ordering, delivery semantics, replication, and rebalancing are some of the most important topics.
Can two consumers in the same group read the same partition?
Normally, no. Within a consumer group, a partition is assigned to one consumer at a time.
Can consumers from different groups read the same partition?
Yes. Different consumer groups maintain their own consumption positions and can independently consume the same topic.
Does Kafka guarantee ordering?
Kafka guarantees ordering within a partition. It does not provide global ordering across all partitions of a topic.
Why do Kafka consumers receive duplicate messages?
A common reason is that the message was processed but the consumer crashed before committing its offset.
How can duplicate processing be handled?
Use idempotent processing, unique event IDs, database constraints, upserts, deduplication records, and appropriate transactional patterns.
What happens when there are more consumers than partitions?
Some consumers remain idle because there are not enough partitions to assign to them.
What happens when a broker fails?
If an eligible in-sync replica exists, Kafka can elect it as the new leader and clients can refresh their metadata and continue processing.
What is the difference between at-least-once and at-most-once?
At-least-once prioritizes avoiding loss but can produce duplicates. At-most-once avoids repeated delivery in the processing flow but can lose messages if failure occurs at the wrong time.
What is the best way to prepare for Kafka scenario-based interview questions?
Do not memorize only definitions. Practice failure scenarios involving offsets, partitions, consumer groups, broker failures, rebalancing, duplicate processing, message ordering, and database transactions. The more scenarios you solve, the easier it becomes to answer unfamiliar Kafka questions.
ย
Table of Contents
Toggle









