Prepstellar

Data Engineering Fundamentals · Data Engineering Foundations

22 cards

Batch, Streaming, and Latency

Swipe, scroll or use ← →
  1. Bounded and unbounded data

    The first question to ask about a pipeline is not which tool to use. It is whether the input ever ends.

    Batch processing operates on a bounded collection: a finite dataset or a group accumulated for a defined period or volume. The job can inspect the complete batch, make several passes, and finish. This suits work such as end-of-day reporting, payroll, backfills, and large repetitive transformations that do not require an immediate response.

    Stream processing operates on an unbounded collection that continues to receive events. Logs, sensor readings, clicks, and transactions are common event streams.

    Bounded input Unbounded input
    Does it end? Yes — a finite set, or one window's worth No — events keep arriving
    What the job can do Read it all, revisit it, then finish Update results incrementally as data comes
    Typical work End-of-day reports, payroll, backfills Clickstreams, sensor feeds, live transactions
    1 / 22
  2. Bounded and unbounded data

    One clarification saves a lot of confusion later. A stream can be micro-batched internally and still remain logically unbounded.

    An engine may collect arriving events for a fraction of a second and process them as a small group, because that is efficient. That is an implementation detail of how the work is executed. It does not change the shape of the source: no final record is coming, so the computation is never "done" in the way an end-of-day batch is done.

    Judge the input by whether it terminates, not by the size of the chunk the engine happens to process.

    2 / 22
  3. Quick check

    A job is handed yesterday's finished order file and asked to summarize it. What makes that input bounded?

    1. AThe source will keep sending records for as long as the ordering service runs

      That describes an unbounded source: it is the case in which the job can never see a complete set.

    2. BA broker retains the whole event history, so no record can ever be lost in transit

      Durable retention is about not losing data; it says nothing about whether the collection has an end.

    3. CThe set of records is finite, so the job can read all of it and then finish

      Right. A bounded input has an identifiable end, so the job can process the collected set and complete.

    3 / 22

  4. Why an unbounded stream needs windows

    Because the complete dataset never arrives, streaming computations incrementally update results and often use finite windows over the flow.

    Consider the difference between two questions. "What is total revenue?" asked of a stream has no final answer, because the next event could always change it. "What was revenue in the last five minutes?" does have an answer, because the window supplies the ending that the source refuses to.

    A window is therefore not a performance trick. It is the device that turns an endless flow into a group with a boundary, so an aggregation can be computed and emitted. Windows say nothing about arrival order, and they do not free the pipeline from holding state — the running totals for open windows have to live somewhere until those windows close.

    4 / 22
  5. Quick check

    Why do most aggregations over an unbounded stream need a window?

    1. AA window carves a finite group out of a source that keeps receiving records

      Right. The full stream has no final element, so the window supplies the finite scope that grouping and emission need.

    2. BA window guarantees that records turn up in exact event-time order, none late

      Windows decide grouping, not arrival: late and out-of-order events remain entirely possible.

    3. CA window removes the need to keep any state while the aggregation is running

      Open windows still hold their running results in state until they close and emit.

    5 / 22

  6. Latency, throughput, and what low latency costs

    Batch systems can process large volumes efficiently and schedule compute when resources are readily available. Their tradeoff is waiting for the collection window and job completion. Batch latency is commonly measured in minutes, hours, or days, while streaming targets results in seconds or milliseconds.

    Low latency is not free. Streaming keeps producers, brokers, consumers, state, monitoring, and recovery mechanisms operating as data arrives. It must handle bursts, out-of-order events, consumer lag, and a source whose final size is unknown. Batch scheduling and recovery are usually easier to reason about for delay-tolerant work.

    Batch Streaming
    Typical latency Minutes, hours, or days Seconds or milliseconds
    What runs A scheduled job, then nothing Producers, brokers, consumers, state, monitoring
    Recovery Rerun the job over the same set Restore state and continue from saved progress
    Hard parts Waiting for the window and the job Bursts, out-of-order events, consumer lag
    6 / 22
  7. Latency, throughput, and what low latency costs

    Throughput and latency are separate measures, and confusing them leads to the wrong fix.

    Throughput is how much work completes per unit of time. Latency is how long one item waits for its result. A system can process many records per second yet still build a long queue, or return each event quickly at a lower total rate.

    That is why "we handle 200,000 records a second" is not an answer to "why is this alert seven minutes old". The first is a rate; the second is a delay. A backlog can grow steadily while throughput stays impressively high, because arrivals are simply faster still.

    7 / 22
  8. Quick check

    A pipeline reports a very high records-per-second rate, yet each event is minutes old by the time its result appears. What does that show?

    1. AThroughput measures when an event happened; latency measures if a source ends

      Occurrence time and boundedness are different concepts entirely; neither is what these two measures report.

    2. BThroughput is a rate of completed work, while latency is the delay for one item

      Right. One is a rate and the other is a delay, so a high rate can coexist with a long queue.

    3. CHigh throughput guarantees millisecond delay for every event, whatever the backlog

      A backlog can grow while throughput stays high, if arrivals are faster still than completions.

    8 / 22

  9. Keep your progress in the app

    That’s 3 of 9 quick checks. In the app they stay answered, and every lesson remembers where you left off.

  10. Choosing between the two

    Choose batch when efficient high-volume completion matters more than immediate action; choose streaming when the value of a result declines with delay.

    That is the whole decision rule, and it is about the value of the answer rather than the fashion of the tool. A payroll run is worth exactly as much at 03:00 as at 22:00, so the cheaper, simpler, delay-tolerant path wins. A fraud decision is worth a great deal in two seconds and almost nothing in two hours.

    Hybrid designs can use streaming for timely signals and batch for deep history or reprocessing. The same events can feed a live alerting path and a nightly job that rebuilds the full history with corrections applied.

    The situation The fit
    Delay-tolerant work over large volumes Batch: efficient completion, simpler recovery
    The result loses value as it ages Streaming: continuous, low-latency processing
    Both a live signal and a deep history A hybrid path, each side doing what it does best
    9 / 22
  11. Choosing between the two

    Apply it to a fraud service. Transactions arrive continuously, a decision is needed within seconds, and occasional bursts must not cost the system any events.

    Streaming is forced by the first two facts: the source never ends and the deadline is seconds. The third fact sets the cost of admission. Durable buffering absorbs the bursts, recovery state lets the pipeline resume without losing its place, consumers scale out when the rate climbs, and monitoring exposes consumer lag before it becomes a missed decision.

    The alternatives fail on the stated facts. A nightly batch over the complete day answers long after the reaction window has closed. A streaming consumer without durable buffering is exactly the design that a burst breaks — low latency does not prevent traffic spikes, it makes them more damaging.

    10 / 22
  12. Quick check

    A fraud check must react within seconds, traffic arrives continuously, and bursts must not lose events. Which design fits, and what does it cost?

    1. AA nightly batch over the finished day, which is cheaper and simpler to recover

      A nightly job answers long after the reaction window has passed, whatever its cost advantage.

    2. BA streaming consumer with no durable buffer, as low latency prevents any bursts

      Low latency does not stop bursts from arriving; without durable buffering, a burst is exactly what loses events.

    3. CA monitored streaming pipeline with durable buffering, recovery state, and scaling

      Right. Streaming cuts the delay, and the price is continuously operated state, recovery, and monitoring.

    11 / 22

  13. Event time and processing time

    Once results depend on when things happened, a pipeline is carrying two clocks and has to keep them apart.

    Event time is the timestamp associated with when an event occurred. Processing time is when a pipeline stage actually processes that event.

    Network delay, retries, and buffering mean these times can differ, and events may arrive out of order. A sale made at 10:00 on a phone with no signal may reach the pipeline at 10:07, after a retry, and land behind a sale made at 10:05.

    Clock What it records Where it comes from
    Event time When it happened in the business The event itself, as produced
    Processing time When a stage handled it The pipeline's own clock
    12 / 22
  14. Quick check

    A sale is made at 10:00 and, after a retry, the pipeline handles it at 10:07. Which value is the event time?

    1. A10:07, because that is the moment a worker actually processed the record

      That is the processing time: the pipeline's own clock, not the event's.

    2. B10:00, because that is when the event occurred in the producing domain

      Right. Event time belongs to the event itself, while processing time belongs to the stage handling it.

    3. CThe moment the consumer last wrote a checkpoint for the partition

      A checkpoint records how far processing has progressed; it is not the business timestamp of a sale.

    13 / 22

  15. Windows, watermarks, and late data

    Event-time windows group records by occurrence time and preserve the intended business period. A sale made at 10:00 counts in the 10:00 window even if it is handled at 10:07, so the report says what actually happened in that period.

    A watermark expresses when the system expects most data for a window to have arrived; later records may be treated as late according to the configured policy. It is the pipeline's declared patience: hold the window open long enough for the stragglers that are worth waiting for, then finalize.

    Processing-time triggers instead decide output based on the pipeline clock, which is the right choice when the question really is about system handling — how much the pipeline got through in the last minute.

    The correct clock follows the question: business occurrence or system handling. If events can arrive ten minutes late, results must be grouped by when they happened, and early figures may be revised, then event-time windows with a watermark that tolerates the required lateness are the fit.

    14 / 22
  16. Quick check

    Events can arrive ten minutes late, the report must group them by when they happened, and early figures may be revised. Which design fits?

    1. AEvent-time windows with a watermark that tolerates the required lateness

      Right. Event time preserves the business period, and the watermark sets how long out-of-order arrivals are accepted.

    2. BProcessing-time windows, assuming arrival order matches when events occurred

      Arrival order does not match occurrence order here: that assumption is exactly what ten-minute lateness breaks.

    3. CThe batch schedule time, discarding the timestamp each event carries

      Discarding the event's own timestamp throws away the only thing that can group records by when they happened.

    15 / 22

  17. Delivery guarantees

    Failures create a choice between loss and repetition. A consumer that dies between doing the work and recording that it did the work leaves the system genuinely unsure, and each guarantee resolves that doubt differently.

    At-most-once delivery avoids redelivery but can lose a record when failure occurs before durable processing. At-least-once delivery retries uncertain work, reducing loss risk while allowing duplicates. Exactly-once processing coordinates state and progress so each input affects the managed result once.

    Checkpoints store processing state and help recovery maintain that guarantee within supported sources and sinks — they are how a restarted job knows what it had already accounted for.

    Guarantee On an uncertain failure The risk you accept
    At-most-once Do not retry A record can be lost
    At-least-once Retry the uncertain work The same input can be applied twice
    Exactly-once Coordinate state with progress Limited to supported sources and sinks
    16 / 22
  18. Quick check

    A consumer fails after doing the work but before recording its progress, under at-least-once delivery. What follows?

    1. AThe uncertain work is retried, so an input whose effect already landed may repeat

      Right. At-least-once favours avoiding loss by retrying, so the earlier attempt may already have taken effect.

    2. BThe broker declines to redeliver it, so that record drops from the result

      Refusing to redeliver is at-most-once behaviour, which trades duplicates for the risk of loss.

    3. CThe pipeline discards every record arriving after the current watermark

      Watermarks govern how long a window waits for late data; they are unrelated to redelivery after a failure.

    17 / 22

  19. Idempotent sinks

    End-to-end behavior includes the sink. Some operations provide at-least-once delivery, and retries can repeat a write. Whether that repetition matters is decided by what happens at the destination.

    An idempotent sink produces the same business result when the same input is applied more than once. A stable event key, merge, or deduplication rule can prevent repeated delivery from creating duplicate business records: the second arrival of key INV-4471 updates the row it already wrote instead of inserting a second one.

    Acknowledgements and durable brokers also reduce loss, but they do not make a non-idempotent side effect safe from repetition. A blind insert is still a second row, and a second row on a billing table is a second bill.

    18 / 22
  20. Idempotent sinks

    Put the two halves together on a billing pipeline. The connector may retry a micro-batch after an uncertain failure, and a lost bill is far less acceptable than a repeated delivery attempt.

    The loss preference settles the delivery mode: at-least-once, because retrying is what keeps a bill from vanishing. That choice creates the duplicate exposure, so the sink has to absorb it — a stable billing key plus a merge that updates the existing row rather than inserting a new one.

    The failing designs each break one half. Disabling redelivery protects against duplicates by accepting exactly the loss the requirement rules out. Keeping at-least-once while inserting a fresh row per retry bills the customer twice. Overwriting the event's own timestamp with the retry time destroys the business record while doing nothing about the duplicate.

    19 / 22
  21. Quick check

    A billing sink may have its micro-batch retried by the connector, and a lost bill is worse than a repeated attempt. Which write design is safest?

    1. ASwitch off redelivery and accept losing any record whose outcome was uncertain

      That trades the duplicate risk for exactly the loss the requirement rules out.

    2. BKeep at-least-once delivery and insert a fresh billing row on every single retry

      Retrying without an idempotent write is what turns one bill into two.

    3. CKeep at-least-once delivery with stable bill keys and an idempotent merge write

      Right. Retrying limits loss, and stable keys with idempotent merges keep repeated attempts from duplicating a bill.

    20 / 22

  22. Key takeaways

    • Batch consumes bounded data; streaming continuously processes unbounded data. Micro-batching inside an engine does not make an endless source bounded.
    • Use streaming for low-latency action and batch for delay-tolerant, high-volume efficiency. Low latency is paid for in continuously operated state, recovery, and monitoring.
    • Throughput and latency are separate: a high rate of completed work can sit alongside a long queue.
    • Event time records occurrence; processing time records pipeline handling. Event-time windows plus a watermark preserve the business period while tolerating late arrivals.
    • At-least-once needs idempotent handling to control duplicates, while weaker redelivery can increase loss risk. Stable keys and merges make a retry harmless.
    21 / 22
  23. Quick check

    Which pairing of choice and reason holds up?

    1. AStreaming suits bounded history, since a finite set has to be processed as it arrives

      A bounded, finished set is the batch case; nothing about it requires continuous handling.

    2. BStreaming when delay destroys a result's value, batch when volume efficiency wins

      Right. The decision follows how quickly the answer loses its worth, not the tool's reputation.

    3. CBatch whenever duplicates are possible, since only batch writes can be made idempotent

      Idempotency is a property of the sink and its keys, not something only batch jobs can have.

    22 / 22

  24. 9 quick checks · then the test

    In the app, finishing the quick checks opens this lesson’s 10-question test, and the ones you miss come back exactly when you’re about to forget them.

The whole course, on your phone

Lessons you can read, audio you can listen to on the way to work, and practice that remembers what you got wrong.