Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

After every deployment of a Kafka Streams service (8 pods, 64 input partitions, about 300 GB of state in total), the application stays in state REBALANCING for 40 to 50 minutes and lag on the input topics climbs to several million records. Logs show tasks restoring from changelog topics.

The pods use emptyDir volumes and default Streams settings. How do you shorten this?

emptyDir is deleted with the pod, so every deploy throws away about 37 GB of state per instance and restores it from the changelogs. We move to a StatefulSet with persistent volumes so a restarted pod replays only the changelog tail after its checkpoint, add static membership so a rolling restart does not move tasks, run one standby replica for fast failover, rely on warmup replicas when scaling, and measure and tune restoration.

Why this question is asked

A 40-minute pause on every deployment makes teams afraid to deploy, which is worse than the pause itself. The logs already tell us the cause, tasks restoring from changelogs, and the question is why the state keeps disappearing and how to make it survive. Interviewers ask this because the fix combines Kubernetes storage, consumer group membership and Streams' own assignment features. In this answer, we will work out why every deploy restores everything, then apply the fixes one at a time, each with what it costs, and finish with measuring restoration and the exactly-once wrinkle.

1Why Every Deploy Restores Everything

300 GB of state over 8 pods is about 37 GB per pod. Each pod keeps that state in RocksDB under state.dir, and here state.dir sits on an emptyDir volume. An emptyDir lives exactly as long as the pod; a rolling deploy replaces every pod, so every new pod starts with an empty directory and must read its whole share from the changelog topics. At, say, 20 to 40 MB per second of effective restore speed, 37 GB takes 15 to 30 minutes per pod, and with tasks moving around during the roll the application stays in REBALANCING for 40 to 50 minutes while lag climbs.

A second effect makes it worse. With default settings, each pod that stops leaves the group, its tasks move to other pods, which have no state for them either, and then move back when the new pod joins. Some state is restored twice.

2Fix 1: Keep the State Across Restarts

The biggest win is to keep the RocksDB files. A StatefulSet gives each pod a stable name (streams-0 to streams-7) and its own PersistentVolumeClaim that is reattached when the pod is replaced. We mount the volume and point state.dir at it.

YAML
# StatefulSet (excerpt)
volumeClaimTemplates:
- metadata: { name: state }
spec: { accessModes: [ReadWriteOnce], resources: { requests: { storage: 80Gi } } }
containers:
- name: app
volumeMounts: [ { name: state, mountPath: /var/lib/kafka-streams } ]
# application.yml
spring.kafka.streams.state-dir: /var/lib/kafka-streams

Now a restarted pod finds its stores and their .checkpoint files and replays only what was written to the changelogs while it was down, typically seconds or a few minutes of data instead of 37 GB.

3Fix 2: Static Membership for Rolling Restarts

Persistent state only helps if the restarted pod gets its own tasks back. With static membership, each instance has a fixed identity, group.instance.id, and when it stops briefly the group does not rebalance; it waits up to the session timeout for the same member to return. We derive the id from the pod name and set the session timeout longer than a normal restart, for example 2 minutes when a restart takes about 60 seconds.

Java
spring:
kafka:
streams:
properties:
group.instance.id: ${POD_NAME} # streams-3; Streams adds a suffix per thread
session.timeout.ms: 120000

The trade-off is that a pod that really dies is noticed only after the session timeout, so its partitions wait up to 2 minutes. Standby replicas reduce what happens next.

4Fix 3: Standby Replicas and Warmup Replicas

num.standby.replicas=1 tells Streams to keep a passive copy of every store on another instance, updated continuously from the changelog. If a pod is lost for good, its tasks move to the instances holding standbys, which only need to catch up a small lag. The cost is doubled state disk, about 75 GB per pod instead of 37, and twice the changelog read traffic.

Since Kafka 2.6 the Streams assignor also avoids stalls when instances are added. It keeps active tasks on instances that are caught up, and builds state for a new instance through warmup replicas in the background, moving the active task only once the warmup is within acceptable.recovery.lag (10,000 records by default). max.warmup.replicas limits how many warm up at once, and probing.rebalance.interval.ms sets how often the assignor checks whether warmups are ready. So scaling out from 8 to 10 pods no longer stalls processing while the new pods fill up.

What each fix changes
FixEffect on a deployCost
Persistent volumes (StatefulSet)Replay only the tail after the checkpointVolumes to manage
Static membershipNo task movement during a rolling restartSlower detection of a dead pod
num.standby.replicas=1Fast failover when a pod is lost2x state disk, more changelog reads
Warmup replicas (default since 2.6)Scale-out without stallsBackground restore traffic

5Measuring and Tuning Restoration

We measure before and after. A StateRestoreListener registered on KafkaStreams logs when each store starts restoring, how many records it has restored and when it ends, and the restore metrics show the rate. With those numbers we can see whether restoration is limited by the network, by RocksDB writes or by the restore consumer.

The restore consumer has its own settings, prefixed with restore.consumer., such as restore.consumer.max.poll.records; raising it from the default can speed restoration noticeably. We also confirm that the changelog topics are compacted, so a restore reads one value per key rather than every update ever made.

Step throughMaking deploys fast
  1. Measure restore time per storeStateRestoreListener, restore metrics
  2. State on emptyDir?
    YesMove to StatefulSet volumesNoKeep
  3. Tasks move during rolling restarts?
    YesStatic membershipNoKeep
  4. Need fast failover on pod loss?
    Yesnum.standby.replicas=1NoAccept restore on loss
  5. Tune restore consumer, check compaction

5 steps in order. Play them, or step through them one at a time.

6Follow-up questions

Why can exactly-once processing force a full restore after a crash?

With exactly-once, the local RocksDB store may contain writes from a transaction that was never committed when the process crashed. Streams cannot tell which writes those are, so when no clean checkpoint exists it wipes the local store and restores it fully from the changelog, which contains only committed data. A clean shutdown writes a checkpoint and avoids this; a crash does not. Work on transactional state stores (KIP-892) aims to remove this limitation, so check your version.

Does the new Streams rebalance protocol change this advice?

Recent Kafka versions are introducing a broker-side rebalance protocol for Streams, which can make rebalances faster and smoother. Persistent state and standbys remain essential, because no protocol can avoid reading 37 GB that was deleted.

How large should the persistent volumes be?

Active plus standby state with room for RocksDB compaction, which temporarily needs extra space. For about 37 GB active and 37 GB standby, 100 GB or more per pod is a sensible start, adjusted from measured usage.

7Conclusion

In this answer, we saw that emptyDir volumes forced every restarted pod to restore about 37 GB from the changelogs. We moved state to StatefulSet persistent volumes so a restart replays only the tail, used static membership so rolling restarts do not move tasks, added a standby replica for fast failover at the cost of double disk, relied on warmup replicas for scale-out, and measured restoration with a listener to tune the restore consumer and confirm compaction.

What to say in the interviewAbout 80 seconds aloud

Open with

The root cause is emptyDir: it is deleted with the pod, so on every deploy each instance loses its share, about 37 GB, and has to restore it from the changelog topics, and with default membership the tasks also move to other pods that have no state either.

Then, if they want more

First, I would run the app as a StatefulSet with a persistent volume per pod and point state.dir at it, so a restarted pod finds its RocksDB files and checkpoint and only replays the changelog tail.

Second, static membership: group.instance.id set from the pod name and a session timeout longer than a restart, so a rolling restart does not trigger task movement. Third, num.standby.replicas=1, so if a pod is lost for good another instance has a warm copy and takes over after a small catch-up, at the cost of double state disk and more changelog reads.

Since Kafka 2.6 the assignor also uses warmup replicas, keeping active tasks on caught-up instances and building state on new ones in the background, so scaling out does not stall. Finally I would measure restoration with a StateRestoreListener and the restore metrics, tune the restore consumer, for example max.poll.records, and check the changelogs are compacted.

About this answer

Last updated
13 November 2026
Versions it names
Kafka 2.6
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Apache Kafka documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "The pods use emptyDir volumes and default Streams settings. How do you shorten this?": https://scrivio-interview-library.netlify.app/spring-boot/kafka-streams-connect/eabf68c955/