Interview Questions

Get ready for your next interview with our comprehensive question library

Apache Kafka Interview Questions

Filter by Difficulty

1.

Explain the core components of Kafka architecture.

beginner

Kafka architecture consists of several key components:

  • Producer: Applications that publish (write) events to Kafka topics
  • Consumer: Applications that subscribe to (read) events from topics
  • Broker: Kafka servers that store data and serve client requests
  • Topic: Categories or feed names to which records are published
  • Partition: Sub-divisions of topics for parallelism and scalability
  • Zookeeper: Coordinates and manages Kafka cluster metadata (being replaced by KRaft)
2.

What is a Kafka topic and how does partitioning work?

beginner

A topic is a category or stream name to which producers send messages and from which consumers read messages. Topics are divided into partitions for scalability and parallelism.

Partitioning benefits:

  • Enables parallel processing by multiple consumers
  • Distributes data across multiple brokers
  • Provides ordering guarantees within each partition
  • Allows horizontal scaling

Example: A topic "user-events" with 3 partitions can have messages distributed across partitions 0, 1, and 2 based on a key or round-robin.

3.

What is the role of Zookeeper in Kafka?

beginner

Zookeeper manages Kafka cluster coordination and metadata:

Responsibilities:

  • Broker discovery and health monitoring
  • Topic and partition metadata storage
  • Leader election for partitions
  • Consumer group coordination (legacy)
  • Configuration management

Note: Kafka is moving away from Zookeeper dependency with KRaft (Kafka Raft) mode, which handles metadata management internally.

4.

What are Kafka Headers and when would you use them?

beginner

Kafka Headers are optional metadata key-value pairs attached to each message record.

Use cases:

  • Routing: Route messages based on headers
  • Tracing: Add correlation IDs for distributed tracing
  • Security: Include authentication tokens
  • Content metadata: MIME types, encoding information
  • Source identification: Origin system information
// Producer adding headers
ProducerRecord<String, String> record = new ProducerRecord<>(
    "my-topic", "key", "value");
record.headers().add("correlation-id", "12345".getBytes());
record.headers().add("source-system", "order-service".getBytes());

Benefits: Headers don't affect partitioning and allow metadata without modifying message payload.

5.

What is Kafka's log retention and cleanup policies?

beginner

Kafka supports two cleanup policies:

1. Delete policy (cleanup.policy=delete):

  • Deletes old log segments based on time/size
  • log.retention.hours=168 (7 days default)
  • log.retention.bytes=-1 (unlimited size default)
  • log.segment.bytes=1GB (segment size)

2. Compact policy (cleanup.policy=compact):

  • Keeps the latest value for each key
  • Useful for changelog topics
  • Background compaction process
  • Maintains ordering within partitions

Combined policy:

cleanup.policy=compact,delete
# Both compaction and time-based deletion

Monitoring: Track log size and compaction metrics to ensure proper cleanup.

6.

What is the difference between Kafka and traditional message queues?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
7.

Explain Kafka producers and their key configurations.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
8.

How do Kafka consumers work and what is a consumer group?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
9.

What is offset management in Kafka?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
10.

Explain Kafka's replication mechanism.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
11.

What are Kafka's delivery semantics?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
12.

What is Kafka Streams and when would you use it?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
13.

Explain Kafka Connect and its purpose.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
14.

How does Kafka ensure high throughput?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
15.

Explain Kafka's log compaction feature.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
16.

What is the difference between `poll()` and `fetch()` in Kafka consumer?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
17.

How do you handle schema evolution in Kafka?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
18.

Explain Kafka's security features.

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
19.

What is the purpose of `__consumer_offsets` topic?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
20.

How do you monitor Kafka cluster performance?

intermediate

Upgrade to Premium to see the answer

Upgrade to Premium
Showing 1 to 20 of 37 results

Premium Plan

$10.00 /monthly
  • Access all premium content - interview questions, and other learning resources

  • We regularly update our features and content, to ensure you get the most relevant and updated premium content.

  • 1000 monthly credits

  • Cancel anytime