A Confluent ksqlDB query falls behind while the source topic is healthy
The scenario
A persistent ksqlDB query on Confluent Cloud reads a healthy source topic. The query's own consumer lag grows. Its committed offset is still moving, just slower than the source. Downstream rows miss their time budget. The source producers are inside their window. Restarting the query has been suggested so it can 'catch up'.
Model answer
What I'd say first:
I would not restart the query. It is behind because it is slow, not stuck. Consumer lag here is the gap between the source and the last row the query finished. The bookmark is still moving. The source topic is healthy.
How I'd work it:
- 1Leave the query running. A restart restores state from the changelog and falls further behind.
- 2Confirm the query bookmark advances on every partition, one ordered slice of the input. If one slice is almost all of the lag, a single key is hot.
- 3If every slice is behind together, add streaming units, the capacity for the query, so the work can run more in parallel. If one key owns a slice, change that key. More units will not split it.
- 4Tell the room the source is on time and the query is the bottleneck. The query owner stays until its lag is back inside the downstream budget.
How I'd explain it:
A persistent query is a consumer with its own group. Moving bookmarks mean the query is working, just not fast enough. A stuck bookmark would be a row it cannot pass. A wrong answer is a restart or more cluster brokers. The brokers are not the slow part, and a restart spends its time rebuilding state.
How I'd prevent it:
Per-partition lag on the query group, with a page when the bookmark moves too slowly. A check that a group-by key can spread. A load test that adds streaming units only when lag is even.
The follow-up they'll ask
“Restart the Confluent ksqlDB query and add brokers so it catches the source?”
No. I would not restart the query, and I would not add brokers on the source cluster. The source is inside its window. The query bookmark is moving, so this is slow, not stuck, and a restart spends time restoring state before it reads anything new. I look per partition. Even lag gets more streaming units. One hot key gets a new key, because more units cannot split a single slice. The downstream budget is the line that matters.
Common mistakes
- Restart the query to catch up
- Add source brokers for a slow query
- Add streaming units for a single hot key
- Treat a moving bookmark as a stuck consumer