The Dataflow Model: A Practical Approach to Balancing Correctness, Latency, and Cost in Massive-Scale, Unbounded, Out-of-Order Data Processing.
"practicality dictates that one can never fully optimize along all dimensions of correctness, latency, and cost for these types of input."
"We as a field must stop trying to groom unbounded datasets into finite pools of information that eventually become complete, and instead live and breathe under the assumption that we will never know if or when we have seen all of our data, only that new data will arrive, old data may be retracted, and the only way to make this problem tractable is via principled abstractions that allow the practitioner the choice of appropriate tradeoffs along the axes of interest: correctness, latency, and cost."
Many current streaming platforms "lack the ability to provide exactly-once semantics"
What is that?
... "or provide windowing semantics that are limited to tuple- or processing-time-based windows"
"MillWheel and Spark Streaming are both sufficiently scalable, fault-tolerant, and low-latency to act as reason- able substrates, but lack high-level programming models that make calculating event-time sessions straightforward."
Shortcoming of all systems up until now:
"they focus on input data (unbounded or otherwise) as something which will at some point become complete. We believe this approach is fundamentally flawed when the realities of today's enormous, highly disordered datasets clash with the semantics and timeliness demanded by consumers."
Model
"Allows for the calculation of event time ordered results, windowed by features of the data themselves, over an unbounded, unordered data source, with correctness, latency, and cost tunable across a broad spectrum of combinations."
Four relevant dimensions:
- What results are computed?
- Where in event time are they being computed?
- When in processing time they materialized
- How can earlier results relate to later refinements?
Components
- Windowing model
- Support unaligned event-time windows
- Triggering model
- Binds output times of results to runtime characteristics of the pipeline
- Incremental processing model
- Updates previous two
etc.
Explanation of components and terminology
Windowing
- "slices up a dataset into finite chunks for processing as a group"
- Always time based.
- Windows may be either
- aligned: applied across all data from a time window
- unaligned: only across specific subsets of data in the time window (e.g. some keys only)
Three window types:
- Fixed
- e.g. process everything hourly
- Generally aligned
- Special case of sliding window where size equals sliding period.
- Sliding, have a fixed window size but also a sliding period
- E.g. hourly windows that start every minute.
- Thus may overlap with other windows
- Also generally aligned, i.e. applied to all data in the sliding window
- Sessions
- Capture period of activity over subset of the data
- Per key, so unaligned windows
- Usually defined by a timeout gap; session ends when timeout gap is reached.
Time Domains
- Event time
- Time of occurrence of the event itself
- Processing Time
- When is the event observed during processing in the pipeline
The time between event time and processing time differs depending on a lot of factors.
For keeping track of this time you can use watermarks.
Watermark:
- Lower bound on event times that have been processed by the pipeline (heuristic, often not 100% correct)
- Simply: at what point in processing time is data from point e1 in event time processed?
- How long does it take before data from event time t1 is processed?
- Useful indication for when the system thinks it is likely that all data up to a given point in event time has been processed.
Dataflow
Assigning windows
Instead of (key, value) pairs, use (key; value; event time; window).
"In this case, each of the two (key; value) pairs is duplicated to exist in both of the windows that overlapped the element's timestamp."
So imagine we have an event (k, v1, 12:00, /[0,->)).
- By default each event is assigned to the complete event time window
- Assign sliding windows of 2m with a 1m slide
Results in:
- (k, v1, 12:00, [11:59, 12:01])
- (k, v1, 12:00, [12:00, 12:02])
Window Merging for
- GroupByKey: key could be a user for example.
- We now have per key a number of values with windows.
- If any of these windows overlap, we merge then into one bigger window representing a single big session.
- After merging we want to groupByWindow as well, to aggregrate the values that now share the same merged window.
- Assign a new timestamp to a time in the window, for watermarking purposes.
Triggers & Incremental Processing
Data is unordered w.r.t. event time, i.e. data from earlier times may come in relatively late w.r.t. data from later times.
So the question is: when are we done with processing a window? When can we emit results?
Problems with Watermarks
Assume we use a watermark as a trigger for deciding when a window is done
- Sometimes too fast
- Very late data might arrive behind the watermark
- Sometimes too slow
- If a single data point is very slow, the watermark will be delayed much
- But since this would be a trigger for emitting results, this would delay the whole pipeline and increase latency
Results are GroupByKeyAndWindow results.
Approach, give for any given window a fast good-enough group of results that is called a pane. At this point do not ensure correctness.
Ensure correctness only after a whole batch is done processing.
- So windowing determined grouping in event time
- Triggering determines when in event time results of groupings are emitted as panes.
N.B. Watermarks are lower bounds on event times that have been processed When we use a trigger on any knowledge about processing time, we speak of feature triggers.
How do panes of the same window relate to each other?
1) Discarding * Trigger throws away window contents * Trigger files are thus independent * Efficient but not suitable for all applications 2) Accumulating * Refinements of later triggers refine the previous intermediate pane results. 3) Accumulating and Retracting
When are retractions necessary?
"Retractions are necessary in pipelines with multiple serial GroupByKeyAndWindow operations, since the multiple results generated by a single window over subsequent trigger fires may end up on separate keys when grouped downstream."
The second grouping operation will then have incorrect results. Why?
Therefore retraction of the original output should be reversed.
Example case for retraction:
"If we are performing aggregations downstream from session creation that depend on properties of the sessions themselves, for example detecting unpopular ads (such as those which are viewed for less than five seconds in a majority of sessions), initial results may be invalidated as inputs evolve over time, e.g. as a significant number of offline mobile viewers come back online and upload session data.
For examples in the paper: remember that the watermark is on the processing time axis, and triggers when it is passed in processing time.
See slides for the example graphs.