Section 15 Β· 30 questions

Kafka

30 interview questions and answers in the Kafka section.

English Kafka Source Markdown
Language versions: English Russian Ukrainian

Questions in this section

  1. What is topic in Kafka
  2. What is partition and why is it needed
  3. How is data distributed across partitions
  4. What is message key and how does it affect partitioning
  5. What is Consumer Group
  6. How does consumer balancing work in a group
  7. Can you have more consumers than partitions
  8. What happens when you add a new consumer to the group
  9. What message delivery guarantees does Kafka provide
  10. What is the difference between at-most-once, at-least-once and exactly-once
  11. How to configure exactly-once semantics
  12. What is offset in Kafka
  13. How does offset commit work
  14. What is the difference between auto commit and manual commit
  15. What is rebalancing and when does it happen
  16. What is replication in Kafka
  17. What are leader and follower replicas
  18. What is ISR (In-Sync Replicas)
  19. How does Kafka ensure fault tolerance
  20. What is producer acknowledgment and what modes exist (acks=0,1,all)?
  21. What is batch in Kafka producer
  22. How does message compression work
  23. What is idempotent producer
  24. How to handle errors when reading messages in Kafka
  25. What is DLQ (Dead Letter Queue) in Kafka
  26. How to monitor consumer lag in Kafka
  27. What is retention policy in Kafka
  28. How are old messages deleted from a Kafka topic
  29. Can you read messages from a specific partition in Kafka
  30. How to implement message filtering on consumer side in Kafka

Study navigator

30 interview preparation questions for Middle/Senior Java Developer.


πŸ“‹ All Questions

# Question Difficulty
1 What is topic in Kafka ⭐
2 What is partition and why is it needed ⭐⭐
3 How is data distributed across partitions ⭐⭐
4 What is message key and how does it affect partitioning ⭐⭐
5 What is Consumer Group ⭐⭐
6 How does consumer balancing work in a group ⭐⭐
7 Can you have more consumers than partitions ⭐⭐
8 What happens when you add a new consumer to the group ⭐⭐
9 What message delivery guarantees does Kafka provide ⭐⭐
10 What is the difference between at-most-once, at-least-once and exactly-once ⭐⭐⭐
11 How to configure exactly-once semantics ⭐⭐⭐
12 What is offset in Kafka ⭐⭐
13 How does offset commit work ⭐⭐
14 What is the difference between auto commit and manual commit ⭐⭐
15 What is rebalancing and when does it happen ⭐⭐⭐
16 What is replication in Kafka ⭐⭐
17 What are leader and follower replicas ⭐⭐
18 What is ISR (In-Sync Replicas) ⭐⭐⭐
19 How Kafka provides fault tolerance ⭐⭐⭐
20 What is producer acknowledgment and what modes exist ⭐⭐
21 What is batch in Kafka producer ⭐⭐
22 How does message compression work ⭐⭐
23 What is idempotent producer ⭐⭐⭐
24 How to handle errors when reading messages ⭐⭐
25 What is DLQ (Dead Letter Queue) ⭐⭐
26 How to monitor consumer lag ⭐⭐
27 What is retention policy ⭐⭐
28 How are old messages deleted from a topic ⭐⭐
29 Can you read messages from a specific partition ⭐⭐
30 How to implement message filtering on the consumer side ⭐⭐

πŸ—ΊοΈ Topic Dependency Map

                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   KAFKA BASICS (1-4)                     β”‚
                    β”‚   1. Topic                               β”‚
                    β”‚   2. Partition                           β”‚
                    β”‚   3. Data Distribution                   β”‚
                    β”‚   4. Message Key                         β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                       β”‚
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β–Ό                          β–Ό                          β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ CONSUMER       β”‚        β”‚ DELIVERY       β”‚        β”‚ PRODUCER           β”‚
    β”‚ GROUPS (5-8)   β”‚        β”‚ GUARANTEES     β”‚        β”‚ (20-23)            β”‚
    β”‚ 5. Consumer    β”‚        β”‚ (9-11)         β”‚        β”‚ 20. acks=0,1,all   β”‚
    β”‚    Group       β”‚        β”‚ 9. Guarantees  β”‚        β”‚ 21. Batch          β”‚
    β”‚ 6. Balancing   β”‚        β”‚ 10. At-most/   β”‚        β”‚ 22. Compression    β”‚
    β”‚ 7. More cons.  β”‚        β”‚     least/     β”‚        β”‚ 23. Idempotent     β”‚
    β”‚ 8. Adding new  β”‚        β”‚     exactly    β”‚        β”‚    producer        β”‚
    β”‚    consumer    β”‚        β”‚ 11. Configure  β”‚        β”‚                    β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚                        β”‚                        β”‚
            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β–Ό
                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                    β”‚   OFFSET AND REBALANCING (12-15)         β”‚
                    β”‚   12. Offset                             β”‚
                    β”‚   13. Commit offset                      β”‚
                    β”‚   14. Auto vs Manual commit              β”‚
                    β”‚   15. Rebalancing                        β”‚
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                     β”‚
            β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
            β–Ό                        β–Ό                        β–Ό
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ REPLICATION    β”‚        β”‚ ERRORS AND     β”‚        β”‚ RETENTION AND      β”‚
    β”‚ AND FA (16-19) β”‚        β”‚ DLQ (24-26)    β”‚        β”‚ FILTERING          β”‚
    β”‚ 16. Replica.   β”‚        β”‚ 24. Error      β”‚        β”‚ (27-30)            β”‚
    β”‚ 17. Leader/    β”‚        β”‚     handling   β”‚        β”‚ 27. Retention      β”‚
    β”‚    Follower    β”‚        β”‚ 25. DLQ        β”‚        β”‚ 28. Deletion       β”‚
    β”‚ 18. ISR        β”‚        β”‚ 26. Lag monit. β”‚        β”‚ 29. Partition read β”‚
    β”‚ 19. Fault      β”‚        β”‚                β”‚        β”‚ 30. Filtering      β”‚
    β”‚    tolerance   β”‚        β”‚                β”‚        β”‚                    β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🟒 Junior Level (weeks 1-2)

Step Topic Files Goal
1 Basics Q1, Q2, Q3, Q4 Topic, partition, key, distribution
2 Consumer Group Q5, Q6 Groups, balancing
3 Offset and commit Q12, Q13, Q14 Offset, commit types
4 Delivery guarantees Q9, Q10 At-most, at-least, exactly-once
5 Producer acks Q20 acks=0,1,all

🟑 Middle Level (weeks 3-4)

Step Topic Files Goal
1 Rebalancing Q7, Q8, Q15 When it happens, eager vs cooperative
2 Replication Q16, Q17, Q18 ISR, leader/follower, fault tolerance
3 Batch & compression Q21, Q22 batch.size, linger.ms, lz4/gzip/snappy
4 Error handling Q24, Q25 Retry, DLQ, poison pill
5 Retention Q27, Q28 retention.ms, retention.bytes, cleanup.policy
6 Monitoring Q26 Consumer lag, tools

πŸ”΄ Senior Level (weeks 5-6)

Step Topic Files Goal
1 Exactly-once Q11 EOS v1 vs v2, Producer ID/Epoch, Outbox
2 Idempotent producer Q23 PID, Epoch, max.in.flight, deduplication
3 Fault tolerance deep Q19 RF, min.insync.replicas, unclean election
4 Advanced consumer Q29, Q30 assign() vs subscribe(), filtering patterns
5 ISR deep dive Q18 ISR shrink/expand, LEO, HW, leader epoch
6 Chaos engineering Q15 (Senior) Cascading rebalancing, GC pauses, tuning

πŸ”— Key Topic Connections

Topic: Kafka Basics

Q1 (Topic) β†’ Q2 (Partition) β†’ Q3 (Distribution) β†’ Q4 (Key)

Key connections:

  • Q2 ↔ Q16: Partitions are replicated for fault tolerance
  • Q3 ↔ Q20: acks=all affects when a message is considered delivered
  • Q4 ↔ Q3: Key determines partition via MurmurHash

Topic: Consumer Groups

Q5 (Consumer Group) β†’ Q6 (Balancing) β†’ Q7 (More consumers)
     ↓
Q8 (Adding consumer) β†’ Q15 (Rebalancing)

Key connections:

  • Q5 ↔ Q12: Each consumer commits offset for each partition
  • Q6 ↔ Q15: Balancing is the rebalance itself
  • Q7 ↔ Q8: Idle consumers waste resources, adding a new one triggers rebalance

Topic: Offset and Delivery

Q12 (Offset) β†’ Q13 (Commit) β†’ Q14 (Auto vs Manual)
     ↓
Q9 (Guarantees) β†’ Q10 (At-most/at-least/exactly) β†’ Q11 (Configure exactly-once)

Key connections:

  • Q13 ↔ Q9: Commit BEFORE processing = at-most-once, AFTER = at-least-once
  • Q14 ↔ Q13: Auto commit = simpler but risk of loss; Manual = control
  • Q10 ↔ Q11: Exactly-once requires transactional producer

Topic: Producer

Q20 (acks) β†’ Q21 (Batch) β†’ Q22 (Compression) β†’ Q23 (Idempotent)

Key connections:

  • Q20 ↔ Q23: Idempotent producer + acks=all = exactly-once delivery to topic
  • Q21 ↔ Q22: Batch + compression = maximum throughput
  • Q23 ↔ Q11: Idempotent producer β€” the foundation of exactly-once

Topic: Fault Tolerance

Q16 (Replication) β†’ Q17 (Leader/Follower) β†’ Q18 (ISR) β†’ Q19 (Fault tolerance)

Key connections:

  • Q17 ↔ Q18: Leader is always in ISR, followers drop out if lagging
  • Q18 ↔ Q19: ISR shrink β†’ reduced fault tolerance
  • Q16 ↔ Q20: acks=all waits for acknowledgment from all ISR replicas

Topic: Operations

Q24 (Error handling) β†’ Q25 (DLQ) β†’ Q26 (Lag monitoring)
     ↓
Q27 (Retention) β†’ Q28 (Deletion) β†’ Q29 (Partition read) β†’ Q30 (Filtering)

Key connections:

  • Q24 ↔ Q25: DLQ β€” the last resort after retries
  • Q25 ↔ Q26: Lag monitoring helps detect issues before DLQ
  • Q27 ↔ Q28: Retention policy determines when and how messages are deleted
  • Q29 ↔ Q30: assign() for reading specific partitions, filtering on consumer side

πŸŽ“ Cheat Sheet: What to Know for Each Level

🟒 Junior

  • Topic = logical channel, partition = sub-channel for parallelism
  • Consumer Group = mechanism for distributing partitions among consumers
  • Offset = position in partition, commit = saving position
  • acks=0 (fire-and-forget), acks=1 (leader only), acks=all (all ISR)
  • At-most-once, at-least-once, exactly-once β€” three delivery semantics

🟑 Middle

  • Rebalancing: eager (full stop) vs cooperative (partial)
  • ISR: replicas that caught up with the leader. Leader is always in ISR
  • Batch: batch.size, linger.ms, compression β€” three throughput levers
  • DLQ: queue for messages that couldn’t be processed after N retries
  • Retention: retention.ms (time) + retention.bytes (size per partition)
  • Sticky partitioning: Kafka 2.4+ replaces round-robin

πŸ”΄ Senior

  • Exactly-once: EOS v2 (Kafka 2.5+), Producer ID + Epoch, transaction coordinator
  • Idempotent producer: deduplication at broker level via PID + sequence
  • ISR shrink/expand: monitoring is critical for fault tolerance
  • Cascading rebalancing: GC pause β†’ exclude β†’ rebalance β†’ overload β†’ another one falls
  • Outbox pattern: for exactly-once Kafka-to-Database
  • Leader Epoch: tracks data loss during failover

πŸ“ File Format

Each file contains:

  • 🟒 Junior Level β€” basic understanding, simple analogies, examples
  • 🟑 Middle Level β€” internals, common mistakes, practical examples
  • πŸ”΄ Senior Level β€” deep dive, edge cases, production experience, monitoring
  • 🎯 Interview Cheat Sheet β€” key takeaways, common questions, red flags, related topics