Kafka min.insync.replicas < replication.factor
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is an open-source stream-processing software platform developed by LinkedIn and donated to the Apache Software Foundation, written in Scala and Java. It is widely used to build real-time streaming data pipelines and applications. At its core, Kafka operates on a publish-subscribe model and deals with messages that are partitioned and replicated across multiple nodes in a cluster to ensure both scalability and fault tolerance.
Understanding Kafka’s Core Concepts: Replication and min.insync.replicas
In Kafka, data is stored in topics which are divided into partitions. These partitions are distributed over different brokers in a Kafka cluster to achieve load balancing. For fault tolerance, Kafka replicates each partition across multiple brokers. This means each partition has one leader and multiple followers. The leader handles all read and write requests for the partition, while the followers passively replicate the leader.
The durability and high availability of data in Kafka hinge on how these replicas are managed. Two important configuration settings related with replication are replication.factor and min.insync.replicas:
- replication.factor: This setting specifies the total number of copies (including the leader) that exist for each partition. For example, a replication factor of 3 means each partition has one leader and two follower replicas.
- min.insync.replicas: This tells Kafka how many of the replicas must acknowledge a write for it to be considered successful. This applies only if the producer's
ackssetting is configured to "all" (this ensures the producer gets an acknowledgment once all in-sync replicas have received the data).
Scenario: min.insync.replicas < replication.factor
When configuring a Kafka broker, setting min.insync.replicas to a value less than replication.factor implies that writes to the partition are considered successful even if not all replicas are successfully written to, as long as the number of successful writes meets the min.insync.replicas criterion. This can have various implications on system performance and data safety:
Performance Considerations
Reducing min.insync.replicas below the replication.factor can potentially increase the throughput and decrease the latency of write operations. This happens because fewer replicas need to confirm the write, which can be particularly beneficial when quick writes are more critical than data durability.
Data Safety
On the flip side, setting min.insync.replicas to a number less than the replication.factor decreases the guarantees of data durability and fault tolerance. If only a minority of replicas need to confirm writes, then the probability increases that in the event of a broker failure, the remaining in-sync replicas do not have the latest writes, leading to data loss.
Best Practices and Recommendations
In practice, configurations largely depend on specific business requirements related to performance and data integrity:
- High durability requirements: Set
min.insync.replicasequal to or just one less thanreplication.factor. This ensures that most replicas, if not all, have the data. - High performance requirements: If performance and lower latency are prioritized over durability, and some data loss can be tolerated, setting
min.insync.replicasto a value less thanreplication.factormight be acceptable.
Technical Example
Imagine a Kafka cluster configuration with replication.factor=3 and min.insync.replicas=2. This setup means that for each partition:
- There are 3 replicas.
- At least 2 of these replicas must confirm writes for the write operation to be acknowledged to the producer.
If the producer's acks is set to "all", then the producer waits until all in-sync replicas have confirmed the receipt of the data.
Summary Table
| Configuration Key | Value | Description |
replication.factor | 3 | Each partition is replicated across three brokers. |
min.insync.replicas | 2 | At least two replicas must acknowledge a write for it to be deemed successful. |
Producer acks | all | The producer will wait for acknowledgments from all in-sync replicas before considering a write successful. |
Conclusion
Configuring Kafka’s min.insync.replicas and replication.factor properly is vital for balancing between system performance and data safety. Understanding the implications of these settings helps in designing systems that meet specific operational criteria, whether prioritizing high availability, fault tolerance, or write performance. Remember, each setting must be considered within the context of your specific use case requirements and risk tolerances.
Related reading
- Kafka Mirror Maker failing to replicate __consumer_offset topic
- Kafka MirrorMaker2 - not mirroring consumer group offsets
- Kafka MirrorMaker2 automated consumer offset sync
- Kafka MirrorMaker 2.0 duplicate each messages
- kafka Multi-Datacenter with high availability
- Kafka multiple consumers for a partition
- Kafka MirrorMaker's consumer not fetching all messages from topics
- kafka Missing required configuration zookeeper.connect which has no default value

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.