Stream processing
We keep the computation open as records arrive. An unbounded input has no final last record to wait for. We will maintain keyed state, partition work, bound queues, and define what a continuously changing result means.
#Section 9An unbounded input needs incremental work
Waiting for every future score event would never finish. Stream processing computes over arriving data while the input remains open. It can maintain a current result or publish bounded windows instead of waiting for the whole stream to end.
For the tiny sequence, the red running sum moves from zero to 2, then to 6 when the third record arrives, then to 7 on the fourth. Blue moves from zero to 3. A stateful operator stores information from earlier records that later records need. The running sum is state; the map that extracts a team is stateless under its simple rule.
A stream engine must manage both input progress and state. Restarting a process with only the latest source offset can lose the sum. Restarting with only the sum and an earlier offset can repeat additions. The recovery part will combine them in a checkpoint. Continuous execution does not remove the need for a consistent restoration boundary.
#Section 10Keyed state has an owner
All contributions for red must update the same logical sum, or a defined merge protocol must combine partial sums. Keyed state associates stored operator data with a grouping key. The engine routes equal keys to the same state owner under its partitioning rule.
Four illustrative input partitions each receive five events per second under equal balance. If each assigned consumer can process ten per second, total capacity is forty per second against twenty input. Those averages do not protect a single hot key whose events all reach one owner. Key distributions and per-record cost determine real capacity.
Kafka-style event streams provide partitioned retained inputs and consumer progress rather than a finished analytical answer. The processor chooses a key and reads the corresponding ordered partition positions into its state protocol. Kafka retention and replay can repair transport gaps, while keyed aggregation, event-time interpretation, and sink effects remain processor responsibilities. A broker name does not replace those mechanisms.
Rescaling moves key ownership and its state. The engine must coordinate that movement with source progress and checkpoint restoration so two owners do not independently mutate the same logical state. A map of keys to workers is not enough; the state migration and activation protocol matters. Use the engine’s tested mechanism rather than inventing a distributed handoff casually.
#Section 11Backpressure slows an upstream stage
A sink writes more slowly than transformations produce output. A backpressure mechanism bounds queued work and propagates the inability to accept more records toward upstream stages. Without it, a long-running job can consume memory until it fails, even if each operator is individually correct.
The input log absorbs a bounded recoverable backlog while consumers slow down, under its retention limit. Source progress must not advance beyond work the recovery protocol can restore. Queue age and input lag make the delayed product effect visible. A queue depth of zero in one operator does not prove the external sink is current.
If backlog is twelve thousand records, new input remains twenty per second, and recovery capacity is one hundred twenty, net drain is one hundred per second. Catch-up takes 120 seconds. Dividing backlog by total processing capacity would wrongly ignore new arrivals. Reserve recovery capacity beyond normal demand and retention beyond the expected outage plus catch-up period.
#Section 12Streaming outputs can be updates
A running total changes after each accepted contribution. The sink can append every version, overwrite the keyed current value, or receive changes to a result table. A changelog output describes inserts, updates, or removals in a derived relation rather than pretending every emitted row is an independent fact to add.
An update from contribution 4 to contribution 6 changes the sum by 2. A retraction-style representation can emit minus 4 followed by plus 6. The net adjustment is 2. If a sink adds both old and new complete totals, it double-counts instead of applying the update semantics.
Sink keys, ordering, and version checks determine how repeated updates behave. A compacted keyed topic, a transactional upsert table, and an append-only audit log serve different purposes. Pick the representation from the reader’s question and the recovery contract. A streaming label cannot resolve incompatible output semantics.