๐ŸŽ‰ 75% of content is free forever โ€” Unlock Premium from $10/mo โ†’
CW
NEWSLIVESearch All Content
๐Ÿ’ผ Servicesโ„น๏ธ Aboutโœ‰๏ธ ContactView Pricing Plansfrom $10

Kafka Replication and ISR: The Failure-Mode Guide

Apache KafkaReplicationโญ Premium

Kafka Replication and ISR: The Failure-Mode Guide

Senior level ยท Why a copy on three disks still loses data, and the two settings that stop it.

Prerequisites

  • !Kafka partitions, leaders and followers
  • !Producer acknowledgement basics

What You'll Learn

  • 1Describe what the in-sync replica set tracks and how a follower joins and leaves it
  • 2Pair acks with min.insync.replicas to state a durability guarantee you can defend
  • 3Read replica health from the command line and JMX before users notice
  • 4Argue for or against unclean leader election on a real topic

Where durability actually comes from

When a producer reports that a message was accepted, the broker has to mean something specific by that. Replication is the mechanism: every partition has exactly one leader that serves all reads and writes, plus followers that maintain identical copies. The default replication factor is one, so a stock Kafka install gives you nothing beyond a single disk. Production topics are normally created with a factor of three, which lets a partition survive two simultaneous broker failures before its data becomes unreachable.

Copies alone are not protection, though. A follower that is copying slowly still holds bytes on disk, but you cannot count on it if it has fallen behind by minutes. What makes replication work is the agreement protocol that decides when a copy is allowed to count toward your guarantee. The gap between holding data and holding data in time is the whole subject of this lesson, and it is exactly where interviewers push.

What the in-sync replica set really measures

The in-sync replica set, or ISR, is the group of replicas considered caught up with the leader. A follower falls out of the ISR when it stops sending fetch requests for longer than replica.lag.time.max.ms, which defaults to ten seconds, and it rejoins as soon as it catches back up to the leader's log end offset.

The detail worth remembering is that the check is purely time-based. Earlier Kafka releases also evicted followers whose record-count lag exceeded a fixed threshold, but that rule punished large batches unfairly and was dropped. A follower steadily pulling a slow megabyte per second stays in the ISR; a follower that stalls for eleven seconds leaves, even if it was only one record behind when the stall began.

Two offsets matter when you reason about failure. The log end offset is the last record a broker has appended locally. The high-watermark is the last offset replicated to every member of the ISR, and it is the point consumers are allowed to read to. Records past the high-watermark exist but are invisible, which is why ISR membership rather than raw replica count is what protects your readers.

The acks and min.insync.replicas contract

Two settings combine to define durability, and neither means much alone. The producer's acks controls how many acknowledgements it waits for. The broker's min.insync.replicas controls how far the ISR may shrink before the broker starts rejecting writes.

With acks=all and min.insync.replicas=2 on a replication factor of three topic, a write succeeds once the leader and at least one follower have persisted it. If a broker dies and the ISR drops to one, the broker refuses the write and the producer sees NotEnoughReplicasException. That failure is the system working: it is telling you the number of acknowledged copies you asked for no longer exists.

Lower min.insync.replicas to one and writes always succeed, but then a single broker holds the only acknowledged copy for as long as the ISR sits at one. Think of replication factor as the ceiling of copies you can ever hold and min.insync.replicas as the floor you refuse to write below. Everything interesting happens in the space between those two numbers.

Choosing an acks level for a workload

SettingWaits forWhat it survivesWhere it belongs
acks=0NothingNothingSkippable metrics and heartbeats
acks=1Leader onlyFollower loss before the ackClickstreams and logs where a gap costs nothing
acks=allLeader and every ISR memberUp to replication factor minus min.insync failuresPayments, orders, ledger and state events
acks=all plus idempotenceSame as all, plus deduplicationRetries without duplicatesAnything that also needs ordering

acks=1 is a defensible default for telemetry because a lost event does not change business outcomes. For money or state, acks=all with min.insync.replicas set to two is the smallest configuration that can honestly claim durability, and the price is real: every write now waits for a second disk on a different machine. Teams that need both usually split topics rather than compromise one topic's guarantee.

When the ISR shrinks: four scenarios you will actually see

A broker crash removes its replicas from every ISR immediately, and recovery begins the moment the broker returns and resumes fetching. A long garbage collection pause looks identical from the leader's point of view, because no fetch requests arrive while the JVM is stopped; if the pause exceeds replica.lag.time.max.ms, the replica is evicted and then quietly re-admitted seconds later.

A network partition isolates one follower while everything else looks healthy, so the ISR drops and the partition becomes temporarily less durable than its configured factor suggests. The nastiest case is a slow disk: fetch requests still arrive, but the follower's append latency keeps it from advancing, so the leader sees churn rather than an outage. ISR shrink rate is therefore a better early-warning signal than broker up or down checks.

โš ๏ธThe floor you forgot to set

A replication factor of three with min.insync.replicas left at the default of one will accept writes with a single acknowledged copy. You have three disks and a one-disk guarantee. Always set the floor explicitly on topics where loss matters.

Unclean leader election, in plain terms

If every replica currently in the ISR fails, the partition has no eligible leader and becomes unavailable until a replica returns. The alternative is unclean.leader.election.enable=true, which lets an out-of-sync replica take over. Availability is restored instantly, but whatever records the new leader was missing are permanently gone, and consumers that already read those offsets have seen data that the log no longer contains.

Leave the setting off, which is the default, for any topic where losing events is unacceptable. Turn it on only for topics where a total outage is worse than a gap, such as coarse operational metrics. The trade is never subtle: you are choosing between no answers and slightly wrong answers.

Inspecting replica health before it becomes an incident

# Per-partition leader, ISR and replica assignment
kafka-topics.sh --bootstrap-server kafka1:9092 \
  --describe --topic orders --under-replicated-partitions

# Force a reassignment check after a broker restart
kafka-reassign-partitions.sh --bootstrap-server kafka1:9092 \
  --topics-to-move-json-file move.json --broker-ids "1,2,3" --generate

# Watch ISR membership settle rather than guessing
kafka-log-dirs.sh --bootstrap-server kafka1:9092 \
  --describe --broker-list 1 --topic orders

Run the under-replicated query on a schedule rather than during an incident. A partition that stays under-replicated for more than a few minutes after a broker returns usually means the follower cannot keep up with catch-up fetch throughput, and the fix is capacity or replica.fetch.max.bytes rather than a restart.

A producer configuration you can defend in review

Properties props = new Properties();
props.put("bootstrap.servers", "kafka1:9092,kafka2:9092,kafka3:9092");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");

// Durability: wait for the leader and at least one follower
props.put("acks", "all");
props.put("enable.idempotence", true);
props.put("retries", Integer.MAX_VALUE);
// Safe with idempotence, and required to preserve ordering on retry
props.put("max.in.flight.requests.per.connection", 5);

KafkaProducer<String, String> producer = new KafkaProducer<>(props);
producer.send(new ProducerRecord<>("orders", "order-123", payload),
    (metadata, error) -> {
        if (error != null) {
            // NotEnoughReplicas means the ISR floor was hit, not a network blip
            log.error("write rejected by ISR floor", error);
        }
    });

Pair it with the broker side so the guarantee exists on both ends:

# server.properties, applied per topic at creation time
min.insync.replicas=2
unclean.leader.election.enable=false
replica.lag.time.max.ms=10000
default.replication.factor=3

The producer can ask for acks=all all day, but without min.insync.replicas on the topic the broker is free to acknowledge with one copy. Configuring only one half of the pair is the most common production gap found in cluster reviews.

Common Mistakes

Setting replication factor to three and never touching min.insync.replicas

Fix: Set min.insync.replicas to two on durable topics so the ISR floor matches the promise you make to stakeholders.

Treating NotEnoughReplicasException as a transient error and retrying blindly

Fix: Alert on it instead. It means the partition is under-replicated, and retrying hides the durability problem until data is written somewhere weaker.

Enabling unclean leader election everywhere to avoid partition outages

Fix: Enable it topic by topic. For anything financial, an unavailable partition you can explain beats a silently truncated one you cannot.

Judging replica health only by whether brokers are up

Fix: Chart ISR size and under-replicated partition count; a healthy broker list with a shrinking ISR is the earlier and more dangerous signal.

Best Practices

  • Create durable topics with an explicit replication factor and min.insync.replicas in the same command, so the ceiling and the floor are reviewed together
  • Alert when ISR size drops below the configured floor or when a partition stays under-replicated past one replication interval
  • Keep replica.lag.time.max.ms long enough to absorb normal GC pauses but short enough that a real stall surfaces within your incident window
  • Split latency-sensitive telemetry onto acks=1 topics instead of weakening a topic that carries money

Interview Questions

Q1: acks=all and replication factor three, but min.insync.replicas is left at one. How durable is a write?

Not durable. The broker only requires the leader to acknowledge, so a write can be acknowledged by a single copy while two followers lag. You survive follower loss but not leader loss after the ack, which is weaker than it appears from the configuration.

Q2: Why is ISR eviction time-based rather than count-based?

A record-count threshold punishes large batches and high-throughput partitions unfairly, evicting followers that are keeping up. Time since the last fetch is a direct signal of follower health and behaves consistently across workloads.

Q3: A partition has lost its leader and no replica is in the ISR. What are your two options and when do you take each?

Wait for an ISR replica to recover, leaving the partition unavailable, or enable unclean leader election and accept permanent data loss. Wait for financial and stateful topics; elect uncleanly only for metrics where a gap is cheaper than an outage.

Q4: How does the high-watermark relate to consumer visibility?

Consumers may only read up to the high-watermark, which is the offset replicated to every ISR member. Records beyond it are written but not yet protected, so a leader failure before they are replicated discards them without consumers ever having seen them.

Q5: What does a sustained ISR shrink rate of a few events per minute tell you?

Something is periodically stalling fetch delivery, most often GC pauses, disk latency or network micro-partitions. It is an early warning that durability headroom is eroding before any under-replicated alert fires.

Key Takeaways

  • Replication factor is the ceiling of copies; min.insync.replicas is the floor you refuse to write below
  • The ISR is defined by fetch recency, not record count, so a slow-but-alive follower stays in and a stalled one leaves after replica.lag.time.max.ms
  • acks=all only means as much as min.insync.replicas allows, so configure both or you have a one-disk guarantee on three disks
  • The high-watermark, not the log end offset, is what consumers can read, which is why ISR membership governs visible data
  • Unclean leader election trades permanent data loss for instant availability and should be a per-topic decision
๐Ÿ”’

Premium Content

Kafka Replication and ISR: The Failure-Mode Guide

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

๐ŸŽฏEnd-to-end Projects
๐Ÿ’ผInterview Prep
๐Ÿ“œCertificates
๐ŸคCommunity Access

Already a member? Log in

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-13

โ€”
โ˜†โ˜†โ˜†โ˜†โ˜†
0 ratings

Rate & Feedback

Advertisement