LESSON 01 · Batch and stream

Ask whether the input ever ends

A batch job reads a finished input and exits, while a stream processor reads input with no end and must decide when each result is ready.

SYSTEM VIEW

The data flow

Diagram view
Orders read—
Unread payments—

Watch a nightly job read a closed day of order files and exit, then a stream job that never finishes, because card payments keep arriving.

  1. Order files holds yesterday’s 6 million completed orders, and nothing more will be added: the input has a known end. At 02:00 the nightly job reads it from the first file to the last, computes seller payouts and exits after 20 minutes.

    Starts
    02:00
    Input
    6 million orders
    Runs
    20 minutes

    What changed

    • Payouts for 6 million orders
    • Nightly job exits at 02:20
  2. A bug paid some sellers the wrong amounts. Fix it and rerun the nightly job over the same files: the input hasn’t changed, so the new payouts replace the old. A closed day is also a complete input, which the finance ledger report needs.

    Input
    the same files
    Output
    replaced

    What changed

    • Wrong payouts
    • Same files read again
    • Corrected payouts
  3. Card payments are still being written, so their log has no last record. The stream job reads each payment as it lands, and new ones keep landing past its cursor. It never finishes, so it carries running state across restarts and decides when each result is ready.

    What changed

    • Card payments, a log still growing
    • Stream job, reading as payments land
    • No last record
  4. A stolen card ending 4417 places five orders in two minutes. The stream job keeps a running count per card, sees the fifth and stops the orders before they ship. The nightly job would see them only in its next run, up to a day late.

    Card 4417
    5 orders in 2 min
    Nightly job
    up to a day late

    What changed

    • 5 orders on card 4417
    • Running count for 4417 reaches 5
    • Orders stopped before they ship
  5. The nightly job runs 20 minutes a day; the stream job never stops. Its running state must survive crashes, payments can arrive out of order, and reprocessing past data is harder than rerunning over closed files.

    Nightly job
    20 min a day
    Stream job
    never stops

    What changed

    • Compute that never stops
    • State that must survive crashes
    • Out-of-order events, harder reprocessing
  6. Ask what decision changes if the number arrives an hour sooner. Try each number: payouts and the ledger gain nothing, so they stay nightly; fraud on a stolen card and a live ops dashboard labeled provisional need the stream. Many systems run both, the nightly job keeping the number of record.

    Nightly job
    the number of record
    Stream job
    early, provisional

    What changed

    • Payouts and ledger stay nightly
    • Stolen cards and dashboards stream
    • Both run, batch keeps the record
    Number

Space plays · ← → step · Home resets

THE IDEA

How it works

A batch job reads bounded data, meaning an input with a known end, such as yesterday’s order files in S3. It computes a result and exits. If it fails or has a bug, you rerun it over the same files and replace the output. A stream processor reads unbounded data, an input that is still being written, such as card payments arriving now. It has no natural finish, so it must carry its running state across restarts and decide when a result is ready to emit.

Take one marketplace, with example numbers. Seller payouts run at 02:00 over 6 million completed orders and take 20 minutes. Sellers are paid once a day, so a fresher total changes nothing, and a bad run is repaired by rerunning it. The finance ledger report is similar: it must be complete, and a closed day gives a complete input. A stolen card is different. Five orders in two minutes must be stopped before they ship, and a nightly job could notice up to a day late. A live operations dashboard also suits a stream, provided its numbers are labeled provisional.

Streaming has real costs: compute that never stops, state that must survive crashes, events that arrive out of order, and harder reprocessing. A useful test is to ask what decision changes if this number arrives an hour sooner. If the answer is none, keep the nightly job. Many systems run both, with a stream serving early estimates and a batch job producing the number of record.

DECISION POINT

Finance needs a daily revenue report that matches the ledger to the cent. A product manager asks you to make it real time because the team already runs Kafka. Would you replace the nightly job?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Bounded input lets a job finish and rerun; unbounded input never gives it that moment.
  • Streaming pays for freshness with always-on compute, durable state, and out-of-order data.
  • Keep the nightly job when nobody acts differently on a fresher number.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
ApplyQUESTION 01

Which job gains the least from moving off a nightly batch?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.