Apache Kafka Streaming (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Handling Head-of-Line Blocking: Concurrency patterns with worker thread pools and out-of-order acknowledgment in consumers.
senior LevelSystem Design
In Simple Words: If message 5 in a partition takes 30 seconds to process (e.g. slow external API call), standard single-threaded consumers cannot process messages 6, 7, 8 behind it, stalling the entire partition.
- Worker Pool Pattern: The Kafka consumer thread only fetches messages and dispatches them into an internal in-memory bounded queue (
BlockingQueue) processed by a thread pool. - Offset Tracking: The consumer thread only commits an offset when all preceding offsets in the partition have confirmed completion, avoiding missing un-processed messages during consumer crashes.