Bird
Raised Fist0
Kafkadevops~10 mins

Memory and buffer configuration in Kafka - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the buffer memory size in Kafka producer configuration.

Kafka
props.put("buffer.memory", [1]);
Drag options to blanks, or click blank then click option'
A33554432
B"buffer.memory"
C1024
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a numeric value.
Setting too small a buffer size causing frequent blocking.
2fill in blank
medium

Complete the code to configure the batch size for Kafka producer buffers.

Kafka
props.put("batch.size", [1]);
Drag options to blanks, or click blank then click option'
A16384
B1000
C"batch.size"
Dtrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of an integer.
Setting batch size too large causing latency.
3fill in blank
hard

Fix the error in setting linger.ms to control buffer delay.

Kafka
props.put("linger.ms", [1]);
Drag options to blanks, or click blank then click option'
A"100"
B100
Ctrue
D"true"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing linger.ms as a string instead of an integer.
Using boolean values which are invalid.
4fill in blank
hard

Fill both blanks to configure buffer memory and batch size correctly.

Kafka
props.put("buffer.memory", [1]);
props.put("batch.size", [2]);
Drag options to blanks, or click blank then click option'
A33554432
B16384
C1000
D"buffer.memory"
Attempts:
3 left
💡 Hint
Common Mistakes
Using strings instead of integers.
Mixing up the values for buffer.memory and batch.size.
5fill in blank
hard

Fill all three blanks to configure buffer.memory, batch.size, and linger.ms properly.

Kafka
props.put("buffer.memory", [1]);
props.put("batch.size", [2]);
props.put("linger.ms", [3]);
Drag options to blanks, or click blank then click option'
A33554432
B16384
C100
D"100"
Attempts:
3 left
💡 Hint
Common Mistakes
Passing linger.ms as a string.
Using incorrect units or types for buffer.memory and batch.size.

Practice

(1/5)
1. Which Kafka configuration setting controls the size of the buffer used to batch data before sending to brokers?
easy
A. fetch.min.bytes
B. batch.size
C. buffer.memory
D. linger.ms

Solution

  1. Step 1: Understand buffer settings in Kafka producer

    The batch.size setting controls the maximum size of a batch of records sent to brokers.
  2. Step 2: Differentiate from other buffer-related settings

    buffer.memory controls total memory for buffering, fetch.min.bytes is for consumers, and linger.ms controls delay before sending batches.
  3. Final Answer:

    batch.size -> Option B
  4. Quick Check:

    Batch size controls batch buffer size [OK]
Hint: Batch size sets buffer for sending data batches [OK]
Common Mistakes:
  • Confusing total buffer memory with batch size
  • Mixing consumer fetch settings with producer buffers
  • Thinking linger.ms controls buffer size
2. Which of the following is the correct syntax to set the buffer memory size to 32MB in Kafka producer properties file?
easy
A. buffer.memory=33554432
B. buffer.memory=32
C. buffer.memory=32m
D. buffer.memory=32MB

Solution

  1. Step 1: Understand Kafka config value units

    Kafka expects buffer.memory in bytes, not with units like MB or m.
  2. Step 2: Convert 32MB to bytes

    32MB = 32 * 1024 * 1024 = 33554432 bytes, so the value must be numeric bytes.
  3. Final Answer:

    buffer.memory=33554432 -> Option A
  4. Quick Check:

    Buffer memory uses bytes, not MB string [OK]
Hint: Use bytes number, not MB string, for buffer.memory [OK]
Common Mistakes:
  • Adding MB or m suffix which Kafka does not parse
  • Using too small number without units
  • Confusing buffer.memory with batch.size units
3. Given this Kafka producer config snippet:
buffer.memory=1048576
batch.size=16384
linger.ms=10

What is the maximum amount of data (in bytes) that can be buffered before sending?
medium
A. 1048586 bytes
B. 16384 bytes
C. 1048576 bytes
D. 10 bytes

Solution

  1. Step 1: Identify buffer.memory meaning

    buffer.memory is the total bytes available to buffer records waiting to be sent.
  2. Step 2: Understand batch.size role

    batch.size is max size per batch, but total buffer can hold multiple batches up to buffer.memory.
  3. Final Answer:

    1048576 bytes -> Option C
  4. Quick Check:

    Total buffer memory = 1048576 bytes [OK]
Hint: buffer.memory is total buffer size, batch.size is per batch [OK]
Common Mistakes:
  • Confusing batch.size as total buffer
  • Adding linger.ms value to buffer size
  • Choosing sum of batch.size and buffer.memory
4. You set buffer.memory=1024 and batch.size=2048 in Kafka producer config. What issue will occur?
medium
A. Producer will throw a configuration error on startup
B. No issue; Kafka adjusts batch.size automatically
C. Producer will silently drop messages exceeding buffer.memory
D. Producer will block or throw an error when batch.size exceeds buffer.memory

Solution

  1. Step 1: Compare batch.size and buffer.memory values

    Here, batch.size (2048) is larger than buffer.memory (1024), which is invalid.
  2. Step 2: Kafka behavior on invalid buffer sizes

    Kafka producer will block or throw an error because it cannot allocate a batch larger than total buffer memory.
  3. Final Answer:

    Producer will block or throw an error when batch.size exceeds buffer.memory -> Option D
  4. Quick Check:

    batch.size must be ≤ buffer.memory [OK]
Hint: batch.size cannot be bigger than buffer.memory [OK]
Common Mistakes:
  • Assuming Kafka auto-corrects batch.size
  • Expecting silent message drops
  • Thinking config error happens at startup
5. You want to optimize Kafka producer for low latency and high throughput. Which combination of memory and buffer settings is best?
hard
A. Increase buffer.memory, decrease linger.ms, increase batch.size
B. Decrease buffer.memory, increase linger.ms, decrease batch.size
C. Keep buffer.memory small, set linger.ms high, increase batch.size
D. Set buffer.memory and batch.size low, linger.ms high

Solution

  1. Step 1: Understand latency vs throughput tradeoff

    Low latency means sending data quickly, high throughput means sending large batches efficiently.
  2. Step 2: Adjust buffer and batch settings accordingly

    Increasing buffer.memory and batch.size allows bigger batches, while decreasing linger.ms reduces wait time before sending.
  3. Final Answer:

    Increase buffer.memory, decrease linger.ms, increase batch.size -> Option A
  4. Quick Check:

    Big buffer + big batch + low linger = low latency & high throughput [OK]
Hint: Big buffer and batch, low linger for speed and volume [OK]
Common Mistakes:
  • Increasing linger.ms reduces latency
  • Decreasing buffer.memory improves throughput
  • Setting batch.size too low for throughput
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard