Kafka Streams State Recovery
State recovery combines local state, changelog topics, task assignment, and processing guarantees. Do not delete local state before establishing which recovery source is healthy.
Capture State
Section titled “Capture State”Record application ID, process ID, client ID, thread/task/store names, assigned input and changelog partitions, state directory, restore offsets/rate, thread state, rebalance history, transaction errors, and uncaught-exception response.
Check:
- state-directory mount, capacity, permissions, and I/O latency;
- changelog topic existence, retention, compaction, ISR, and authorization;
- restore-consumer fetch errors and lag;
- repeated task migration or member fencing;
- RocksDB/background errors and open-file limits;
- transaction coordinator and output topic health for exactly-once processing.
Diagnose the Pattern
Section titled “Diagnose the Pattern”| Pattern | Likely cause |
|---|---|
| Full restore every restart | Ephemeral/missing state volume, changing instance identity, state cleanup |
| Restore never catches up | Input rate, slow disk/network, insufficient instances, changelog issue |
| Same task repeatedly migrates | Group instability or process/resource failure |
| Local store corruption | Disk/filesystem/process crash or RocksDB failure |
| Transaction fencing | Duplicate instance/transactional identity or task movement |
Recover
Section titled “Recover”- Restore the state volume or fix storage capacity/latency.
- Restore changelog topic availability and authorization.
- Stabilize group membership before adding more instances.
- Quarantine a corrupt local store only after confirming the changelog can rebuild it.
- Use the Streams application reset tool only for an intentional logical reset with the application stopped and an approved data/reprocessing plan.
Danger
Deleting state.dir, changelog topics, or application offsets is not a generic restart procedure. It can force massive restore traffic, lose state, or replay side effects.
Kafka 4.4 Transactional Stores
Section titled “Kafka 4.4 Transactional Stores”Opt-in transactional state stores can roll back uncommitted changes instead of rebuilding the full store after an error. Confirm the store type and configuration before assuming this recovery behavior.
Verify
Section titled “Verify”Restore completes, tasks remain assigned, threads reach RUNNING, changelog lag reaches steady state, stores answer expected queries, transaction errors stop, and output semantics remain correct.
Prevent Recurrence
Section titled “Prevent Recurrence”Use persistent fast state volumes, monitor restore time and changelog health, size recovery capacity, preserve stable instance placement where useful, and test loss of one state directory.