Quick revision
The short answer
NotEnoughReplicasException means the partition has fewer in-sync replicas than min.insync.replicas, so the broker refuses acks=all writes rather than accept them with weak durability. It is retriable, so the producer keeps retrying internally until delivery.timeout.ms, 2 minutes by default, expires, and then fails the send with a TimeoutException. The service must handle that failed future by retrying at the application level, storing the event for later such as in an outbox, or failing the request, and the team should find out why replicas fell out of sync, without lowering min.insync.replicas just to silence the errors.
What to remember
In this answer, we decoded NotEnoughReplicasException as the broker refusing acks=all writes because the ISR fell below min.insync.replicas, and saw how internal retries end in a TimeoutException after delivery.timeout.ms. The service must handle the failed future by failing the request, storing the event for retry or using an outbox, and the team must find why a second replica was out of sync, often an unsafe rolling restart, rather than lowering min.insync.replicas.
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.
NotEnoughReplicasException means the partition has fewer in-sync replicas than min.insync.replicas, so the broker refuses acks=all writes rather than accept them with weak durability. It is retriable, so the producer keeps retrying internally until delivery.timeout.ms, 2 minutes by default, expires, and then fails the send with a TimeoutException. The service must handle that failed future by retrying at the application level, storing the event for later such as in an outbox, or failing the request, and the team should find out why replicas fell out of sync, without lowering min.insync.replicas just to silence the errors.
Why this question is asked
A broker restart is routine maintenance, so errors during one are a sign that either the restart procedure or the producer's error handling has a gap. These two exceptions often appear together and are easily misread as network problems. Interviewers ask this to see whether we understand what the broker is protecting and how a producer should behave when Kafka says 'not now'. In this answer, we will decode each error, follow the timeline from the restart to the failed send, decide how the service should react, and then find and fix the cause on the broker side.
1What NotEnoughReplicasException Means
Our topic has replication factor 3 and min.insync.replicas 2, and producers use acks=all. While all three replicas are in the in-sync replica set, or ISR, writes succeed. When we restart broker 1, its replicas leave the ISR. If another replica of the same partition is also out of sync at that moment, because broker 2 is slow, its disk is struggling or it is still catching up from an earlier restart, the ISR shrinks to one. One is fewer than min.insync.replicas, so the leader rejects acks=all writes with NotEnoughReplicasException.
This is Kafka working as designed. Accepting the write with only one copy would mean an acknowledged record could be lost if that broker failed next. The exception is retriable: the condition is expected to clear when the restarted broker catches up. A close relative, NotEnoughReplicasAfterAppendException, means the leader wrote the record but the ISR shrank before enough replicas confirmed it; that one can lead to duplicates on retry, which idempotence handles.
2Why It Ends in a TimeoutException
The producer does not give up on the first retriable error. It retries, with retry.backoff.ms between attempts, and the total time it will spend on one record is bounded by delivery.timeout.ms, 120,000 ms by default. That clock starts when send() is called and covers time waiting in the batch, waiting for a response and all retries. If the ISR is still too small when the two minutes are up, the producer fails the record with a TimeoutException whose message says it expired after the delivery timeout.
There is a second kind of TimeoutException in the same situation. If the producer cannot get metadata for the partition, for example while leadership is moving, send() itself can block for up to max.block.ms, 60 seconds by default, and then throw a TimeoutException about the topic not being present in metadata. Reading the message tells us which one we have.
7 messages in order. Play them, or step through them one at a time.
The record never got in; the producer gave up after two minutes of retries.
3How the Service Should React
In Spring Kafka, KafkaTemplate.send() returns a CompletableFuture<SendResult>. The worst reaction is no reaction: if nobody looks at the future, the failure is logged by the client at best and the event is silently lost. The service must decide, per kind of event, what a failed send means.
There are three reasonable reactions. If the request is still in progress, we can fail it and return an error such as HTTP 503, so the caller retries and nothing is half done. If the event must be delivered but the request can succeed, we store the event, for example in a pending table, and a background job re-sends it. The strongest option is to avoid the problem altogether with a transactional outbox: the event is written to an outbox table in the same database transaction as the business change, and a relay publishes it with unlimited patience, so a two-minute broker problem only delays events. We can also retry at the application level a few times, but only with idempotence enabled and with a limit, so we do not pile up requests during an outage.
4Finding Why Replicas Fell Out of Sync
A single broker restart should not drop a partition below min.insync.replicas, because two other replicas should remain. If it did, a second replica was already out of sync. We check the under-replicated partitions metric (UnderReplicatedPartitions) and the ISR shrink and expand rates on each broker, and look at the brokers involved: a disk that is slow or nearly full, network saturation, long garbage collection pauses, or a follower still catching up from a previous restart.
Very often the cause is the restart procedure itself. A rolling restart must wait until the previous broker has fully rejoined, that is, until under-replicated partitions are back to zero, before restarting the next one. Restarting brokers on a fixed timer, or two at once, is a common way to produce exactly these errors. Rack or availability zone awareness, which spreads replicas of each partition across zones, makes sure one maintenance action cannot take out two replicas.
- Check under-replicated partitions = 0
- Restart one brokercontrolled shutdown moves leadership away
- Wait for it to rejoinreplicas back in the ISR
- Under-replicated partitions back to 0?YesRestart the next brokerNoWait and investigate
- Watch producer error rates throughout
5 steps in order. Play them, or step through them one at a time.
5Do Not Lower min.insync.replicas to Make Errors Go Away
It is tempting to set min.insync.replicas to 1 so writes never fail during restarts. That does make the errors disappear, but it changes the meaning of every acknowledgement: during exactly these moments, a record acknowledged by a single replica is lost if that broker fails before others copy it. If the business accepts that risk for a particular topic, it can be a deliberate decision, documented as such. As a quick fix for noisy logs, it trades a visible, recoverable problem for an invisible, unrecoverable one.
6Follow-up questions
Should we just raise delivery.timeout.ms?
Raising it can help a producer survive a slightly longer disruption, but it also means records wait longer in memory and requests block longer. Memory is bounded by buffer.memory, and once it is full, send() blocks for up to max.block.ms. A modest increase is fine; an outbox is the real answer for events that must survive long outages.
Can retries reorder or duplicate records?
With enable.idempotence=true, the default since Kafka 3.0, retries do not create duplicates or reorder records within a partition, as long as max.in.flight.requests.per.connection is 5 or less. Without idempotence, a retry after a lost response can write the record twice.
7Conclusion
In this answer, we decoded NotEnoughReplicasException as the broker refusing acks=all writes because the ISR fell below min.insync.replicas, and saw how internal retries end in a TimeoutException after delivery.timeout.ms. The service must handle the failed future by failing the request, storing the event for retry or using an outbox, and the team must find why a second replica was out of sync, often an unsafe rolling restart, rather than lowering min.insync.replicas.
Open with
NotEnoughReplicasException means the partition's in-sync replica set is smaller than min.insync.replicas, so the leader refuses acks=all writes. With replication factor 3 and min ISR 2, that means only one replica was in sync, so besides the broker we restarted, another replica must already have been lagging.
Then, if they want more
The producer treats it as retriable and keeps retrying until delivery.timeout.ms, two minutes by default, expires, and then completes the send's future with a TimeoutException. A different TimeoutException can come from send itself after max.block.ms if metadata is unavailable, and the message tells them apart. In the service, I would never ignore the CompletableFuture from KafkaTemplate.
Depending on the event, I would fail the request with a retryable error, store the event in a pending table for a background re-send, or better, write events through a transactional outbox so a broker problem only delays them. Application-level retries are fine with idempotence on and a limit.
On the broker side, I would look at under-replicated partitions and ISR shrink rates, and at disk, network and GC on the lagging broker, and check the restart procedure: the next broker should only be restarted when under-replicated partitions are back to zero.
I would not lower min.insync.replicas to one to silence the errors, because that quietly makes acknowledged writes losable.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Kafka 3.0
- 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, Spring for Apache Kafka reference
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 "During a broker restart a producer logs NotEnoughReplicasException and TimeoutException...": https://scrivio-interview-library.netlify.app/spring-boot/kafka/1121d9d835/