What are In-Sync Replicas (ISR) in Kafka?
In Apache Kafka, data isย replicated across brokers for fault tolerance.
-
Each topic partition has:
-
Leader replica โ handles all reads/writes.
-
Follower replicas โ replicate data from the leader.
-
๐ In-Sync Replicas (ISR) = the set of replicas (leader + followers) that have fully caught up with the leaderโs data.
-
If a follower is lagging too much, itโs removed from ISR.
-
Only ISR members are considered safe copies of the data.
๐น Example
Suppose you have a topic partition with replication factor = 3:
-
Broker 1 โ Leader
-
Broker 2 โ Follower
-
Broker 3 โ Follower
If all are up-to-date, ISR = {Broker 1, Broker 2, Broker 3}.
If Broker 3 falls behind (network/disk issue), ISR = {Broker 1, Broker 2}.
๐น Why ISR Matters?
-
Acknowledgements:
-
If
acks=all
โ Kafka waits for data to be written to all ISR replicas, ensuring durability. -
If a broker is out of ISR, Kafka doesnโt wait for it.
-
-
Leader Election:
-
If the leader fails, a new leader is chosen only from ISR to ensure no data loss.
-
๐น Configurations Related to ISR
-
min.insync.replicas
-
Minimum number of ISR replicas required for a write to be considered successful.
-
Prevents writes if too few replicas are in sync (avoids data loss).
-
-
acks
(producer config)-
acks=1
โ leader only. -
acks=all
โ leader + all ISR replicas. -
acks=0
โ no acknowledgement (fast but risky).
-
๐น Quick Analogy
Think of ISR like a class attendance register:
-
Leader = teacher.
-
Followers = students copying notes.
-
ISR = students who are up-to-date with the teacherโs notes.
-
If a student is far behind, teacher doesnโt rely on him for group work.
๐น In Short
In-Sync Replicas (ISR) = the set of replicas (leader + followers) that are fully caught up with the leader.
-
Used for durability, acknowledgements, and safe leader election.
-
Key configs:
acks
,min.insync.replicas
.