Batch vs Stream
The spec's mode declares intent - but what actually makes a pipeline streaming is a type: stream source (or MongoDB change streams). Everything else works the same in both modes; the difference is how frames are read, written, and kept alive.
At a glance
modedeclares intent - atype: streamsource (or MongoDB change streams) is what actually makes a pipeline streaming.- Batch - one pass to completion, positions from asset offsets, commits when the run succeeds.
- Stream - continuous micro-batches, runs until killed, positions and state carried by Spark checkpoints.
The two modes
batch | stream | |
|---|---|---|
| Reads | One pass to completion | Continuous micro-batches |
| Writes | Direct writes per output | foreachBatch micro-batches |
| Run lifetime | Starts and finishes | Runs until killed |
| Position | Asset offset watermarks | Spark checkpoints |
| Stateful steps | Parquet state per step | Spark checkpointed state |
| Scheduling | Fire and finish | One live run at a time |
Batch
Batch runs are one-shot: read everything past the offsets, process, write, commit, done.
- Incremental reads come from asset offsets - a
WHERE key > valuewatermark per asset, committed only after the run succeeds - Stateful steps (
aggregate,forward_fill,gap_fill) keep cross-run state in Parquet files, committed after destinations succeed - Schedules fit naturally: the scheduler fires a run, it finishes, the next one waits
Code
A batch pipeline can still write to a stream - e.g. publish rows to a Kafka topic (type: stream destination) as part of the run. The write is direct, not continuous.
Stream
A pipeline becomes streaming when a source reads continuously - a stream source (Kafka, Redis, Kinesis, SQS) or MongoDB change streams:
Code
Streaming behavior:
- Outputs write micro-batch by micro-batch - per-output
options:trigger_interval(e.g."10 seconds"),output_mode(appenddefault;update;completeis coerced toappend) - Ingestion is throttled per asset - e.g. Kafka
max_offsets_per_trigger, Kinesismax_fetch_records_per_shard - Aggregates become windowed with
state.window(tumbling/session) or running totals without it - The engine keeps the run alive: streaming queries are awaited, so the run stays
RUNNINGuntil killed - Spark checkpoints carry source positions and stateful state across restarts - kill the run, start it again, and it resumes from the checkpoint
Stream sources never use asset offset or chain - their position lives in the checkpoint, not the offsets table.
Choosing
| You need | Use |
|---|---|
| Scheduled loads, incremental watermarks | batch |
| Continuous, low-latency ingestion | stream |
| Cross-run accumulating aggregates, bounded history | batch + stateful steps |
| Rolling windows, live dashboards | stream + state.window |
| Publish a batch result to a topic | batch + stream destination |
| Exactly-once where the sink allows | stream + idempotent sink (e.g. JDBC upsert) |
Practical notes:
- A scheduled pipeline with a
RUNNINGrun is skipped until it finishes - long-running stream pipelines and cron schedules don't mix; start stream pipelines on demand - Restarts resume from checkpoints, but missed time is not replayed - a schedule that came due while the app was down runs once, then advances
- Both modes report the same stages, lineage, samples, and logs - see Execution Lifecycle
Related pages
- Execution Lifecycle - statuses, stages, reconciliation
- Checkpoints and Offsets - positions and state in depth
- Sources - stream sources and their options
- Destinations - streaming output options
- Transforms - windowed and running aggregates