# π **Kafka Interview Questions & Answers β The Ultimate 50+ Guide for Data Engineers, Developers & Architects**
**#KafkaInterview #ApacheKafka #DataEngineering #StreamingInterview #KafkaQuestions #RealTimeProcessing #EventDriven #BigDataInterview**
---
## πΉ **Table of Contents**
1. [Introduction: Why Kafka Interview Questions Matter](#introduction-why-kafka-interview-questions-matter)
2. [Basic Kafka Concepts (Questions 1β15)](#basic-kafka-concepts-questions-1β15)
3. [Producers & Consumers (Questions 16β25)](#producers--consumers-questions-16β25)
4. [Topics, Partitions & Replication (Questions 26β35)](#topics-partitions--replication-questions-26β35)
5. [Kafka Streams & ksqlDB (Questions 36β42)](#kafka-streams--ksqldb-questions-36β42)
6. [Schema, Serialization & Schema Registry (Questions 43β47)](#schema-serialization--schema-registry-questions-43β47)
7. [Security, Monitoring & Production (Questions 48β55)](#security-monitoring--production-questions-48β55)
8. [Advanced & Scenario-Based Questions (Questions 56β65)](#advanced--scenario-based-questions-questions-56β65)
9. [Final Tips for Acing Kafka Interviews](#final-tips-for-acing-kafka-interviews)
---
## πΉ **Introduction: Why Kafka Interview Questions Matter**
Apache Kafka has become the **de facto standard** for real-time data streaming in modern architectures. Companies like **Netflix, Uber, LinkedIn, and Walmart** rely on Kafka for mission-critical systems.
As demand grows, so does competition for **Data Engineers, Streaming Developers, and Platform Architects**.
This guide provides **65+ Kafka interview questions** β from **basic to advanced**, with **detailed answers**, real-world examples, and best practices.
Whether you're preparing for:
- A **Junior Developer** role
- A **Senior Data Engineer** position
- Or a **Streaming Architect** interview
This is your **ultimate Kafka prep resource**.
Letβs dive in!
---
## πΉ **Basic Kafka Concepts (Questions 1β15)**
---
### **Q1: What is Apache Kafka?**
**Answer:**
Apache Kafka is an **open-source distributed event streaming platform** used to build real-time data pipelines and streaming applications. It enables high-throughput, fault-tolerant, and scalable publish-subscribe messaging.
> β Kafka is not just a message queue β itβs a **distributed commit log** that can store, process, and react to streams of events.
**Key Features:**
- High throughput
- Low latency
- Durability (data stored on disk)
- Scalability (horizontal)
- Fault tolerance (replication)
---
### **Q2: What are the main components of Kafka?**
**Answer:**
The core components are:
| Component | Role |
|--------|------|
| **Broker** | A Kafka server that stores data and serves clients |
| **Topic** | A category/feed name to which messages are published |
| **Producer** | App that sends data to a topic |
| **Consumer** | App that reads data from a topic |
| **ZooKeeper (or KRaft)** | Manages cluster metadata (in older versions); KRaft replaces ZooKeeper in newer Kafka versions |
> πΉ In Kafka 3.3+, **KRaft (Kafka RaFt Metadata mode)** eliminates ZooKeeper dependency.
---
### **Q3: What is a Topic in Kafka?**
**Answer:**
A **topic** is a logical category or feed name to which records are published. Itβs like a "table" or "folder" for messages.
Example:
```bash
topic: user-logins
topic: payment-events
topic: clickstream
```
Each topic is split into **partitions** for scalability.
---
### **Q4: What is a Partition in Kafka?**
**Answer:**
A **partition** is an **ordered, immutable sequence of records** that is continually appended to.
- Each partition is an **ordered log** with messages assigned a sequential **offset**.
- Partitions allow **parallelism** β multiple producers/consumers can work simultaneously.
- Messages within a partition are **ordered**, but not across partitions.
> β More partitions = higher throughput and scalability.
---
### **Q5: What is an Offset?**
**Answer:**
An **offset** is a unique ID for a message within a partition.
Example:
```
Partition 0: [msg0] β [msg1] β [msg2]
offset=0 offset=1 offset=2
```
The consumer tracks:
- **Current offset**: next message to read.
- **Committed offset**: last successfully processed message.
On restart, consumer resumes from **committed offset**.
---
### **Q6: What is a Consumer Group?**
**Answer:**
A **consumer group** is a set of consumers that **cooperatively read from a topic**.
- Each partition is consumed by **only one consumer** in the group.
- Enables **parallel processing** and **horizontal scaling**.
Example:
- Topic with 3 partitions.
- 3 consumers in group β each reads one partition.
- 4th consumer β idle.
> β This is how Kafka achieves **load balancing** among consumers.
---
### **Q7: What is ZooKeeperβs role in Kafka?**
**Answer:**
ZooKeeper manages **cluster metadata**, including:
- Broker IDs and status
- Topic configurations
- Access Control Lists (ACLs)
- Leader/follower elections
> β οΈ **Note**: Kafka 3.3+ introduces **KRaft (Kafka RaFt mode)**, which removes ZooKeeper dependency.
---
### **Q8: What is KRaft? Why was it introduced?**
**Answer:**
**KRaft (Kafka RaFt Metadata mode)** is a new consensus protocol that allows Kafka to manage its own metadata, **eliminating ZooKeeper**.
**Benefits:**
- Simpler architecture
- Faster controller failover
- Larger cluster scalability (up to 1M partitions)
- Easier operations
> β Use KRaft for **new Kafka clusters**.
---
### **Q9: What are the different delivery semantics in Kafka?**
**Answer:**
Kafka supports three delivery guarantees:
| Guarantee | How Achieved | Risk |
|---------|--------------|------|
| **At-most-once** | `acks=0` | Message loss |
| **At-least-once** | `acks=all` + retries | Duplicates |
| **Exactly-once** | Idempotent producer + transactions | No loss, no duplicates |
> β **Exactly-once** is available via Kafka Streams, transactions, or idempotent producers.
---
### **Q10: What is the role of a Kafka Producer?**
**Answer:**
A **producer** is a client application that **publishes records** to Kafka topics.
Responsibilities:
- Serialize data
- Choose partition (via key)
- Handle retries and batching
- Send messages to the correct broker
---
### **Q11: What is the role of a Kafka Consumer?**
**Answer:**
A **consumer** reads messages from Kafka topics.
Responsibilities:
- Subscribe to topics
- Poll for messages
- Deserialize data
- Track and commit offsets
- Handle rebalancing
---
### **Q12: What is a Broker in Kafka?**
**Answer:**
A **broker** is a Kafka server that:
- Stores data (topics/partitions)
- Serves producer and consumer requests
- Participates in replication
A **Kafka cluster** consists of one or more brokers.
Each broker has a unique **broker ID**.
---
### **Q13: What is Replication in Kafka?**
**Answer:**
**Replication** copies each partition across multiple brokers for **fault tolerance**.
- One **leader** handles reads/writes.
- Others are **followers** (replicate data).
- If leader fails, a follower becomes leader.
> β **Replication factor = 3** is standard in production.
---
### **Q14: What is ISR (In-Sync Replicas)?**
**Answer:**
**ISR (In-Sync Replicas)** are replicas that are **synchronized** with the leader.
- Only ISR members can become leader during failover.
- Prevents **data loss**.
Configurable via:
```properties
replica.lag.time.max.ms=30000 # 30 seconds
```
If a follower falls behind, itβs removed from ISR.
---
### **Q15: What is the difference between Queue and Publish-Subscribe in Kafka?**
**Answer:**
| Feature | Queue (Point-to-Point) | Publish-Subscribe |
|--------|------------------------|-------------------|
| Consumers | One consumer per message | Multiple subscribers |
| Use Case | Task distribution | Event broadcasting |
| Kafka Equivalent | Single consumer group | Multiple consumer groups |
> β Kafka supports **both models** via consumer groups.
---
## πΉ **Producers & Consumers (Questions 16β25)**
---
### **Q16: What is the purpose of `acks` in Kafka Producer?**
**Answer:**
`acks` controls how many replicas must acknowledge receipt before the producer considers the write successful.
| Value | Meaning |
|------|--------|
| `acks=0` | Fire-and-forget (fastest, risk of loss) |
| `acks=1` | Leader acknowledges (balanced) |
| `acks=all` or `acks=-1` | Leader + all ISR acknowledge (safest) |
> β Use `acks=all` in production.
---
### **Q17: What is idempotent producer?**
**Answer:**
An **idempotent producer** ensures that **duplicate messages are not written** due to retries.
Enabled with:
```java
props.put("enable.idempotence", "true");
```
> β Guarantees **exactly-once delivery within a session**.
Uses **producer ID + sequence number** per partition.
---
### **Q18: What is the difference between synchronous and asynchronous send?**
**Answer:**
| Sync Send | Async Send |
|---------|-----------|
| Blocks until acknowledgment | Non-blocking |
| Slower | Faster |
| Good for debugging | Preferred in production |
| Uses `get()` on `Future` | Uses `Callback` |
```java
// Sync
producer.send(record).get();
// Async
producer.send(record, callback);
```
---
### **Q19: What is consumer lag? How do you monitor it?**
**Answer:**
**Consumer lag** = difference between **latest message offset** and **consumerβs current offset**.
High lag means consumer is **falling behind**.
Monitor with:
```bash
bin/kafka-consumer-groups.sh \
--bootstrap-server localhost:9092 \
--describe \
--group my-group
```
Use **Prometheus + Grafana** or **Confluent Control Center** in production.
---
### **Q20: What is rebalancing in Kafka?**
**Answer:**
**Rebalancing** occurs when:
- A consumer joins/leaves a group
- Partitions are added
- Consumer fails
During rebalance:
- All consumers pause
- Partitions are reassigned
- Consumers resume
> β οΈ Long processing in `poll()` can trigger rebalances.
---
### **Q21: How do you prevent rebalancing issues?**
**Answer:**
- Set `max.poll.interval.ms` high enough for processing.
- Offload heavy work to another thread.
- Use **CooperativeStickyAssignor** for incremental rebalancing.
- Avoid blocking in `poll()`.
---
### **Q22: What is `enable.auto.commit`? When should you use it?**
**Answer:**
`enable.auto.commit=true` means Kafka **automatically commits offsets** every `auto.commit.interval.ms` (default: 5s).
> β οΈ **Avoid in production** β can cause **duplicate processing** if consumer fails after processing but before commit.
β Use **manual commits** (`commitSync()`) for **at-least-once** delivery.
---
### **Q23: What is the difference between `commitSync()` and `commitAsync()`?**
**Answer:**
| `commitSync()` | `commitAsync()` |
|---------------|----------------|
| Blocks until commit succeeds | Non-blocking |
| Slower | Faster |
| Safe (retry on failure) | May lose commit if consumer crashes |
| Use in main loop | Use for performance, with `commitSync()` on shutdown |
---
### **Q24: How does Kafka ensure message ordering?**
**Answer:**
Kafka guarantees **ordering within a partition**.
To preserve order:
- Use the **same key** for related messages.
- They go to the **same partition**.
> β No ordering guarantee across partitions.
---
### **Q25: What happens if a consumer fails during processing?**
**Answer:**
- If **offsets are committed**, the message is **lost** (at-most-once).
- If **not committed**, it will be **reprocessed** (at-least-once).
- With **exactly-once**, Kafka Streams or transactions prevent duplicates.
> β Use **idempotent processing** to handle duplicates safely.
---
## πΉ **Topics, Partitions & Replication (Questions 26β35)**
---
### **Q26: How do you choose the number of partitions for a topic?**
**Answer:**
Factors:
- **Throughput needs**: more partitions = higher parallelism.
- **Consumer count**: 1 consumer per partition per group.
- **Broker limits**: β€ 2000 partitions per broker.
- **Rebalance time**: more partitions = longer rebalances.
> β Start with 6β12, scale as needed.
---
### **Q27: Can you decrease the number of partitions in a topic?**
**Answer:**
β **No.** You can **increase** partitions, but **not decrease**.
> β οΈ Increasing partitions can break **key-based ordering**.
---
### **Q28: What is log compaction? When would you use it?**
**Answer:**
**Log compaction** keeps only the **latest value** for each key.
Use for:
- **State-based topics** (e.g., user profiles, inventory)
- Avoid replaying all events
Set:
```properties
cleanup.policy=compact
```
> β Combine with `delete`: `cleanup.policy=compact,delete`
---
### **Q29: What is the default retention period for messages?**
**Answer:**
Default: **7 days** (`retention.ms=604800000`)
Configurable per topic:
```bash
--config retention.ms=86400000 # 1 day
```
---
### **Q30: What is a follower replica?**
**Answer:**
A **follower** is a broker that **replicates data** from the leader.
- Pulls data from leader.
- Becomes leader if current leader fails.
- Must be in **ISR** to be eligible.
---
### **Q31: What is `min.insync.replicas`?**
**Answer:**
Minimum number of replicas that must be in sync for `acks=all` to succeed.
```properties
min.insync.replicas=2
```
With RF=3, this ensures durability even if one replica fails.
> β Set `unclean.leader.election.enable=false` to avoid data loss.
---
### **Q32: What is the role of the leader replica?**
**Answer:**
The **leader**:
- Handles all **read/write requests** for a partition.
- Replicates data to followers.
- Maintains the **high watermark** (last committed offset).
---
### **Q33: How does Kafka handle broker failure?**
**Answer:**
- ZooKeeper/KRaft detects failure.
- A **follower in ISR** becomes the new leader.
- Producers/consumers reconnect to new leader.
- No data loss if `acks=all` and `min.insync.replicas` met.
---
### **Q34: What is the `__consumer_offsets` topic?**
**Answer:**
Internal topic that stores **consumer group offsets**.
- Key: `<group.id, topic, partition>`
- Value: committed offset
- Compact + delete policy
> β Never delete or modify this topic.
---
### **Q35: How do you reassign partitions to new brokers?**
**Answer:**
Use `kafka-reassign-partitions.sh`:
1. Generate reassignment plan:
```bash
--generate --topics-to-move-json-file topics.json --broker-list "0,1,2,3"
```
2. Execute:
```bash
--execute --reassignment-json-file reassign.json
```
> β Used when adding new brokers.
---
## πΉ **Kafka Streams & ksqlDB (Questions 36β42)**
---
### **Q36: What is Kafka Streams?**
**Answer:**
A **Java/Scala library** for building **real-time stream processing** applications.
Features:
- Filter, map, join, aggregate
- Windowing (tumbling, hopping, session)
- State stores (RocksDB)
- Exactly-once processing
> β Embedded in your app β no separate cluster.
---
### **Q37: What is ksqlDB?**
**Answer:**
**ksqlDB** is a **streaming SQL engine** for Kafka.
- Write SQL-like queries on streams.
- Real-time analytics.
- No code required.
Example:
```sql
SELECT * FROM users WHERE region = 'US' EMIT CHANGES;
```
> β Great for prototyping and dashboards.
---
### **Q38: What is the difference between KStream and KTable?**
**Answer:**
| KStream | KTable |
|--------|--------|
| Append-only event stream | Changelog stream (latest state) |
| Each record is an event | Each record updates state |
| Use for filtering, mapping | Use for joins, aggregations |
---
### **Q39: What is windowing in Kafka Streams?**
**Answer:**
**Windowing** groups events by time for aggregation.
Types:
- **Tumbling**: Fixed, non-overlapping (e.g., 1-min counts)
- **Hopping**: Fixed size, overlapping (e.g., 1-min window every 30s)
- **Session**: Dynamic, based on activity gaps
---
### **Q40: How does Kafka Streams achieve exactly-once processing?**
**Answer:**
Using:
- **Idempotent producers**
- **Transactional writes**
- **Atomic commits** of processing and offset
Enabled with:
```java
props.put("processing.guarantee", "exactly_once_v2");
```
---
### **Q41: What are state stores in Kafka Streams?**
**Answer:**
**State stores** (e.g., RocksDB) store:
- Aggregations
- Joins
- Windowed data
Fault-tolerant via **changelog topics**.
Supports **interactive queries** (REST API to query state).
---
### **Q42: What is interactive querying in Kafka Streams?**
**Answer:**
Ability to **query the state** of a Kafka Streams app via REST API.
Useful for:
- Building real-time dashboards
- Debugging
- Exposing stream state to external apps
---
## πΉ **Schema, Serialization & Schema Registry (Questions 43β47)**
---
### **Q43: Why use Schema Registry?**
**Answer:**
Schema Registry:
- Stores Avro/Protobuf/JSON schemas
- Assigns unique IDs
- Enforces compatibility
- Enables schema evolution
> β Prevents "garbage-in, garbage-out" data.
---
### **Q44: What is Avro? Why is it used with Kafka?**
**Answer:**
**Avro** is a binary serialization format with:
- Schema-first design
- Compact size
- Schema evolution support
- Language independence
β Ideal for Kafka due to efficiency and schema safety.
---
### **Q45: What are compatibility types in Schema Registry?**
**Answer:**
| Type | Meaning |
|------|--------|
| **Backward** | New schema can read old data β |
| **Forward** | Old schema can read new data |
| **Full** | Both backward and forward |
| **None** | No checks |
> β Use **Backward** for most use cases.
---
### **Q46: What happens if a schema change is not compatible?**
**Answer:**
Schema Registry **rejects** the new schema.
Producer fails with:
```
IncompatibleSchemaException
```
> β Forces teams to handle evolution safely.
---
### **Q47: What is the naming convention for subjects in Schema Registry?**
**Answer:**
```
<TopicName>-<Type>
```
Example:
- `user-events-value` β value schema
- `user-events-key` β key schema
Configurable.
---
## πΉ **Security, Monitoring & Production (Questions 48β55)**
---
### **Q48: How do you secure Kafka?**
**Answer:**
Use:
- **SSL/TLS** for encryption in transit
- **SASL** (PLAIN, SCRAM, Kerberos) for authentication
- **ACLs** for authorization
- **Encryption at rest** (disk-level)
---
### **Q49: What is SASL/SCRAM?**
**Answer:**
**SASL/SCRAM** (Salted Challenge Response Authentication Mechanism) is a secure way to authenticate clients using username/password with hashing.
More secure than SASL/PLAIN.
---
### **Q50: How do you monitor Kafka?**
**Answer:**
Monitor:
- **JMX metrics** via Prometheus
- **Consumer lag**
- **Under-replicated partitions**
- **Broker CPU, disk, network**
- Use **Grafana**, **Burrow**, or **Confluent Control Center**
---
### **Q51: What is MirrorMaker?**
**Answer:**
**MirrorMaker** replicates data between Kafka clusters.
Use for:
- Disaster recovery
- Multi-region setups
- Cloud migration
**MirrorMaker 2** supports active-passive and active-active.
---
### **Q52: How do you perform a rolling restart?**
**Answer:**
1. Stop one broker.
2. Upgrade config/jar.
3. Restart.
4. Wait for ISR sync.
5. Repeat for next broker.
β Zero downtime.
---
### **Q53: What is Kafka Connect?**
**Answer:**
A framework for **scalable, fault-tolerant** data integration.
- **Source Connectors**: Pull data into Kafka (e.g., JDBC, Debezium)
- **Sink Connectors**: Push data from Kafka (e.g., Elasticsearch, S3)
---
### **Q54: What is Debezium?**
**Answer:**
**Debezium** is a CDC (Change Data Capture) connector that captures row-level changes from databases (MySQL, PostgreSQL) and streams them to Kafka.
---
### **Q55: What is tiered storage?**
**Answer:**
**Tiered storage** (Kafka 3.6+) offloads old log segments to **cloud storage** (S3, GCS).
Benefits:
- Reduce broker disk usage
- Long retention at low cost
- No need for external archiving
---
## πΉ **Advanced & Scenario-Based Questions (Questions 56β65)**
---
### **Q56: How would you design a fraud detection system using Kafka?**
**Answer:**
1. **Producers**: App logs transactions.
2. **Topic**: `transactions` (partitioned by user ID).
3. **Kafka Streams**: Windowed count of transactions per user in 1 min.
4. If > 5 transactions β alert.
5. **Sink**: Send to alert system or DB.
> β Use exactly-once for accuracy.
---
### **Q57: How do you handle message size limits?**
**Answer:**
Default max: **1MB**.
Solutions:
- Increase `message.max.bytes` and `replica.fetch.max.bytes`
- Use compression (`compression.type=snappy`)
- Split large messages
- Store large data in S3, send reference in Kafka
---
### **Q58: How do you test Kafka applications?**
**Answer:**
- **Unit tests**: `@EmbeddedKafka` (Spring), `EmbeddedKafkaCluster`
- **Integration tests**: Testcontainers
- **End-to-end**: Deploy to staging with real traffic
---
### **Q59: What is the impact of too many small messages?**
**Answer:**
- High network overhead
- Reduced throughput
- Inefficient batching
β **Fix**: Use `linger.ms` and `batch.size` to batch messages.
---
### **Q60: How do you upgrade Kafka version?**
**Answer:**
1. Test in staging.
2. Use rolling restart.
3. Update one broker at a time.
4. Verify compatibility.
5. Update clients.
> β Use dual writing for major version upgrades.
---
### **Q61: How do you debug consumer lag?**
**Answer:**
1. Check if consumer is stuck (CPU, GC).
2. Review `max.poll.interval.ms`.
3. Monitor processing time.
4. Scale consumers or optimize logic.
---
### **Q62: How do you ensure data lineage in Kafka?**
**Answer:**
- Use **Schema Registry** with metadata.
- Add **trace IDs** to messages.
- Use **OpenLineage** or **data catalog** tools.
- Log producer/consumer info.
---
### **Q63: What are the trade-offs of using ksqlDB vs Kafka Streams?**
**Answer:**
| ksqlDB | Kafka Streams |
|-------|---------------|
| Easy (SQL) | Code required |
| Limited flexibility | Full control |
| External server | Embedded |
| Slower for complex logic | Faster, optimized |
> β Use ksqlDB for analytics, Kafka Streams for complex apps.
---
### **Q64: How do you handle schema evolution safely?**
**Answer:**
1. Use **Avro + Schema Registry**.
2. Set compatibility to **Backward**.
3. Only **add optional fields**.
4. Never remove or rename fields.
5. Test in staging.
---
### **Q65: What are the signs of a misconfigured Kafka cluster?**
**Answer:**
- High consumer lag
- Frequent rebalances
- Under-replicated partitions
- Disk full errors
- Slow produce/fetch requests
- ZooKeeper timeouts
> β Monitor and tune proactively.
---
## πΉ **Final Tips for Acing Kafka Interviews**
1. **Know the fundamentals**: Brokers, topics, partitions, offsets.
2. **Explain trade-offs**: At-least-once vs exactly-once, batching vs latency.
3. **Use real examples**: "In my last project, we used Kafka Streams to..."
4. **Draw diagrams**: Sketch consumer groups, partitioning, flows.
5. **Show depth**: Donβt just say "Kafka is fast" β explain **why** (sequential I/O, batching).
6. **Ask smart questions**: "Do you use KRaft or ZooKeeper?"
> π¬ **"The best Kafka engineers donβt just know the API β they understand the philosophy."**
---
β **Youβre now fully prepared** to crush any Kafka interview.
#KafkaInterview #KafkaQuestions #DataEngineering #Streaming #ApacheKafka #BigData #EventDriven #InterviewPrep #KafkaMastery