Challenge - 5 Problems
Kafka Memory Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of the producer buffer size setting?
Consider a Kafka producer configured with
buffer.memory=33554432 (32 MB). What is the maximum amount of memory the producer can use to buffer records waiting to be sent?Kafka
Properties props = new Properties(); props.put("buffer.memory", "33554432"); KafkaProducer<String, String> producer = new KafkaProducer<>(props); System.out.println(producer.metrics().get("bufferpool-total-bytes").metricValue());
Attempts:
2 left
💡 Hint
The buffer.memory property sets the total bytes of memory the producer can use to buffer records.
✗ Incorrect
The
buffer.memory setting controls the total bytes of memory the producer can use to buffer records before sending. Setting it to 33554432 means 32 MB of buffer memory.❓ Predict Output
intermediate2:00remaining
What happens if fetch.min.bytes is set too high?
In a Kafka consumer configuration, if
fetch.min.bytes is set to 1048576 (1 MB), what is the expected behavior when the broker has less data available?Kafka
Properties props = new Properties(); props.put("fetch.min.bytes", "1048576"); KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props); ConsumerRecords<String, String> records = consumer.poll(Duration.ofMillis(100)); System.out.println(records.count());
Attempts:
2 left
💡 Hint
fetch.min.bytes controls the minimum amount of data the broker returns to the consumer.
✗ Incorrect
Setting fetch.min.bytes to 1 MB means the consumer will wait until at least 1 MB of data is available before returning records, which can increase latency but improve throughput.
🔧 Debug
advanced2:00remaining
Why does the producer throw a BufferExhaustedException?
A Kafka producer configured with
buffer.memory=16384 (16 KB) and batch.size=32768 (32 KB) throws a BufferExhaustedException during high load. Why?Kafka
Properties props = new Properties(); props.put("buffer.memory", "16384"); props.put("batch.size", "32768"); KafkaProducer<String, String> producer = new KafkaProducer<>(props); // High volume sending loop for (int i = 0; i < 100000; i++) { producer.send(new ProducerRecord<>("topic", "key", "value")); }
Attempts:
2 left
💡 Hint
buffer.memory must be at least as large as batch.size to hold a batch in memory.
✗ Incorrect
The producer's buffer.memory is 16 KB but batch.size is 32 KB, so the producer cannot allocate enough memory for a batch, causing BufferExhaustedException.
📝 Syntax
advanced2:00remaining
Identify the syntax error in this Kafka consumer buffer configuration
Which option contains a syntax error in setting the consumer's fetch.max.bytes property in Java?
Kafka
Properties props = new Properties();
Attempts:
2 left
💡 Hint
Property keys must be strings in quotes.
✗ Incorrect
Option D misses quotes around the property key, causing a compile-time error because fetch.max.bytes is not defined as a variable.
🚀 Application
expert3:00remaining
Calculate total memory usage for a Kafka producer with multiple buffers
A Kafka producer is configured with
buffer.memory=67108864 (64 MB), batch.size=16384 (16 KB), and max.in.flight.requests.per.connection=5. What is the minimum total memory the producer needs to handle 5 in-flight batches without blocking?Attempts:
2 left
💡 Hint
Total memory must cover all in-flight batches but cannot exceed buffer.memory.
✗ Incorrect
Each batch is 16384 bytes. For 5 in-flight requests, minimum memory is 5 * 16384 = 81920 bytes. This is less than buffer.memory (64 MB), so the producer can handle it without blocking. Actual usage includes overhead, so total is slightly more than 81920 bytes but less than 67108864 bytes.