Sobes.tech
Middle

What is a replication factor in Kafka and how does min.insync.replicas work?

sobes.tech AI

Answer from AI

The replication factor in Kafka is the number of copies (replicas) of each topic partition that are stored on different brokers to ensure fault tolerance and data availability. For example, if the replication factor is 3, each partition will be stored on three brokers.

The min.insync.replicas parameter defines the minimum number of replicas that must acknowledge a write (be "in-sync" with the leader) for the producer to consider the write successful when using the acknowledgment level acks=all. This guarantees that data is not only written to the leader but also to a sufficient number of replicas, increasing reliability.

If the number of available in-sync replicas is less than min.insync.replicas, then when attempting to write with acks=all, the producer will receive an error, preventing data loss during failures.

Example:

  • replication.factor = 3
  • min.insync.replicas = 2
  • Producer writes with acks=all

The write will be successful if at least 2 replicas acknowledge the write. If one replica fails and only 1 in-sync replica remains, the write will be rejected.