---
title: "KafScale 2.1 diskless Kafka: a lease owner crashes"
description: "KafScale 2.1: a fetch needs the etcd lease too, so a crashed owner's partition takes no writes or reads for the 10 s TTL; a graceful stop hands over."
url: https://monedula.dev/kafka-simulator/scenarios/kafscale-2-broker-crash/
---

# KafScale 2.1 diskless Kafka: a lease owner crashes

Scenario 08.2.1 · KafScale: a lease owner crashes. Diskless · Advanced · about 4 min · Apache Kafka 4.4 · KafScale 2.1.

KafScale 2.1 · a hard-killed owner keeps its etcd lease for the 10 s TTL, and since a fetch needs the lease too, its partition takes no writes and no reads until another broker takes over; a graceful stop hands over at once.

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

## What you start with

In KafScale each partition has one owner broker, which holds a lease for it in etcd with a TTL of 10 s. A fetch needs the lease too, so the broker that serves a read must own the partition, and a graceful stop releases its leases before it lets requests in flight finish. Partition orders-0 is owned by broker-2 and orders-1 by broker-3. broker-2 will be killed without warning, and later broker-3 will be stopped gracefully. Producer p1 is set to retries=30 and retry.backoff.ms=500, about 15 s of retries with the simulator's fixed backoff. Watch the lease lane for etcd, p1's and c1's errors and the partition strips.

## Step by step

1. **Two partitions, two owners** (t+1.100s): orders is a KafScale topic (KafScale 2.1) with two partitions, one replica each, every byte in S3. p1's first two records (keys A and D) made broker-2 take orders-0's lease in etcd and broker-3 take orders-1's (the simulator's hash picks them). Both were acked at 790 ms and consumer c1 of g1 read them at 1000 ms. p1 is set to retries=30 and retry.backoff.ms=500: about 15 s of retries with the simulator's fixed backoff. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.1&t=0)
2. **Owner of orders-0 crashes: lease orphaned** (t+1.500s): broker-2 was killed without warning at 1500 ms, with nothing in flight: both records had been acked. Its lease on orders-0 is orphaned: it stays in etcd until KafScale's lease TTL of 10 s runs out, at 11500 ms, and the lease lane counts it down. Until then no other broker may write orders-0, and in KafScale no other broker may serve its reads either. The metadata still names broker-2, the lease holder, as the partition's leader. broker-3 still holds orders-1. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.1&t=1)
3. **orders-0 refuses writes and reads** (t+3.100s): p1 sent order-3 (orders-0) and order-4 (orders-1) at 2000 ms. order-4 went to broker-3, its owner, was acked at 2690 ms and read by c1 at 3000 ms. order-3 reached a broker that does not hold the lease and was refused with NOT_LEADER_OR_FOLLOWER, a retriable error, at 2050, 2550 and 3050 ms. c1's fetches of orders-0 at 2000 and 3000 ms got the same error: in KafScale a fetch needs the lease, as a produce does. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.1&t=2)
4. **Lease expires, the next request takes over** (t+11.600s): From 2000 to 11050 ms orders-0 refused 19 produce attempts and 10 fetches. At 11500 ms, 10 s after the kill, the orphaned lease expired. The first request for orders-0 after that was p1's retry at 11550 ms, before c1's next fetch at 12000 ms. It went to broker-1 (the simulator's hash over the alive brokers), which took the lease and restored orders-0: etcd's end offset is 1 and S3's is 1, so numbering goes on from 1. broker-1 gave order-3 offset 1 and is uploading it. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.1&t=3)
5. **The retried record is acked and read** (t+13.100s): The upload ended, broker-1 wrote the end offset 2 to etcd, and order-3 was acked at 12190 ms, about 10.2 s after p1 first sent it. c1 read it at 13000 ms through broker-1, the new owner. Nothing was written twice: broker-2 died with no request in flight. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.1&t=4)
6. **A graceful stop releases its lease first** (t+17.100s): order-5 (orders-1) was acked by broker-3 at 14690 ms and read by c1 at 15000 ms. broker-3 was stopped gracefully at 15000 ms with nothing in flight, and released orders-1's lease at once: in KafScale a graceful stop releases its leases first. order-6, sent at 15500 ms, went to broker-1, which took the lease at 15550 ms without waiting for any TTL, restored (end offset 3) and was acked at 16190 ms; c1 read it at 17000 ms. All six records are acked and read once; the high watermarks are 2 and 4. 08.2.6 stops an owner while a write is in flight. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.1&t=5)

## The takeaway

A hard-killed owner kept its partition for the lease TTL. For 10 s orders-0 took no writes and no reads: p1 and c1 were both refused with NOT_LEADER_OR_FOLLOWER, because in KafScale a fetch needs the lease as a produce does. orders-1 kept being acked and read. Once etcd deleted the expired lease, the first request for orders-0, p1's retry, made broker-1 take the lease and restore the partition, and the record was acked and read. The graceful stop released its lease at once, so orders-1 moved without waiting. All six records were acked and read once. Simulator choices: a restore takes no extra time, the broker that takes over comes from the simulator's hash, and p1's retry settings are chosen to outlast the 10 s TTL.

## Configs in this scenario

- [`retries`](https://kafka.apache.org/44/configuration/producer-configs/#producerconfigs_retries): How many times the producer sends a batch again after a transient error (default 2147483647, so in practice delivery.timeout.ms ends the retrying); idempotence needs it above 0.
- [`retry.backoff.ms`](https://kafka.apache.org/44/configuration/producer-configs/#producerconfigs_retry.backoff.ms): How long the producer waits before retrying a failed send, so it does not hammer a broker that is still recovering.

## Further reading

- [KafScale v2.1.0 source on GitHub](https://github.com/KafScale/platform/blob/v2.1.0/pkg/metadata/lease_manager.go)

## Troubleshooting

- [NOT_LEADER_OR_FOLLOWER in Kafka: causes and fixes](https://monedula.dev/kafka/troubleshooting/not-leader-or-follower/)
