Streams, Batches, and Materialized Views
Core Concepts (5)
- 1.Batch favours throughput and simplicity, streams favour freshness
- 2.Event time and processing time differ
- 3.Windows turn endless streams into answers
- 4.Materialized views trade storage for read speed
- 5.State in stream jobs needs checkpoints and care
Map to Your Experience
Recall a report or dashboard that was always hours late. What did the business lose by waiting, and what would fresher data have cost?
Design Brief: Live Revenue Dashboard
Learn
Data processing comes in two broad shapes. Batch jobs run over a bounded set of data, such as yesterday's orders, and finish. Stream jobs run continuously over unbounded data and produce results as events arrive. Batch is simpler to reason about and cheap per record. Streaming gives freshness at the cost of more moving parts.
The key stream concept is the difference between event time and processing time. Event time is when something happened; processing time is when your system saw it. Mobile devices go offline, networks stall, and queues back up, so the two diverge. If you aggregate by processing time, results shift whenever the pipeline slows down.
Windows turn an endless stream into finite answers. Tumbling windows split time into fixed slices, sliding windows overlap, and session windows follow bursts of activity. Each needs a rule for late events: wait a while before finalising, update the result when stragglers arrive, or drop them and record the loss.
A materialized view stores the result of a query so that reads are cheap. A dashboard table that is updated as events flow is a materialized view. The cost is storage and the work of keeping it fresh. The real risk is drift, where the view and the source disagree, so schedule a periodic recomputation to check.
Stateful stream jobs hold counters and joins in memory. They survive restarts by checkpointing state and tracking positions in the input. Test recovery before you need it, because the first real failure is a bad time to learn that a replay double counts.
Map
List three reports your organisation produces and the delay each one has. For each, write what decision it supports and whether a one minute delay would change that decision. Mark which ones truly need streaming and which are fine as nightly batches. Share the result with a colleague and note where their reading differs from yours.
Design
Design the revenue dashboard pipeline. Describe the streaming path, the window length, and how late events are handled. Describe the nightly batch that produces the official numbers and how you compare the two. State what the dashboard shows when the stream is delayed, so users are never misled by silent staleness. Keep the output to a single page that a peer could review in ten minutes without your help.
Requirements
- •Show the streaming and batch paths
- •Define the windowing and late data rules
- •Explain how the two paths are reconciled
Constraints
- •Events may arrive up to ten minutes late
- •Finance numbers are the source of truth
Must Cover
Trade-off Axis
freshness vs correctness
Referenced Patterns
Competencies Advanced
Ready to Design?
Open this day in the Design Studio. The studio follows this track: its days, concepts, patterns and trade-offs are loaded, and you keep one design across the whole track.
Open in Studio →