---
title: "Kafka unclean.leader.election.enable: offline or data loss"
description: "The whole ISR is dead and unclean election is off, so the Kafka partition stays offline. Turn the flag on and a stale replica leads, losing 3 committed records."
url: https://monedula.dev/kafka-simulator/scenarios/unclean-leader/
---

# Kafka unclean.leader.election.enable: offline or data loss

Scenario 03.2.3 · Unclean leader. Replication · Advanced · about 3 min · Apache Kafka 4.3.

A stale survivor is promoted with data loss when unclean.leader.election.enable is flipped on.

Run it: https://monedula.dev/kafka-simulator/playground/?scenario=03.2.3

## What you start with

With unclean.leader.election.enable=false, a partition whose entire ISR is dead stays offline rather than promote a stale replica. Here both in-sync brokers are killed after a follower has been throttled out of date, then the unclean flag is flipped on.

## Step by step

1. **Cluster ready - RF 3, min.ISR 2** (t+0.000s): orders has 3 in-sync replicas. unclean.leader.election.enable is OFF: Kafka prefers durability over availability. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=03.2.3&t=0)
2. **2 records committed on all three** (t+4.100s): High-watermark is 2 - broker-3 holds both records. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=03.2.3&t=1)
3. **broker-3 throttled out of ISR - stale survivor** (t+12.100s): broker-3 is stuck at LEO 2 while the leader committed up to 5; it has fallen out of ISR but is still alive. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=03.2.3&t=2)
4. **broker-1 killed - broker-2 leads (clean election)** (t+16.600s): broker-2 is the only in-sync replica left, so it is elected cleanly with no data loss. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=03.2.3&t=3)
5. **broker-2 killed - partition OFFLINE** (t+21.000s): ISR is empty. With unclean election disabled, Kafka refuses to promote the stale broker-3: durable, but unavailable. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=03.2.3&t=4)
6. **Unclean election enabled - broker-3 leads, records lost** (t+25.000s): broker-3 (LEO 2) is promoted unclean. The high-watermark drops from 5 to 2 - 3 committed records are gone. Availability restored at the cost of durability. (The simulator elects at once; in KRaft a dynamically enabled flag waits for the periodic check, 5 min by default, unless you run kafka-leader-election.sh with the unclean option.) [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=03.2.3&t=5)

## The takeaway

Flipping unclean.leader.election.enable on promotes the stale survivor and brings the partition back online, but at the cost of losing every record it never received - availability bought with data loss. (In real KRaft the election is not instant: a dynamically enabled flag waits for the controller's periodic check, 5 min by default, unless kafka-leader-election.sh runs an unclean election.)

## Configs in this scenario

- [`unclean.leader.election.enable`](https://kafka.apache.org/43/configuration/topic-configs/#topicconfigs_unclean.leader.election.enable): Lets a replica that is not in the ISR become leader when no in-sync replica is left, which brings the partition back online but loses the writes that replica never received (default false). [How unclean.leader.election.enable works](https://monedula.dev/kafka-simulator/configs/unclean-leader-election-enable/)

## Further reading

- [Apache Kafka documentation](https://kafka.apache.org/43/configuration/topic-configs/#topicconfigs_unclean.leader.election.enable)

## Troubleshooting

- [Kafka offline partitions with no leader: causes and fixes](https://monedula.dev/kafka-simulator/troubleshooting/offline-partitions-no-leader/)
