---
title: "KafScale 2.1 proxy: etcd down past the 60 s cache TTL"
description: "KafScale 2.1: the Kafka proxy routes from its cache for 60 s after etcd stops, then goes not ready and answers REQUEST_TIMED_OUT itself."
url: https://monedula.dev/kafka-simulator/scenarios/kafscale-2-proxy-cache-expiry/
---

# KafScale 2.1 proxy: etcd down past the 60 s cache TTL

Scenario 08.2.4 · KafScale: etcd down longer than the proxy cache. Diskless · Advanced · about 4 min · Apache Kafka 4.4 · KafScale 2.1.

KafScale 2.1 · the proxy routes from its cache for 60 s after etcd stops, then goes not ready and answers every request REQUEST_TIMED_OUT itself; etcd back, it is ready at once.

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

## What you start with

Kafka clients connect to KafScale through its proxy, which reads the brokers and partition routes from etcd. The proxy keeps routing from its cache while etcd is down, but only while the cache is fresh: KAFSCALE_PROXY_BACKEND_CACHE_TTL_SEC, 60 s by default. After that the proxy is not ready: it answers each client request with REQUEST_TIMED_OUT itself, closes that connection, and its /readyz check returns 503. Here etcd stops and stays down for 64.5 s, long enough for broker-2, the partition's owner, to lose its etcd session too. Producer p1 is set to retries=30 and retry.backoff.ms=1000. Watch the proxy node and its countdown, etcd on the lease lane, and p1's and c1's errors.

## Step by step

1. **Before the outage** (t+5.500s): orders is a KafScale topic (KafScale 2.1) with one partition, owned by broker-2. order-1 was acked at 790 ms and consumer c1 of g1 read it at 5000 ms (it polls every 5 s). The proxy that clients connect to is ready: it reads the brokers and partition routes from etcd. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.4&t=0)
2. **etcd stops: the proxy counts down** (t+6.100s): etcd stopped at 6000 ms. The proxy keeps routing from its cache while the cache is fresh, 60 s by default (KAFSCALE_PROXY_BACKEND_CACHE_TTL_SEC): it will go not ready at 66000 ms, and the proxy node counts down. The brokers need etcd for produce, offset commits and fetches: even broker-2, the owner, which has orders-0 loaded, reads the end offset from etcd for each fetch, so c1's fetches will get REQUEST_TIMED_OUT (#342, fixed by #352). broker-2's keepalives to etcd now fail. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.4&t=1)
3. **broker-2's etcd session ends** (t+20.100s): At 16000 ms, one lease TTL (10 s) into the outage, broker-2's etcd client gave up on its keepalives and ended the session. KafScale then drops the log of every partition it owned: broker-2 owns nothing now. The lease key stays in etcd, which is down, so the proxy still routes orders-0 to broker-2. At c1's poll at 20000 ms the offset commit and the fetch got REQUEST_TIMED_OUT, as at every poll since etcd stopped; to load orders-0 again broker-2 now also needs a new etcd session. In KafScale a request waits for etcd until the client's request.timeout.ms runs out; the simulator answers at once. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.4&t=2)
4. **The brokers refuse, the proxy still routes** (t+60.100s): c1's offset commit and fetch got REQUEST_TIMED_OUT from the brokers at every poll from 10000 ms. p1 sent order-2 at 60000 ms; broker-2 refused it with REQUEST_TIMED_OUT at 60050 ms and p1 retries every second. The proxy still routes these requests from its cache, 5.9 s before its TTL runs out. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.4&t=3)
5. **The proxy goes not ready** (t+66.100s): At 66000 ms, 60 s after etcd stopped, the proxy's cache went stale and the proxy went not ready: its /readyz check returns 503. It now answers every client request with REQUEST_TIMED_OUT itself, without reaching a broker, and closes that client's connection. p1's retries from 61050 to 65050 ms were refused by broker-2; from 66050 ms the proxy refuses them. To p1 the error is the same. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.4&t=4)
6. **etcd is back: the proxy is ready at once** (t+70.600s): The proxy refused p1 at 66050, 67050, 68050, 69050 and 70050 ms, and c1's poll at 70000 ms. etcd started at 70500 ms, and the proxy was ready again at once: its next request reads etcd. etcd's leader renewed every lease for one TTL, so the orders-0 key, still naming broker-2, now expires at 80500 ms unless broker-2 takes it back: its old session is gone and keeps nothing alive. Nothing was written during the outage. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.4&t=5)
7. **Traffic resumes** (t+75.100s): p1's retry at 71050 ms went through the proxy to broker-2, which the key in etcd still names. broker-2 took the lease back under a new etcd session, restored orders-0 from etcd and S3 (both at 1) and wrote order-2 at offset 1; it was uploaded, committed in etcd and acked at 71690 ms, 11.7 s after p1 first sent it. c1 committed order-1's offset and read order-2 at 75000 ms. Both records were acked once; nothing was lost. [Open at this step](https://monedula.dev/kafka-simulator/playground/?scenario=08.2.4&t=6)

## The takeaway

For the first 60 s of the outage the proxy routed from its cache and the brokers answered: REQUEST_TIMED_OUT for p1's produce and c1's offset commits, because they need etcd. c1's fetches went to broker-2, the owner, which had the partition loaded but cannot read its end offset without etcd, so they got REQUEST_TIMED_OUT too. 10 s in, broker-2's etcd session ended and it dropped its partition log. When the cache went stale, the proxy went not ready and answered every request itself with REQUEST_TIMED_OUT, closing the client connection each time, so p1 sees the same error either way; /readyz returning 503 is what tells the two apart. etcd came back and the proxy was ready again at once. etcd also renewed broker-2's old lease for one TTL, kept alive by nobody; p1's next retry reached broker-2, which took the lease back under a new etcd session, restored the partition from etcd and S3, and was acked, and c1 read the record. Nothing was lost. Simulator choices: the proxy's 60 s count from the moment etcd stopped (KafScale refreshes its cache every 10 s, so the real grace is between 50 and 60 s); a fetch answers REQUEST_TIMED_OUT at once, where KafScale answers once its 3 s etcd read times out; broker-2's session ends exactly 10 s after etcd stopped (KafScale's etcd client gives up between about 6.7 and 11 s); the closed connection is only marked on the client's error (the simulator's clients have no connection state); and p1's backoff is fixed at 1 s.

## 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.
- [`request.timeout.ms`](https://kafka.apache.org/44/configuration/producer-configs/#producerconfigs_request.timeout.ms): How long the client waits for the response to one request before it sends it again or fails it (default 30000, 30 seconds); for a producer it should stay above the broker replica.lag.time.max.ms to avoid retries that write duplicates.

## Further reading

- [KafScale v2.1.0 source on GitHub](https://github.com/KafScale/platform/blob/v2.1.0/cmd/proxy/main.go#L781-L793)

## Troubleshooting

- [TimeoutException in Kafka producers: causes and fixes](https://monedula.dev/kafka/troubleshooting/producer-timeout-exception/)
