Free sample lesson ยท Apache Flink for Engineers: 5 Real-World Use Cases

Stream processing vs. batch processing

Lesson 1 of the Wondering course Apache Flink for Engineers: 5 Real-World Use Cases

Two ways to handle data

Every data system faces one question: when do you process what arrives?

Batch processing collects data and handles it at set intervals, such as a nightly run.

Stream processing handles each record as it arrives, continuously.

When the work happens
  • Batch
  • Stream

The data can be identical. The timing of the answer is what changes.

How a batch job runs

A batch job waits. Records pile up in storage while nothing is computed.

At the scheduled moment, the job wakes up and processes everything collected.

Results land in a report or table. Then the cycle starts over and data begins piling up again.

The batch cycle
  • Data arrives: Records pile up in storage.
  • Wait for interval: Nothing is computed while the window fills.
  • Job runs: Everything collected is processed at once.
  • Results published: Output lands in a report or table.

This repeating rhythm is why batch answers always arrive on a schedule, never on demand.

How a stream flows

A stream never waits for a window to close.

Each record is processed the moment it arrives, and the result is available almost immediately.

There is no pile of unprocessed data sitting in storage.

One record through a stream
  • Event happens: A single record is created.
  • Arrives: The pipeline receives it without waiting for a window.
  • Processed: The record is handled the moment it arrives.
  • Result ready: The answer is available almost immediately.

Because the pipeline is always running, the answer moves with the event instead of trailing behind it.

Latency is the real gap

Latency is the delay between an event happening and a system reacting to it.

With a nightly batch job, that delay can stretch to hours.

With a stream, the same reaction can land in about 50 milliseconds.

Delay before a reaction

That distance is not a small tuning detail. It decides which actions are still possible.

Where batch falls short

Fraud detection makes the gap concrete.

Caught in a nightly report, the fraudulent transaction already went through. You are writing history.

Caught in 50 milliseconds, the transaction can be blocked before it completes.

Fraud caught when?
  • Transaction happens
  • Detected in 50ms?: Does the system react while the event is still open?
  • Block transaction: The transaction is stopped before it completes.
  • Nightly report: The fraudulent transaction already went through.
  • Writing history
  • Loss prevented

Same data, same rules. Only the timing changed the outcome.

Batch is not obsolete

Streaming is not automatically better. It is better when latency matters.

If nobody acts on the answer within hours, a nightly batch run is a fine choice.

Ask one question: does a faster answer change what someone can do?

When is 50ms worth nothing?

If yes, stream. If no, batch.

Choosing between them

The decision comes down to three things: when data is processed, how long the delay is, and what the answer is used for.

Batch processes at intervals and produces reporting.

Streams process on arrival and enable action while the event is still open.

Batch or stream?
  • Batch
  • Stream

Match the processing style to the deadline of the decision it supports.

Check yourself

Batch processing handles collected records at scheduled intervals rather than as each record arrives.

  • True
  • False

Answer: True

Batch processing waits for a scheduled run, collects records, and processes them together. Stream processing handles records continuously as they arrive.

A nightly _____ run produces a scheduled report, while _____ processing produces results as records arrive.

Answer: A nightly batch run produces a scheduled report, while stream processing produces results as records arrive.

Batch processing waits for a scheduled interval and commonly produces reports. Stream processing handles records on arrival, making results available almost immediately.

A company needs to block fraudulent transactions before they complete. Which processing approach best supports this requirement?

  • Stream processing
  • Nightly batch processing
  • Scheduled reporting only
  • End-of-day table refresh

Answer: Stream processing

Stream processing is appropriate because it reacts as each transaction arrives, potentially within about 50 milliseconds. A nightly batch result would arrive after the transaction had already gone through.

Keep going

This is lesson 1 of 8 in Apache Flink for Engineers: 5 Real-World Use Cases. Next up:

  1. Flink's stateful processing model
  2. Real-time fraud detection
  3. Real-time ETL with CDC
  4. Real-time aggregation and alerting
  5. Event-driven application orchestration

Start this course free

Wondering turns any topic into short lessons you can read, watch, or listen to, with practice questions and an AI tutor.