Get ready for your next interview with our comprehensive question library
Kafka architecture consists of several key components:
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:
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.
Zookeeper manages Kafka cluster coordination and metadata:
Responsibilities:
Note: Kafka is moving away from Zookeeper dependency with KRaft (Kafka Raft) mode, which handles metadata management internally.
Kafka Headers are optional metadata key-value pairs attached to each message record.
Use cases:
// 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.
Kafka supports two cleanup policies:
1. Delete policy (cleanup.policy=delete
):
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
):
Combined policy:
cleanup.policy=compact,delete
# Both compaction and time-based deletion
Monitoring: Track log size and compaction metrics to ensure proper cleanup.
Upgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumUpgrade to Premium to see the answer
Upgrade to PremiumAccess 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