0
0
KafkaConceptBeginner · 3 min read

What is min.insync.replicas in Kafka and How It Works

min.insync.replicas in Kafka is a broker configuration that sets the minimum number of replicas that must acknowledge a write for it to be considered successful. It ensures data durability by requiring a minimum number of in-sync replicas to confirm the write before the producer receives an acknowledgment.
⚙️

How It Works

Imagine you have a group of friends (replicas) who all keep copies of your important notes (data). When you write a new note, you want to make sure that at least a certain number of friends have safely stored it before you feel confident that your note is safe.

In Kafka, min.insync.replicas is like setting the minimum number of friends who must confirm they have the note before you consider the write successful. If fewer than this number confirm, Kafka will reject the write to avoid losing data if some replicas fail.

This setting works together with the producer's acks setting and the topic's replication factor to balance between data safety and write availability.

💻

Example

This example shows how to set min.insync.replicas for a Kafka topic using the Kafka command-line tool.

bash
kafka-topics.sh --alter --topic my-topic --config min.insync.replicas=2 --bootstrap-server localhost:9092
Output
Topic 'my-topic' was updated.
🎯

When to Use

Use min.insync.replicas when you want to ensure strong data durability and avoid data loss during broker failures. For example, in financial or critical logging systems, you want multiple replicas to confirm writes before accepting them.

If you set it too high, writes may fail often if replicas are down, reducing availability. If set too low, you risk losing data if a replica fails before replicating the data.

It is best used with acks=all on the producer side and a replication factor of at least 3 to balance safety and availability.

Key Points

  • min.insync.replicas defines the minimum number of replicas that must acknowledge a write.
  • It helps prevent data loss by ensuring multiple copies have the data.
  • Works with acks=all and replication factor for durability.
  • Setting it too high can reduce write availability.
  • Commonly set to 2 or more in production for safety.

Key Takeaways

min.insync.replicas ensures a minimum number of replicas confirm writes for durability.
It prevents data loss by rejecting writes if not enough replicas are in sync.
Use it with acks=all and replication factor ≥ 3 for best results.
Setting it too high can cause write failures during replica outages.
Common production value is 2 to balance safety and availability.