Unclean leader election enable - srivalligade04/ConfluentExamPreparationNotes GitHub Wiki

In Apache Kafka, the setting unclean.leader.election.enable (often written as unclean.leader.election.enable=true/false) controls whether an "unclean" broker can be elected as the leader of a partition when no in-sync replicas (ISRs) are available.

What does "unclean" mean?

An unclean leader is a broker that does not have the latest data for a partition (i.e., it's not in the ISR list). Electing it as leader can lead to data loss, because it may not have the most recent messages.

unclean.leader.election.enable=true

  • Kafka allows an out-of-sync replica to become the leader if no in-sync replicas are available.
  • This prevents downtime (availability is prioritized).
  • But it risks data loss, since the new leader might not have the latest messages.

unclean.leader.election.enable=false

  • Kafka does not allow an out-of-sync replica to become the leader.
  • This prevents data loss (durability is prioritized).
  • But it can cause partition unavailability until an in-sync replica comes back.

When to use which?

  • Use true if availability is more important than data durability (e.g., real-time systems where uptime is critical).
  • Use false if data integrity is more important than uptime (e.g., financial systems).