Kafka — Technical Interview Flashcards
NOTE
Interview progression:
Fundamentals → Partitions & Ordering → Producers → Consumers → Storage & Reliability → Internals → Implementation → Architecture & Trade-offs → Production Troubleshooting → 15-Year Scenarios → War Stories
1. Fundamentals
Q: What problem does Kafka solve?
Kafka is a distributed event-streaming platform used to reliably publish, store, and consume large volumes of events asynchronously.
It decouples producers from consumers and allows multiple consumers to independently process the same event stream.
Q: Why would you use Kafka instead of a traditional message queue?
Kafka is optimized for high-throughput event streaming, durable ordered logs, replayability, and multiple independent consumers.
Traditional queues often focus more on task distribution where a message is consumed and removed.
Mnemonic
Kafka = Distributed durable log + replay + multiple consumers.
Q: Kafka vs synchronous REST communication?
REST creates synchronous request/response coupling. Kafka introduces asynchronous communication through durable events.
REST is appropriate when the caller needs an immediate response. Kafka is appropriate when work can happen asynchronously or multiple downstream systems need the event.
Q: What are the core components of Kafka?
The major components are:
-
Producer
-
Broker
-
Topic
-
Partition
-
Consumer
-
Consumer Group
-
Replicas
-
Controller
-
Offset
Q: What is a Kafka broker?
A broker is a Kafka server responsible for storing partitions and serving producer and consumer requests.
Q: Broker vs Cluster?
A broker is one Kafka server.
A cluster is a collection of brokers working together.
Q: What is a Kafka topic?
A topic is a logical stream/category of events.
A topic is physically divided into one or more partitions.
Q: Topic vs Partition?
A topic is the logical stream.
A partition is the physical ordered log within that topic.
Kafka distributes partitions across brokers for scalability.
Common Pitfall
A topic does not provide one global ordering guarantee. Ordering exists within an individual partition.
Q: Why does Kafka use partitions?
Partitions provide:
-
Parallelism
-
Horizontal scalability
-
Distribution across brokers
-
Per-partition ordering
Q: Is a Kafka partition a queue?
Conceptually it is closer to an append-only distributed log than a traditional queue.
Consumers track their position using offsets instead of removing messages from the partition.
Mnemonic
Queue → consume/remove conceptually.
Kafka → read from position.
Q: What is an offset?
An offset is the position of a record within a partition.
It identifies where a consumer is in the partition’s log.
Q: Is a Kafka offset globally unique?
No.
Offsets are unique only within a partition.
A record is effectively identified by:
topic + partition + offset
2. Partitions & Ordering
Q: Why is ordering guaranteed only within a partition?
Kafka appends records sequentially to each partition.
Multiple partitions can be processed independently, so Kafka cannot naturally establish a single ordering across them.
Q: How is a partition selected for a Kafka record?
Typically the producer determines the partition.
If a key is present, Kafka uses the partitioning strategy based on that key.
Without a key, records can be distributed across partitions.
Q: What is the role of a message key?
The key determines partition affinity.
Records with the same key can therefore be routed to the same partition, preserving ordering for that key.
Q: How would you preserve ordering for a specific customer?
Use customerId as the Kafka message key.
All events for that customer are routed to the same partition, giving ordered processing for that customer.
Mnemonic
Ordering requirement → identify the business entity → use it as the key.
Q: Can Kafka guarantee ordering across partitions?
No.
Ordering is guaranteed only within a partition.
Q: Can two consumers process different partitions in parallel?
Yes.
Each consumer can independently process partitions assigned to its consumer group.
Q: What happens if one partition receives significantly more traffic than others?
That partition becomes a hot partition.
Its consumer may experience lag even though other partitions have capacity.
Common Pitfall
Increasing the number of consumers will not solve a hot-partition problem if the traffic is concentrated on one key.
Q: What happens to ordering if you increase the number of partitions?
Existing records remain in their existing partitions, but future records may be mapped differently depending on the partitioning strategy.
Therefore partition-count changes require careful consideration when key-based ordering is important.
Q: Why can increasing partitions be dangerous for ordering?
A key’s partition assignment can potentially change when the partition count changes.
This can result in the same logical key being associated with different partitions over time.
Q: How do you choose a good Kafka message key?
Choose a key representing the entity for which ordering or locality matters.
Examples:
-
customerId -
orderId -
accountId -
deviceId
3. Producers
Q: What does a Kafka producer do?
A producer serializes records and sends them to Kafka brokers.
It determines the target topic and partition and can batch/compress records before transmission.
Q: What is producer batching?
The producer collects multiple records and sends them together.
Batching reduces network overhead and improves throughput.
Q: What is
linger.ms?
linger.ms controls how long the producer may wait for additional records before sending a batch.
Higher values can improve batching but add latency.
Q: What is
batch.size?
It controls the target size of a producer batch.
Larger batches can improve throughput but increase memory usage and potentially latency.
Q: What does producer compression do?
Compression reduces the amount of data transferred and stored.
Common algorithms include:
-
gzip
-
snappy
-
lz4
-
zstd
Q: What is
acks=0?
The producer does not wait for broker acknowledgement.
This gives lower latency but weaker durability guarantees.
Q: What is
acks=1?
The leader acknowledges the record after writing it locally.
A leader failure before replication can potentially result in data loss.
Q: What is
acks=all?
The leader waits for acknowledgement from the required in-sync replicas according to Kafka’s replication configuration.
This provides stronger durability.
Mnemonic
acks=0 → fastest / weakest
acks=1 → leader only
acks=all → strongest durability
Q: What is an idempotent producer?
An idempotent producer prevents duplicate records caused by producer retries from being written multiple times under supported producer semantics.
Q: Why are producer retries dangerous without idempotence?
A request may succeed at the broker while the acknowledgement is lost.
The producer retries, potentially creating a duplicate record.
Q: What is
enable.idempotence?
It enables producer-side mechanisms that allow Kafka to safely handle retries without creating duplicate records for the same producer session/partition sequence.
4. Consumers & Consumer Groups
Q: What is a Kafka consumer?
A consumer reads records from Kafka partitions and processes them.
It maintains its position using offsets.
Q: What is a consumer group?
A consumer group is a set of consumers cooperating to process a topic.
Within a group, a partition is assigned to only one consumer at a time.
Q: Why are consumer groups important?
They provide:
-
Parallel processing
-
Horizontal scaling
-
Fault recovery
-
Independent consumption of the same topic
Q: What happens when consumers > partitions?
Some consumers remain idle because each partition can have only one active consumer within a consumer group.
Mnemonic
Maximum useful consumers in one group ≈ number of partitions.
Q: What happens when a consumer crashes?
Kafka detects the failure and triggers a rebalance.
The affected partitions are reassigned to available consumers.
Q: What is a consumer rebalance?
A rebalance redistributes partitions among consumers in a consumer group.
It can occur when consumers join, leave, fail, or group membership changes.
Q: Why can frequent rebalances be problematic?
They temporarily interrupt processing and can cause throughput degradation, increased latency, and consumer lag.
Q: What is consumer lag?
Consumer lag represents how far a consumer is behind the latest available records in a partition.
Q: Where are consumer offsets stored?
Kafka stores committed consumer offsets in the internal __consumer_offsets topic.
Q: What is the difference between current position and committed offset?
The current position is where the consumer is currently reading.
The committed offset is the durable checkpoint Kafka knows about.
Q: What happens if a consumer crashes before committing its offset?
After reassignment, the new consumer can restart from the last committed offset.
This may cause the record to be processed again.
Common Pitfall
Kafka’s offset commit does not automatically mean your database transaction has committed.
Q: What delivery semantics can Kafka consumers achieve?
Common semantics are:
-
At-most-once
-
At-least-once
-
Exactly-once under specific Kafka-supported transactional designs
Q: What is at-least-once processing?
A record can be processed one or more times, but the system attempts not to lose it.
Duplicates are possible.
Q: Why is at-least-once commonly used in production?
It is relatively simple and reliable.
Applications typically achieve business-level idempotency to handle duplicates.
Q: How would you make a Kafka consumer idempotent?
Use a business identifier such as eventId or orderId and ensure processing of the same event cannot apply its business effect twice.
5. Reliability, Replication & ISR
Q: What is replication factor?
Replication factor is the number of copies of each partition maintained across brokers.
Q: Why should replicas be distributed across brokers?
To prevent one broker failure from making all copies unavailable.
Q: What is a partition leader?
The leader is the replica responsible for serving reads and writes for a partition.
Q: What is a follower replica?
A follower replica replicates data from the partition leader.
Q: What is ISR?
ISR means In-Sync Replicas.
It is the set of replicas considered sufficiently caught up with the leader according to Kafka’s replication rules.
Q: What happens when a broker goes down?
Partitions led by that broker may have their leadership transferred to another eligible replica.
Consumers and producers reconnect to the new leader.
Q: What happens when a partition leader fails?
Kafka elects an eligible replica as the new leader.
Clients refresh metadata and begin communicating with the new leader.
Q: What happens if all replicas of a partition are unavailable?
The partition becomes unavailable until an eligible replica can become leader, depending on the cluster’s configuration and failure state.
Q: How does Kafka provide fault tolerance?
Primarily through:
-
Partition replication
-
Leader/follower architecture
-
ISR
-
Leader election
-
Distributed brokers
Q: What is
min.insync.replicas?
It defines the minimum number of in-sync replicas required for certain writes to succeed when using acks=all.
Common Pitfall
replication.factor=3alone does not guarantee three healthy copies are available for every acknowledged write.acksandmin.insync.replicasmatter.
Q: Why is
replication.factor=3,acks=all, andmin.insync.replicas=2a common production pattern?
It allows one replica to fail while still requiring at least two in-sync replicas for successful acknowledged writes.
6. Storage & Kafka Internals
Q: How does Kafka store messages?
Kafka stores records in append-only log files on disk.
Partitions are divided into segments.
Q: What are Kafka log segments?
A partition is split into multiple segment files.
New records are appended to the active segment while older segments can be deleted or compacted according to retention policy.
Q: Why doesn't Kafka immediately delete consumed messages?
Kafka separates consumption from storage.
Messages remain available according to the topic’s retention policy regardless of whether consumers have processed them.
Q: How does Kafka retention work?
Retention can be based primarily on:
-
Time
-
Size
Older segments are removed when retention policies require it.
Q: What is log compaction?
Log compaction retains the latest value for each key rather than retaining every historical record indefinitely.
Q: When would you use log compaction?
Examples:
-
Customer latest state
-
Product configuration
-
Account state
-
Service configuration
Q: Delete retention vs compaction?
Delete retention removes old records based on retention policies.
Compaction preserves the latest record for each key while removing superseded records.
Q: What is the difference between event history and current state?
Event history records what happened.
Current state represents the latest known value.
Kafka can support both through normal retention and log compaction respectively.
Q: Why is sequential disk I/O important to Kafka performance?
Kafka’s append-only log allows efficient sequential writes and reads, making disk throughput an important part of Kafka’s performance model.
Q: What is zero-copy in Kafka?
Kafka can efficiently transfer data from disk to network using mechanisms that reduce unnecessary copying between kernel and application memory.
Mnemonic
Kafka performance is not simply “RAM = fast”. Sequential disk + page cache + network efficiency matter heavily.
7. Consumer Lag & Troubleshooting
Q: What are common causes of increasing consumer lag?
Possible causes include:
-
Slow downstream dependency
-
Insufficient consumer instances
-
Hot partition
-
CPU exhaustion
-
GC pauses
-
Network problems
-
Database bottlenecks
-
Frequent rebalances
-
Poor consumer configuration
Q: How would you troubleshoot increasing consumer lag?
Start by determining:
-
Which topic?
-
Which partition?
-
Which consumer group?
-
Is lag uniform or concentrated?
-
Consumer CPU/memory?
-
Processing latency?
-
Downstream DB/API latency?
-
Rebalances?
-
Broker health?
-
Partition traffic distribution?
Production mnemonic
Lag → Partition → Consumer → Processing → Dependency → Broker
Q: What does it mean if only one partition has very high lag?
Suspect a hot partition, skewed key distribution, or a slow consumer assigned to that partition.
Q: What if all partitions have increasing lag?
Look for a systemic bottleneck:
-
Insufficient consumer capacity
-
Slow downstream service
-
Database saturation
-
Broker/network degradation
-
Consumer application regression
Q: Why doesn't simply adding consumers always solve lag?
Consumers cannot exceed useful partition parallelism, and a hot partition cannot be split across multiple consumers within the same consumer group.
Q: How would you troubleshoot a slow consumer?
Measure:
-
Poll latency
-
Processing latency
-
DB/API latency
-
CPU
-
Memory
-
GC
-
Thread pool saturation
-
Network
-
Rebalance frequency
Then identify whether the bottleneck is Kafka or downstream processing.
Common Pitfall
Don’t immediately increase consumer count. First determine whether the bottleneck is Kafka consumption, application processing, or a downstream dependency.
8. Kafka Configuration & Implementation
Q: What are the important producer configurations you would review?
Typical production settings include:
-
acks -
enable.idempotence -
retries -
compression.type -
batch.size -
linger.ms -
delivery.timeout.ms
Q: What are important consumer configurations?
Common ones include:
-
group.id -
enable.auto.commit -
auto.offset.reset -
max.poll.records -
max.poll.interval.ms -
session.timeout.ms -
heartbeat.interval.ms
Q: What does
auto.offset.resetcontrol?
It determines where a consumer starts when no valid committed offset exists.
Typical values include:
-
earliest -
latest -
none
Common Pitfall
auto.offset.reset=earliestdoes not mean “always read from the beginning.” It applies when there is no valid committed offset.
Q: What is
max.poll.interval.ms?
It defines the maximum allowed interval between successful consumer poll calls before Kafka considers the consumer unable to keep up.
Q: How can slow processing cause consumer instability?
If processing takes too long between polls, Kafka can consider the consumer unhealthy, causing partition reassignment and potentially repeated rebalances.
Q: What is the danger of increasing
max.poll.interval.msblindly?
It can hide slow processing and delay detection of unhealthy consumers.
The real processing bottleneck should still be investigated.
Q: How would you structure Kafka configuration in a Spring Boot application?
Typically separate:
-
Producer configuration
-
Consumer configuration
-
Topic configuration
-
Serialization/deserialization
-
Error handling
-
Retry/DLT configuration
Keep environment-specific values externalized.
Q: What is a dead-letter topic?
A dead-letter topic stores records that cannot be successfully processed after configured retry/error-handling policies.
Q: Retry vs Dead-Letter Topic?
Retry is appropriate for potentially transient failures.
DLT is appropriate when the record cannot be successfully processed after retries or requires manual investigation.
Mnemonic
Transient → Retry. Permanent/poison → DLT.
9. Kafka Error Handling & Reliability Patterns
Q: What is a poison-pill message?
A poison-pill message repeatedly fails processing and prevents normal progress if not handled correctly.
Examples include malformed payloads or unexpected schema changes.
Q: How should a consumer handle transient failures?
Use controlled retries with appropriate backoff.
Avoid immediately retrying thousands of times in a tight loop.
Q: Why can aggressive retries make an outage worse?
Retries generate additional load against an already failing dependency.
This can create a retry storm.
Common Pitfall
Retrying is not free capacity. During dependency failure, uncontrolled retries can amplify the incident.
Q: What is exponential backoff?
The retry delay increases after successive failures.
It reduces pressure on a recovering dependency.
Q: What is a retry topic?
A retry topic is used to delay failed records before attempting processing again.
It can separate retry timing from the main consumer flow.
Q: How would you prevent one bad message from blocking a partition?
Use appropriate error handling such as:
-
Retry policy
-
Retry topics
-
DLT
-
Controlled offset handling
The exact approach depends on whether ordering must be preserved.
Common Pitfall
Sending a failed record to a DLT can preserve throughput but may violate a business requirement if later events depend on the failed event.
10. Kafka Connect vs Kafka Streams
Q: What is Kafka Connect?
Kafka Connect is a framework for moving data between Kafka and external systems.
Examples:
-
Database → Kafka
-
Kafka → Elasticsearch
-
Kafka → S3
Q: What is Kafka Streams?
Kafka Streams is a Java library for processing Kafka streams.
It supports operations such as:
-
Filtering
-
Mapping
-
Aggregation
-
Joins
-
Windowing
Q: Kafka Connect vs Kafka Streams?
Kafka Connect → move data.
Kafka Streams → process data.
Mnemonic
Connect = transport. Streams = computation.
Q: When would you use Kafka Streams instead of a normal consumer?
Use Kafka Streams when the application performs stream-processing operations such as joins, aggregations, windowing, or stateful processing.
11. Kafka Architecture & Trade-offs
Q: What are Kafka's major advantages?
-
High throughput
-
Horizontal scalability
-
Durable storage
-
Replayability
-
Multiple independent consumers
-
Partition-level ordering
-
Fault tolerance
-
Event-driven architecture
Q: What are Kafka's major disadvantages?
-
Operational complexity
-
Partition management
-
Consumer lag management
-
Ordering limitations
-
Duplicate processing
-
Schema evolution complexity
-
Monitoring requirements
-
Overkill for simple request/response workloads
Q: When should you NOT use Kafka?
Avoid Kafka when you simply need:
-
Simple synchronous request/response
-
A tiny background job queue
-
Low operational complexity
-
Very small workloads where Kafka provides no meaningful benefit
Q: Kafka vs RabbitMQ?
Kafka is particularly strong for durable event streams, replayability, high throughput, and multiple independent consumers.
RabbitMQ is often attractive for traditional task/message routing and flexible messaging patterns.
Q: Kafka vs database polling?
Kafka provides push-oriented event distribution and durable streaming.
Database polling repeatedly queries the database and can create unnecessary load and latency.
Q: Kafka vs REST?
REST is request/response communication.
Kafka is asynchronous event streaming.
They often coexist rather than replace one another.
Q: Should every microservice communicate through Kafka?
No.
Use Kafka where asynchronous event-driven communication provides architectural value.
Using Kafka for every interaction can unnecessarily increase complexity and latency.
12. Schema & Data Contracts
Q: Why is schema evolution important in Kafka?
Kafka messages can remain in the system for a long time and may be consumed by multiple independently deployed applications.
Therefore producers and consumers must remain compatible across versions.
Q: What is schema compatibility?
It defines whether different versions of an event schema can safely interact.
Q: What is a schema registry?
A schema registry centrally manages event schemas and their compatibility rules.
Q: Why is JSON not automatically enough for enterprise Kafka?
JSON provides flexibility but does not inherently enforce a formal contract.
Schema-based formats such as Avro or Protobuf can provide stronger compatibility and governance.
Q: What happens if a producer removes a field that an old consumer requires?
The old consumer may fail or behave incorrectly.
Schema evolution must therefore consider backward/forward compatibility.
13. ZooKeeper vs KRaft
Q: What was ZooKeeper's role in Kafka?
Historically, ZooKeeper was used for Kafka cluster metadata and controller coordination.
Q: What is KRaft?
KRaft is Kafka’s built-in consensus architecture based on the Raft protocol, removing Kafka’s dependency on ZooKeeper.
Q: Why did Kafka move toward KRaft?
KRaft simplifies Kafka architecture by consolidating cluster metadata management within Kafka itself.
Q: Is ZooKeeper required for modern Kafka?
Modern Kafka deployments use KRaft rather than requiring ZooKeeper.
Interview Tip
Don’t answer simply “ZooKeeper manages Kafka.” Explain that it historically provided metadata/controller coordination and that modern Kafka uses KRaft.
14. High-Throughput Architecture
Q: How would you design Kafka for high throughput?
Consider:
-
Appropriate partition count
-
Producer batching
-
Compression
-
Efficient serialization
-
Adequate broker capacity
-
Consumer parallelism
-
Fast disks/network
-
Avoiding hot partitions
-
Monitoring lag
Q: How would you decide the number of partitions?
Consider:
-
Required producer throughput
-
Required consumer throughput
-
Number of consumers
-
Ordering requirements
-
Broker capacity
-
Future scaling requirements
Common Pitfall
Don’t choose partitions solely based on today’s traffic. Partition count is difficult to reduce later and affects scalability and ordering.
Q: What is a hot partition?
A partition receiving disproportionately high traffic compared with other partitions.
Q: How would you fix a hot partition?
First determine why keys are skewed.
Possible solutions:
-
Improve key distribution
-
Change partitioning strategy
-
Increase partition count where appropriate
-
Use a more evenly distributed key
But changing the key can affect ordering semantics.
Q: How would you optimize Kafka producer throughput?
Consider:
-
Batching
-
Compression
-
Appropriate
linger.ms -
Appropriate
batch.size -
Async sends
-
Idempotence
-
Efficient serialization
Q: How would you optimize consumer throughput?
Consider:
-
More partitions
-
More consumers
-
Batch processing
-
Efficient downstream operations
-
Appropriate
max.poll.records -
Parallel processing where ordering permits
15. Security
Q: How would you secure Kafka in production?
Typical controls include:
-
TLS encryption
-
SASL authentication
-
ACL authorization
-
Network isolation
-
Secret management
-
Encryption at rest where required
-
Audit/monitoring
Q: Authentication vs authorization in Kafka?
Authentication answers:
Who are you?
Authorization answers:
What are you allowed to do?
Q: What is a Kafka ACL?
An Access Control List defines permissions for Kafka resources such as topics and consumer groups.
Q: What security mistake do you commonly see in Kafka deployments?
Giving applications broader topic permissions than necessary.
Security principle
Least privilege: a service should access only the topics and consumer groups it actually needs.
16. Production Troubleshooting
Q: Kafka throughput suddenly dropped. How would you investigate?
Check:
-
Producer throughput
-
Broker CPU
-
Disk I/O
-
Network
-
Request latency
-
Under-replicated partitions
-
ISR changes
-
Consumer throughput
-
Controller events
-
Recent deployments/configuration changes
Q: What does an under-replicated partition indicate?
One or more replicas are not sufficiently caught up with the leader.
It can indicate broker, disk, network, or load problems.
Q: What would you check if ISR keeps shrinking?
Investigate:
-
Broker CPU
-
Disk latency
-
Network latency
-
GC pauses
-
Broker overload
-
Replica fetch performance
Q: Kafka disk usage is growing rapidly. What would you investigate?
Check:
-
Topic retention
-
Retention size
-
Retention time
-
Log compaction
-
Segment behavior
-
Unexpected producer traffic
-
Replication/storage configuration
Q: Consumer lag suddenly increases after a deployment. What do you investigate first?
Compare the new version’s:
-
Processing latency
-
Error rate
-
DB/API calls
-
CPU/memory
-
GC
-
Poll behavior
-
Rebalance frequency
against the previous version.
Q: Consumers are constantly rebalancing. What could cause it?
Possible causes:
-
Consumer crashes
-
Long processing time
-
max.poll.interval.mstoo low -
Network instability
-
Deployment churn
-
Group membership instability
Q: Kafka brokers are healthy but consumer lag keeps increasing. What is your first suspicion?
The consumer application or its downstream dependencies may be the bottleneck.
Production heuristic
Healthy brokers + growing lag = investigate consumers and dependencies before blaming Kafka.
17. 15-Year Experience — Architecture Scenarios
Scenario 1 — Order Processing
Q: You are designing an order platform processing 50,000 orders/sec. How would you design the Kafka architecture?
I would start with:
-
Business event model
-
Partitioning strategy
-
Ordering requirements
-
Expected throughput
-
Consumer parallelism
-
Replication factor
-
Failure model
-
Retry/DLT strategy
-
Schema evolution
-
Observability
-
Capacity planning
For example, orderId could be the key if all events for an order must remain ordered.
Q: The business says "all events must be globally ordered." What would you challenge?
I would challenge whether global ordering is actually required.
Global ordering severely limits parallelism.
Usually the requirement is really:
“Events for the same business entity must be ordered.”
Architect Tip
Convert vague requirements like “ordered” into “ordered by what business key?”
Scenario 2 — Payment Events
Q: A payment service publishes
PaymentCreated,PaymentAuthorized, andPaymentCompleted. How would you preserve their order?
Use the same payment/order business key for all related events so they are routed to the same partition.
Q: What if payment events are processed by multiple services?
Use separate consumer groups.
Each service independently consumes the same Kafka topic.
Q: What if the payment service processes an event twice?
Design the consumer to be idempotent using a unique event/business identifier.
Scenario 3 — Database Failure
Q: Your Kafka consumer updates PostgreSQL. PostgreSQL goes down. What happens?
Kafka can continue retaining the records while the consumer fails or pauses processing.
The consumer can retry later without requiring Kafka to resend the event from the producer.
Q: Would you commit the Kafka offset before or after updating PostgreSQL?
Usually after successful business processing.
Otherwise a crash could result in the message being marked consumed even though the database update failed.
Common Pitfall
Kafka offset commit + database commit are separate operations. This creates a distributed consistency problem.
Q: How would you solve the Kafka + database dual-write problem?
Options include:
-
Transactional outbox
-
Idempotent consumers
-
Kafka transactions where applicable
-
CDC-based approaches
The correct choice depends on the consistency requirement.
Scenario 4 — Consumer Scaling
Q: You have 100 Kafka consumers but only 20 partitions. What happens?
Only 20 consumers can actively own partitions in that consumer group.
The remaining consumers are idle.
Q: Management asks you to add another 100 consumers to fix lag. What do you say?
First determine whether partition parallelism is the bottleneck.
If there are only 20 partitions, simply adding consumers will not provide 200-way parallelism.
Scenario 5 — Hot Key
Q: One customer generates 30% of all traffic. How would you handle it?
First determine whether strict ordering for that customer is required.
If yes, distributing that customer’s events across multiple partitions would break straightforward partition ordering.
If ordering is not required, the keying strategy can potentially be changed.
Q: What trade-off exists between ordering and scalability?
Strong ordering requires related events to share a partition.
That concentrates processing and limits parallelism for that key.
18. 15-Year Experience — Production Scenarios
Q: At 2 AM, consumer lag jumps from 10 seconds to 30 minutes. Walk me through your response.
I would:
-
Confirm scope.
-
Identify affected consumer groups.
-
Identify affected partitions.
-
Determine whether lag is uniform or skewed.
-
Check consumer health.
-
Check downstream dependencies.
-
Check broker health.
-
Check recent deployments/configuration changes.
-
Mitigate the bottleneck.
-
Monitor recovery rate.
Incident mnemonic
Scope → Partition → Consumer → Dependency → Broker → Recent Change → Mitigate
Q: Your Kafka cluster is healthy but the application is processing only 10% of its normal throughput. What do you investigate?
Focus on the application:
-
CPU
-
GC
-
Thread pools
-
DB latency
-
External APIs
-
Connection pools
-
Lock contention
-
Serialization/deserialization
-
Batch size
-
Consumer configuration
Q: Consumer lag is high only for one partition. What does that tell you?
It strongly suggests partition-level skew.
Investigate:
-
Hot key
-
Slow processing for records in that partition
-
Uneven traffic
-
Consumer assigned to that partition
Q: Kafka producers are timing out but brokers show low CPU. What would you investigate?
Look beyond CPU:
-
Network latency
-
Disk latency
-
Request queueing
-
ISR health
-
Broker request latency
-
Metadata issues
-
Authentication/TLS
-
Client configuration
-
Network saturation
Q: A broker has high disk utilization but low CPU. Is Kafka CPU-bound?
Not necessarily.
Kafka performance can be constrained by disk throughput/latency or network even when CPU is relatively idle.
Q: After increasing partitions, your consumer throughput improved but ordering-related bugs appeared. Why?
The partitioning topology may have changed the ordering relationship for keys/events.
Increasing partitions should therefore be treated as an architectural change when key-based ordering matters.
19. War Stories — Senior/Architect-Level Questions
Q: Tell me about a Kafka incident where increasing consumers did not solve the problem.
A strong answer should explain:
-
Initial symptom
-
Metrics observed
-
Why consumer scaling appeared reasonable
-
What the actual bottleneck was
-
Evidence that proved the root cause
-
Mitigation
-
Long-term fix
-
What monitoring was added afterward
Interview Tip
Don’t tell a generic Kafka story. Tell the interviewer how you reasoned from symptoms to root cause.
Q: Tell me about a time when Kafka caused unexpected duplicate processing.
Discuss:
-
Producer retries or consumer replay
-
Offset behavior
-
Failure window
-
Business impact
-
Idempotency strategy
-
Remediation
Q: Tell me about a production Kafka outage you handled.
Structure your answer:
Situation → Impact → Diagnosis → Mitigation → Root Cause → Permanent Fix → Prevention
Q: Tell me about a time you deliberately chose NOT to use Kafka.
A strong architect answer should demonstrate that Kafka is not automatically the answer.
Explain:
-
Requirements
-
Alternatives considered
-
Why Kafka added unnecessary complexity
-
Why the selected solution was simpler
Q: Tell me about a Kafka scaling decision you got wrong.
Explain:
-
Original assumption
-
What actually happened
-
Metric that exposed the problem
-
Architectural correction
-
Lesson learned
Senior Interview Tip
A good failure story demonstrates engineering judgment, not incompetence.
Q: Tell me about a time when ordering requirements conflicted with scalability.
Explain the business requirement, the ordering key, partitioning decision, scalability limitation, and the compromise you made.
Q: Tell me about a time when a downstream database caused Kafka lag.
A strong answer should explain how you distinguished:
Kafka problem → consumer problem → database problem
and how you prevented the database failure from becoming a cascading outage.
20. Deep Architecture Questions
Q: How would you design Kafka for multi-region disaster recovery?
Discuss:
-
Active/active vs active/passive
-
Replication between regions
-
RPO/RTO
-
Data sovereignty
-
Ordering
-
Duplicate events
-
Failover
-
DNS/routing
-
Consumer recovery
-
Operational complexity
Q: What does exactly-once mean in Kafka?
Exactly-once semantics aim to ensure that Kafka’s transactional processing can avoid duplicate effects within supported Kafka transactional boundaries.
It does not automatically make arbitrary external side effects exactly once.
Common Pitfall
“Kafka exactly-once means my database/API call happens exactly once.”
That is not automatically true.
Q: How would you design Kafka so one slow consumer does not affect other consumers?
Use separate consumer groups.
Consumer groups consume independently and therefore one group’s processing speed does not directly determine another group’s progress.
Q: How would you design event replay for a failed downstream service?
Kafka’s retention allows consumers to restart from an earlier offset or replay retained events.
The consumer must be designed so replaying events does not corrupt business state.
Q: How would you prevent replay from causing duplicate business operations?
Use idempotency keys, deduplication, transactional processing, or state checks appropriate to the business operation.
Q: What happens if a consumer processes an event successfully but crashes before committing its offset?
The event may be processed again after restart/rebalance.
Therefore business processing should generally tolerate duplicate delivery.
21. Final Architect-Level Rapid Fire
Q: Kafka's biggest strength?
High-throughput, durable, replayable distributed event streaming.
Q: Kafka's biggest architectural limitation?
Ordering is fundamentally partition-scoped, not globally scalable.
Q: What determines consumer parallelism?
Primarily the number of partitions.
Q: What determines ordering?
Partition assignment.
Q: What determines durability?
Replication and acknowledgement configuration.
Q: What determines consumer progress?
Offsets.
Q: What indicates a consumer is falling behind?
Consumer lag.
Q: What handles failed replicas?
Replication, ISR, and leader election.
Q: What handles poison messages?
Retry/error handling and potentially DLT.
Q: What handles duplicate processing?
Idempotency.
Q: What handles event contract evolution?
Schema governance and compatibility rules.
Q: What handles external-system integration?
Kafka Connect.
Q: What handles stream processing?
Kafka Streams.
Q: What replaced ZooKeeper in modern Kafka architecture?
KRaft.
Q: What is the first question you should ask when someone says "we need ordering"?
“What exactly needs to be ordered, and by which business key?”
Architect Mnemonic
Kafka design = Partition + Key + Ordering + Replication + Consumer Group + Failure Handling
22. Interviewer’s Hidden Follow-ups
These are the questions I would expect an interviewer to ask after your first answer.
Q: You said "Kafka guarantees ordering." What exactly do you mean?
Kafka guarantees ordering within a partition, not across the entire topic.
Q: You said "Kafka is exactly once." Is that really true?
Only within specific Kafka transactional semantics. External side effects such as arbitrary database/API calls require additional design.
Q: You said "just add consumers." What if there are fewer partitions?
Consumer count cannot create more partition-level parallelism.
Q: You said "replication factor 3 means no data loss." Is that sufficient?
No. Durability also depends on producer acknowledgements, ISR state, min.insync.replicas, and failure scenarios.
Q: You said "consumer committed the message." What did it actually commit?
It committed its Kafka offset. That does not necessarily mean the associated business transaction committed.
Q: You said "Kafka is fast." What makes it fast?
Append-oriented storage, sequential I/O patterns, batching, partition parallelism, efficient networking, compression, and page-cache utilization all contribute.
Q: You said "increase partitions." What could go wrong?
Ordering/key distribution implications, operational overhead, resource usage, and potentially changed partition assignment behavior.
Q: You said "retry the message." What happens if the downstream service is completely down?
Uncontrolled retries can amplify the outage. Use backoff, bounded retries, retry topics, circuit-breaking, or DLT depending on the requirement.
23. The Kafka Mental Model
┌───────────────┐
│ Producer │
└───────┬───────┘
│
▼
┌───────────────┐
│ Topic │
└───────┬───────┘
│
┌─────────────┼─────────────┐
▼ ▼ ▼
Partition 0 Partition 1 Partition 2
│ │ │
▼ ▼ ▼
Consumer A Consumer B Consumer C
│ │ │
└─────────────┼─────────────┘
▼
Business Logic
│
▼
DB / API / Event
Key concepts:
Partition → parallelism + ordering boundary
Key → determines logical partition affinity
Offset → consumer position
Group → consumer scaling/isolation
Replica → fault tolerance
ISR → healthy/caught-up replicas
Retention → how long events remain available
Lag → consumer falling behind
Idempotency → protection against duplicate processing
Final Interview Mental Model
When faced with almost any Kafka design question, reason in this order:
1. What is the event?
2. Who produces it?
3. Who consumes it?
4. What must be ordered?
5. What should the key be?
6. How many partitions?
7. What happens when something fails?
8. Can processing be repeated safely?
9. How do we observe lag/errors?
10. What are the operational trade-offs?