Quick revision
The short answer
max.block.ms (60 s) bounds how long send() itself blocks for metadata or buffer space, and that error comes back on the calling thread. After send() returns, delivery.timeout.ms (120 s) bounds everything else: lingering for linger.ms, attempts of up to request.timeout.ms (30 s) each, and retries spaced by retry.backoff.ms (100 ms, growing to 1 s). Since retries defaults to Integer.MAX_VALUE, the callback gets a non-retriable error such as RecordTooLargeException at once, but a retriable one only when the 120 s run out.
What to remember
In this answer, we saw that a producer record waits in two places: inside send(), bounded by max.block.ms, and afterwards, bounded by delivery.timeout.ms, which covers lingering, attempts limited by request.timeout.ms and retries paced by the back-off settings. Since retries is effectively unlimited, the callback gets non-retriable errors immediately and retriable ones only when the delivery timeout expires.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
max.block.ms (60 s) bounds how long send() itself blocks for metadata or buffer space, and that error comes back on the calling thread. After send() returns, delivery.timeout.ms (120 s) bounds everything else: lingering for linger.ms, attempts of up to request.timeout.ms (30 s) each, and retries spaced by retry.backoff.ms (100 ms, growing to 1 s). Since retries defaults to Integer.MAX_VALUE, the callback gets a non-retriable error such as RecordTooLargeException at once, but a retriable one only when the 120 s run out.
Why this question is asked
Producer timeouts look like a list of unrelated numbers until something goes wrong in production: a send that hangs a request thread for a minute, or a callback that reports a failure two minutes after the broker went away. Interviewers ask this question because a developer who understands how the timers nest can predict both behaviours and choose settings on purpose. In this answer, we will recap what happens inside the producer, look at the wait that happens inside send(), then the delivery timeout that wraps everything after it, see how retries are paced, and finally list exactly when the callback receives an error.
1A Quick Recap of the Producer's Inner Path
The Java KafkaProducer never sends a record the moment we call send(). It first needs metadata, the map of which broker leads which partition, and it caches that map. Then it serializes the key and value, chooses a partition, and appends the record to a batch in the record accumulator, an in-memory area whose total size is buffer.memory (32 MB by default). A background thread, the sender, takes ready batches out of the accumulator and sends them to the leader brokers as produce requests.
So a record lives in two phases: first our own thread is blocked inside send(), then send() has returned a Future and the record waits, travels, maybe gets retried, and completes. Each phase has its own timer, and that split is the key to the whole question.
2The Wait Inside send(): max.block.ms
send() can block our thread for two reasons. If the producer has no metadata for the topic yet, for example on the first send after startup or while the brokers are unreachable, it waits for a metadata response. If the accumulator is full because batches cannot leave fast enough, it waits for buffer space to be freed. Both waits together are limited by max.block.ms, which is 60,000 ms by default.
Notice that this error belongs to our own thread and appears at the end of that wait, not two minutes later. Depending on the client version, it is thrown from send() or delivered straight away through the callback and an already-failed Future, so robust code handles both. The important design point is that max.block.ms is not part of the delivery timeout. It is a separate budget for the synchronous part of the call, and in a web request thread a 60 s block is usually far too long, which is why latency-sensitive services lower it to a few seconds.
3The Clock That Wraps Everything After send(): delivery.timeout.ms
Once send() returns, the record's delivery clock is running. delivery.timeout.ms, 120,000 ms by default, is the upper bound on the time from the return of send() to a final success or failure. It includes the time the record waits in its batch, the time spent in flight to the broker, every retry, and the back-off between retries. When the clock runs out, the producer fails the record with a TimeoutException even if it would have liked to try again.
Inside that budget, two smaller timers do their work. linger.ms tells the producer how long a batch may wait to collect more records before it is sent; the default is 5 ms since Kafka 4.0 (it was 0 before). request.timeout.ms, 30,000 ms by default, limits how long one produce request waits for the broker's response; when it expires, that attempt counts as failed and becomes a candidate for a retry.
- send() blocks for metadata or buffer spacebounded by
max.block.ms, 60 s - Record waits in a batchup to
linger.ms, 5 ms, or until the batch is full - Produce request in flighteach attempt bounded by
request.timeout.ms, 30 s - Did the broker succeed?YesCallback gets the offsetNoLook at the error
- Is the error retriable?YesBack off, then retryNoCallback gets the error now
- Has delivery.timeout.ms passed since send()?YesCallback gets a TimeoutExceptionNoSend the batch again
6 steps in order. Play them, or step through them one at a time.
Only the first step blocks our thread. Every later step counts against the single 120 s delivery budget.
The producer enforces that delivery.timeout.ms is at least linger.ms plus request.timeout.ms, so a record cannot expire before its first attempt had a fair chance.
4How Retries Are Paced: retries, retry.backoff.ms and retry.backoff.max.ms
retries counts how many times the producer may resend a failed batch. Its default is Integer.MAX_VALUE, which in practice means 'keep trying', but the delivery timeout still caps the total time. So in a modern client we tune the time budget, not the retry count.
Between attempts, the producer waits. retry.backoff.ms (100 ms by default) is the first wait, and recent clients (Kafka 3.7 and later) grow that wait exponentially, with some random jitter, up to retry.backoff.max.ms (1,000 ms by default). The jitter matters when many producers lose a broker at the same moment: without it, they would all retry in lockstep and hit the new leader together. Before each retry, the producer also refreshes its metadata, because the most common retriable errors, such as NOT_LEADER_OR_FOLLOWER, mean that the partition has moved.
Setting retries=0, a value still copied from old blog posts, throws away this protection: a routine leader election, which normally takes well under a second, would then fail records that a retry would have delivered.
5When the Callback Actually Receives an Error
Now we can answer the second part of the question precisely. Errors fall into two families. Non-retriable errors mean that sending again cannot help: RecordTooLargeException when a record is bigger than max.request.size or the topic's limit, authorization failures such as TopicAuthorizationException, or an invalid record. The producer reports these to the callback as soon as it learns of them, without waiting for any timer.
Retriable errors, such as NOT_LEADER_OR_FOLLOWER, NOT_ENOUGH_REPLICAS, a disconnect, or a request that timed out, are kept inside the client and retried. The callback hears nothing until either an attempt succeeds, in which case it receives the metadata with the offset, or delivery.timeout.ms runs out, in which case it receives a TimeoutException with a message saying how long has passed since the batch was created.
| Setting | Default | What it bounds |
|---|---|---|
max.block.ms | 60,000 ms | time our thread is blocked inside send() |
linger.ms | 5 ms (0 before Kafka 4.0) | how long a batch waits for more records |
request.timeout.ms | 30,000 ms | one produce attempt waiting for a response |
| retries | Integer.MAX_VALUE | number of resends; in practice unlimited |
retry.backoff.ms / retry.backoff.max.ms | 100 ms / 1,000 ms | pause between attempts, growing exponentially |
delivery.timeout.ms | 120,000 ms | whole time from send() returning to the final answer |
Notice that the callback runs on the producer's sender thread, so it must be quick. And an application that ignores the callback or the Future never sees a failed send at all.
6Follow-up questions
Why not simply set retries to 3 instead of relying on the delivery timeout?
Because a count does not describe what we care about. Three retries with a 100 ms back-off might all happen within a single leader election and fail a record that would have succeeded a second later, while three retries against a broker that accepts connections but never answers could take 90 s. Expressing the budget as time, with delivery.timeout.ms, gives the same worst case regardless of which failure happens, and that is why Kafka made the retry count effectively unlimited.
Can a TimeoutException in the callback mean the record was actually written?
Yes, in one case. If the last attempt reached the broker and was written, but the response never arrived before the timeout, the producer reports a failure for a record that is in the log. That is why a record reported as failed and then resent by the application can appear twice, and why consumers of important events deduplicate by an event id.
7Conclusion
In this answer, we saw that a producer record waits in two places: inside send(), bounded by max.block.ms, and afterwards, bounded by delivery.timeout.ms, which covers lingering, attempts limited by request.timeout.ms and retries paced by the back-off settings. Since retries is effectively unlimited, the callback gets non-retriable errors immediately and retriable ones only when the delivery timeout expires.
Open with
I think of the producer as having two clocks. The first is max.block.ms, 60 seconds by default, which limits how long send itself can block my thread, waiting for metadata or for space in the 32 megabyte buffer.
Then, if they want more
That error comes back on my thread at the end of the wait. Once send returns, the second clock starts: delivery.timeout.ms, two minutes by default, which covers the whole rest of the record's life. Inside it, linger.ms, now 5 milliseconds by default, lets a batch fill up, and each produce request may wait request.timeout.ms, 30 seconds, for a response.
The producer enforces that the delivery timeout is at least linger plus the request timeout. Retries default to Integer.MAX_VALUE, so the count does not really stop anything; the delivery timeout does. Between retries it backs off from 100 milliseconds up to one second with jitter, and refreshes metadata because a moved leader is the usual cause.
So the callback gets a non-retriable error like RecordTooLargeException or an authorization failure right away, but a retriable problem such as a broker outage only shows up as a TimeoutException once the two minutes are used up. That is why I always handle the callback or the future, and why I lower max.block.ms on latency-sensitive paths.
About this answer
- Last updated
- 13 November 2026
- Versions it names
- Kafka 4.0, Kafka 3.7
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Explain how delivery.timeout.ms, request.timeout.ms, linger.ms, retries...": https://scrivio-interview-library.netlify.app/spring-boot/kafka-clients-in-depth/daad5addbe/