Skip to content

Introduction

Why stream processing?

When to compute an answer on request, on a schedule, or as each change arrives.

Learn with an AI assistant

Copy the prompt and paste it into a chat with an AI assistant.

You are a tutor for the course "Stream Processing".
Topic: "Why stream processing?"
In short: When to compute an answer on request, on a schedule, or as each change arrives.
Topic text in Markdown: https://stream-processing-systems.github.io/introduction/why-stream-processing.md
Base your explanations on the topic text. First ask how I want to study: a short summary, a step-by-step walkthrough, or a deep dive with questions that check my understanding. Use the text's example and terms. If you add anything the text does not say, point it out.

Imagine you ordered groceries for delivery. At the store, a picker (the worker who collects your items) cannot find red apples and proposes green apples instead.1 The app asks you to accept or decline, and the picker waits for your answer. You need to see the proposal while the picker is still in the aisle.

The store handles many orders like yours at the same time, and a supervisor wants an overview of the workload. Both needs depend on the same data: changes to orders that keep coming in. The question is when to turn those changes into an answer. There are three common ways to do it.

The simplest way is to wait until someone looks. When you open the order page, the app sends a request. The service reads the order, works out its current status, and sends back the page. This is processing on request: the calculation runs because someone asked for it.

This works well for checking delivery progress. You look at your order a few times, reading one order is cheap, and the service does no work while nobody is looking.

The weakness is that the page shows the order as it was when you opened it. If the picker proposes a replacement a minute later, you will not see it until you open the page again. The app could reload every few seconds. That is still processing on request, and most of those requests would find nothing new.

The supervisor needs something different: a list of all active orders. The store can collect changes and run one calculation every fifteen minutes. Each run reads everything collected so far, builds the list, and saves it as a report. This is batch processing: a collected set of data is processed together, in one run.

It suits a report that can wait. One run covers many orders at once, and a fifteen-minute delay is acceptable for reviewing the store’s workload.

The weakness is the gap between runs. If you accept a replacement just after a run, the report shows your order as waiting for up to fifteen minutes. Running more often shortens the gap, but each run repeats the work for orders that did not change, and some gap always remains.

A fifteen-minute report is far too slow for the replacement. Reloading every few seconds would be fast enough, but it means asking about every active order again and again, while most of them have nothing new to show.

So we turn the approach around. Instead of waiting for a question or a schedule, the system reacts to each change when it arrives. Each change is recorded as an event: a small record of something that happened, such as “replacement proposed” or “order packed”. When the proposal arrives, the system updates your order page. When your answer arrives, it updates the picker’s screen and the store’s list of orders waiting for a customer.

This is stream processing: handling a continuing flow of events as they arrive and keeping results up to date along the way.

Three ways to calculate a result The same order changes arrive at irregular moments; processing on request calculates when someone looks, batch processing on a fixed schedule, and stream processing right after each change. Order changes arrive at any moment Processing on request when someone looks Batch processing every 15 minutes Stream processing after each change TIME

The cost is that the system works on every change, even when nobody is looking at the result. It also needs a way to receive the events and deliver its updates. None of this requires a special product or a large distributed system. A small application can read an event, apply one rule, and write the new result. Teams add specialized tools when there are more events, more readers of the results, and more ways for things to fail.

Results like these are often called real-time. That does not mean instant. An event has to be recorded, delivered, processed, and shown, and every step takes some time. An event can also arrive late, out of order, or not at all. In practice, real-time means the delay is small enough for a stated purpose. For the replacement, a few seconds may be fine, while a few minutes are not.

Four questions help decide:

  1. How quickly does someone need the result?
  2. Who needs it, and how often do they look?
  3. How often does the data change, and how much work is it to recalculate?
  4. What goes wrong if the answer is a few minutes old?

The grocery service answers them differently for each task:

Delivery progressStore overviewReplacement during picking
How quickly?When the shopper looksEvery fifteen minutes is enoughWithin seconds
Who, and how often?One shopper, a few timesA supervisor, at regular reviewsThe shopper, the picker, and store staff, while the order is prepared
Changes and cost to recalculateFew changes; reading one order is cheapMany orders change; one run covers them allChanges arrive at unpredictable moments across many orders
If a few minutes old?Nothing; nobody was lookingLittle; the report can waitThe picker keeps waiting after you have already answered
FitsProcessing on requestBatch processingStream processing

One service can use all three approaches. Stream processing is worth its cost where a decision depends on changes during ongoing work. Elsewhere, a simpler approach is enough.

Stream processing reacts to each event, so each event has to say enough. If the system only receives “order updated”, it cannot tell whether to show you a new proposal or confirm the replacement you accepted. To act on an event, the system needs to know what happened, to which order, and when.

  • A result can be calculated when someone asks, on a schedule over collected data, or as each change arrives.
  • Stream processing reacts to events as they arrive. It helps when decisions depend on changes during ongoing work.
  • A real-time result still has a delay, and that delay must be small enough for its purpose.
  • One service can use different approaches for different tasks.

Enable JavaScript for the interactive quiz. Questions and answers are available below.

An order page refreshes every two seconds. On each refresh, the service reads that order, calculates its current status, and returns it, even if nothing has changed. Which processing approach does this describe?
  • Processing on request.
  • Batch processing.
  • Stream processing.

Correct answer: Processing on request.

Each page refresh causes the service to calculate an answer. A frequent request is still a request.

Calculate when someone asks
A report is updated only by a batch calculation every fifteen minutes: at 10:00, 10:15, and so on. At 10:01, a shopper's replacement answer reaches the system and is available for processing. When will the saved report reflect it?
  • When the supervisor next opens the report.
  • After the next calculation at 10:15.
  • As soon as the shopper's answer arrives.

Correct answer: After the next calculation at 10:15.

The answer is available after the 10:00 run. The next calculation at 10:15 can include it and save the updated report.

Calculate on a schedule
A service uses stream processing to keep a saved order list up to date. Nobody opens the list for three minutes, but order changes keep arriving. How does the calculation continue during that time?
  • Update the result whenever a change arrives.
  • Update the result at the next scheduled run.
  • Update the result when someone opens the list.

Correct answer: Update the result whenever a change arrives.

The service keeps applying arriving changes to the saved result, even when nobody opens the list.

Process each change as it arrives
A shopper needs to see a replacement proposal within five seconds. A second screen needs its updates within one second. Both screens show their respective changes after three seconds. Which screen meets its stated timing requirement?
  • The requirement is met only for the shopper's screen.
  • The requirement is met for both screens.
  • The requirement is met for neither screen.

Correct answer: The requirement is met only for the shopper's screen.

Three seconds is within the shopper's five-second requirement, but exceeds the other screen's one-second requirement.

What "real-time" means
Store staff need to see replacement answers within seconds. Many orders are active, most have not changed, and repeatedly reading all of them is costly. Which approach best fits these conditions?
  • Recalculate from active orders every time staff refresh the list.
  • Recalculate from collected changes every fifteen minutes.
  • Update the list from each replacement answer as it arrives.

Correct answer: Update the list from each replacement answer as it arrives.

Each arriving answer updates the list without repeatedly reading all unchanged orders. This matches the stated need for timely updates.

Which approach fits
  1. Uber: Retail Order Fulfillment API Guide.

© 2026 Grig Alex · CC BY-NC-SA 4.0