Recover a Structured Streaming query
Choose source, sink, output mode and checkpoint based on the delivery contract.
Recover a Structured Streaming query
Work through the decision
A fare query reads an append-only event source. After a restart, it emits a batch twice to a custom external database. Does a successful checkpoint guarantee every external write happens only once?
Check your reasoning
Treat the input as an unbounded table. A micro-batch consumes a bounded range of source offsets and applies the query plan to it. A durable, unique checkpoint stores query progress and state. For end-to-end exactly-once behavior, the source must support replay and the sink must support an appropriate transactional or idempotent commit. A foreachBatch callback can run again for a batch after failure.
Compare the choices
- Durable checkpoint
- Give each query its own persistent checkpoint for offsets, progress and state. Keep compatible configuration when restarting the same query.
- Idempotent sink commit
- Make replay of a logical batch or business key safe, for example by recording the committed batch ID transactionally with its output. Check source and sink guarantees together.
- Append output mode
- Emit newly available final rows for supported queries. Stateful window results may be delayed until the event-time watermark passes the window.
- Update output mode
- Emit result rows changed since the prior trigger for supported queries and sinks. The consumer must interpret updates accordingly.
- Complete output mode
- Emit the entire current aggregation result table on each trigger for supported operations. Check state size and sink cost.
Test the decision
Choose an output mode supported by both query and sink. Append emits newly available final rows, update emits changed rows and complete emits the entire current result table where supported. Test a controlled restart with the same checkpoint and validate the resulting business keys at the destination.
Practice the guide skills
- Treat an input stream as an unbounded table and explain which offsets, state and sink guarantees a restart requires. Watch 2:01:01 · Continue at 2:01:18 · Continue at 2:01:33
- Choose input, trigger, output mode and sink for an append-only event archive versus a changing aggregate. Watch 2:02:27 · Continue at 2:03:03 · Continue at 2:04:23
Official objectives for this lesson
Related lesson · Structured Streaming
Recover a Structured Streaming query quiz
Answer 3 questions. Check each answer for an explanation.