Apache Kafka Kafka Producers & Consumers 1 — Questions and Answers
Question 1: Which producer configuration controls the maximum time (in ms) a producer will wait before sending a batch of records?
- linger.ms (Correct answer)
- batch.size
- acks
- retries
Correct answer: linger.ms
linger.ms specifies the delay a producer adds before sending a batch, allowing more records to accumulate.
Question 2: What does setting `acks=all` mean for a Kafka producer?
- The producer waits for acknowledgment from all in-sync replicas (Correct answer)
- Only the leader acknowledges
- No acknowledgment is required
- Only followers acknowledge
Correct answer: The producer waits for acknowledgment from all in-sync replicas
acks=all (or acks=-1) requires the leader to wait for the full set of in-sync replicas to acknowledge the record.
Question 3: Which consumer configuration determines how frequently the consumer offsets are committed automatically?
- auto.commit.interval.ms (Correct answer)
- fetch.min.bytes
- max.poll.records
- session.timeout.ms
Correct answer: auto.commit.interval.ms
auto.commit.interval.ms sets the frequency (in milliseconds) at which the consumer's offsets are committed when enable.auto.commit is true.
Question 4: What is the purpose of the `max.poll.records` consumer configuration?
- Limits the maximum number of records returned in a single poll() call (Correct answer)
- Sets the max partition count
- Controls the fetch size in bytes
- Defines the max lag allowed
Correct answer: Limits the maximum number of records returned in a single poll() call
max.poll.records controls the maximum number of records that a single call to poll() will return.
Question 5: When a Kafka producer sends a message without a key, how is the partition selected?
- Round-robin across available partitions (Correct answer)
- Always partition 0
- Random single partition for the whole session
- Based on timestamp
Correct answer: Round-robin across available partitions
Without a key, the default partitioner distributes messages in round-robin fashion across all available partitions.
Question 6: Which setting must be enabled for a Kafka consumer to commit offsets automatically?
- enable.auto.commit=true (Correct answer)
- auto.offset.reset=earliest
- isolation.level=read_committed
- fetch.wait.max.ms=500
Correct answer: enable.auto.commit=true
enable.auto.commit=true instructs the consumer to automatically commit offsets at the interval specified by auto.commit.interval.ms.
Which producer configuration controls the maximum time (in ms) a producer will wait before sending a batch of records?