The full answer
Spark Streaming processes data continuously as it arrives, while Spark batch processing runs over a fixed, already-complete dataset and then stops. "Spark Streaming" originally meant the DStream API, which is now a legacy project with no further updates; modern Spark streaming uses Structured Streaming, which runs streams with the same DataFrame and SQL API as batch.
Batch
- Input is bounded: a set of files or a table snapshot.
- A job reads everything, computes and finishes.
- Latency: minutes to hours, depending on schedule.
- Typical uses: nightly loads, reports, model training, backfills.
Streaming
- Input is unbounded: Kafka topics, event hubs, files landing in a folder, change feeds from Delta tables.
- A query keeps running, processing new data in small increments (micro-batches, by default as soon as the previous one finishes, or on a fixed interval).
- Latency: typically from under a second to a few minutes.
- Needs state for aggregations and joins over time, event-time handling for late data, and checkpointing for recovery.
- Typical uses: real-time dashboards, alerting, fraud detection, continuous ingestion into a lakehouse.
Structured Streaming in one example
from pyspark.sql import functions as F
events = (spark.readStream.format("kafka")
.option("kafka.bootstrap.servers", "broker:9092")
.option("subscribe", "clicks").load()
.select(F.from_json(F.col("value").cast("string"), click_schema).alias("c"))
.select("c.*"))
per_minute = (events
.withWatermark("event_time", "10 minutes")
.groupBy(F.window("event_time", "1 minute"), "page")
.count())
(per_minute.writeStream
.format("delta")
.outputMode("append")
.option("checkpointLocation", "/chk/clicks_per_minute")
.toTable("gold.clicks_per_minute"))
The transformation code is the same as a batch query; only readStream and writeStream differ.
Key differences in practice
| Batch | Streaming | |
|---|---|---|
| Input | Bounded | Unbounded |
| Run | Starts and ends | Runs continuously (or incrementally on a schedule) |
| Recovery | Re-run the job | Resume from the checkpoint with exactly-once results |
| State | Not needed between runs | Kept for aggregations, joins and deduplication |
| Time | Data is complete | Late and out-of-order data; watermarks decide how long to wait |
| Cost | Pay while the job runs | Pay while the stream runs |
A useful middle ground
trigger(availableNow=True) runs a streaming query that processes everything new since the last run and then stops. You get streaming's incremental processing and checkpointed progress with batch-style scheduling, which is how many ingestion pipelines run today.
Last updated 16 October 2026
Sources