Stateful queries get a lower-latency execution option
Apache Spark 4.3.0 added streaming aggregation, dropDuplicates and Scala/Java transformWithState to Real-Time Mode when it was released on October 30, 2026. These additions support queries that retain information across events, including deduplication and running aggregates. Apache describes latency on the order of 100 milliseconds; Databricks reports results below 150 ms at the 99th percentile for tested stateful workloads. The deployment question is whether those gains meet an application’s latency, budget and recovery requirements. Sources: Apache Spark, Databricks
Micro-batch schedules bounded jobs, while Real-Time Mode processes records through long-running tasks. Spark combines concurrent stage scheduling with pipelined shuffle dependencies so producers and consumers execute together. The scheduler rejects a pipelined group when task slots are insufficient, and failures affect the group collectively. Capacity planning therefore belongs alongside operator compatibility in a migration review. Sources: Apache Spark
The benchmark measures updates under specific conditions
Databricks’ November 5, 2026, announcement reports lower 99th-percentile, or P99, latency for all three stateful workloads in the table below. The Apache benchmark used Kafka input and output at 1,000 records per second, with five input partitions and five shuffle partitions. It compared a five-minute Real-Time Mode trigger with an immediate micro-batch trigger. Observations covered 30 minutes, excluding ten minutes of warm-up, and used RocksDB checkpoint format V2 with changelog checkpointing. Sources: Apache Spark, Databricks
Table
Published stateful P99 latency, in milliseconds
| Workload | Real-Time Mode P99 | Micro-batch P99 |
|---|---|---|
| Deduplication | 136 | 503 |
| Window aggregation | 139 | 610 |
| JVM transformWithState | 141 | 463 |
Deduplication used 80% fresh keys and 20% duplicates; aggregation used one-minute windows and 1,000 keys. Custom state used 50,000 keys, with one state read and update per row and no timers or time-to-live expiration. Latency came from input and output Kafka CreateTime timestamps, rather than downstream consumer receipt. Aggregation samples measure emitted updates, and micro-batches can combine updates. The 139 ms result therefore does not measure delivery of a finalized one-minute window. Sources: Apache Spark
The modes generated separate inputs with slightly different counts instead of replaying one recorded stream. Databricks explicitly limits its latency claims to the tested workloads. The published comparison does not establish lower resource cost or equivalent latency and correctness after restart. Treat the results as a reason to test faster updates, not as a cost estimate or a latency guarantee. Sources: Apache Spark, Databricks
Checkpoint cadence and capacity affect the decision
A five-minute Real-Time Mode trigger primarily controls checkpoint cadence; it does not make every result wait five minutes. Watermark advancement and idle-partition timers can still wait for batch boundaries. Stateful Real-Time Mode commits progress synchronously, while asynchronous progress tracking applies to stateless Real-Time Mode. Applications needing rapid interim updates should therefore be evaluated separately from those waiting for completed event-time windows. Sources: Apache Spark
Spark’s guide says ten Kafka partitions plus five aggregation partitions require at least 15 simultaneous cores. That requirement makes reserved capacity a cost consideration even when measured CPU use is modest. Compare identical machines first to isolate execution differences. Then find the smallest configuration of each mode that meets the same latency, throughput and recovery targets. Sources: Apache Spark
Upstream Spark 4.3 excludes stream-stream joins, flatMapGroupsWithState and Python custom-state APIs from Real-Time Mode. A Databricks tutorial describes row-based Python custom state, a separate implementation claim from upstream Spark support. Java virtual machine (JVM) custom-state callbacks in Real-Time Mode receive one non-late row per invocation, unlike micro-batch’s grouped iterator. Review how existing custom-state logic handles that difference before changing the trigger. Sources: Apache Spark, Databricks
Replay one stream and measure application latency
For a controlled evaluation, replay one immutable event corpus into isolated runs, preserving partition ordering and arrival timing. Give each event an immutable ID, business key, event timestamp, sequence number and payload checksum. Test deduplication with known duplicates, aggregation with independently computed integer totals, and custom state with deterministic transitions. Define lateness and window-finalization rules before testing. Compare equivalent business results rather than requiring identical intermediate row counts.
For the equal-resource comparison, hold machines, Spark build, partitions, state backend, checkpoint storage, Kafka durability settings and sink constant. Compare immediate micro-batch processing with practical fixed intervals, and vary Real-Time Mode checkpoint duration separately. Measure producer-to-consumer delay with synchronized clocks and documented timestamp placement, acknowledgments and consumer polling. Databricks’ tutorial says its e2eLatencyMs metric excludes sink-write time. Use application-observed latency to judge delivery requirements. Sources: Databricks
- Report median, tail and maximum latency, separating delays around checkpoints.
- Measure aggregate freshness and final-window availability separately.
- Track offered and processed throughput, output rates and backlog growth.
- Record allocated compute, actual CPU use, memory and state size.
- Count checkpoint bytes and requests, disk activity and shuffle traffic.
- Report infrastructure cost against the agreed service objective.
Repeat the comparison under steady traffic, bursts, idle periods followed by bursts, larger key populations and concentrated traffic on individual keys. Alternate execution-mode order and include enough checkpoint cycles to expose occasional stalls. Publish each configuration so checkpoint and resource differences remain visible. For the equal-service-objective comparison, resize each mode until it meets the same requirements. Use that result to compare deployment costs.
Correct state can still produce duplicate business actions
Spark’s guide distinguishes exactly-once processing of managed state from Kafka output, which remains at-least-once and can repeat records after restart. Consider a replayed aggregate update: Spark’s final state can be correct while a downstream consumer adds the repeated contribution twice. Include the application’s downstream write behavior in the correctness test. Checking only the final Spark aggregate would miss that failure. Sources: Apache Spark
Test executor loss and driver restart separately, injecting failures midway through a Real-Time Mode batch, near a checkpoint and during checkpoint-storage delays. Continue producing events during recovery. Measure both the first resumed output and the time needed to clear the backlog. After draining the stream, check for missing IDs, inflated totals, repeated external records and duplicates that escaped suppression across the restart. Verify window boundaries and late-event handling against the declared policy.
Set acceptance thresholds before switching
Consider Real-Time Mode when a supported stateful query needs faster interim updates and the application can fund concurrent capacity. Require a materially better application-latency result on the intended stream, within budget, with failure-and-replay tests passing. Keep micro-batch when it already meets the requirement or when the measured gain does not justify reserved resources. For workloads driven by completed windows, make final-result availability the deciding measurement.
Before rollout, verify that existing state and checkpoints can migrate safely for the exact query and configuration. Exercise the intended checkpoint store with larger state and concentrated traffic. Test whether a shorter checkpoint interval changes both normal-operation latency and recovery behavior. Set acceptance thresholds for normal operation, catch-up time and downstream duplicate handling before choosing a production configuration.