Real architecture · Staff
Spark and Storm: after MapReduce (Lambda and Kappa architectures)
Real production architecture. Key points: stream processing semantics.
Short answer
Real production architecture. Key points: stream processing semantics. In the cluster analytics frameworks of the RDD paper's era, such as MapReduce, reusing data between two computations had a high cost: in most of them, the only way was to write the result to an external stable storage system, such as a distributed file system.
01 · CONTEXT
What MapReduce left unanswered
In the cluster analytics frameworks of the RDD paper's era, such as MapReduce, reusing data between two computations had a high cost: in most of them, the only way was to write the result to an external stable storage system, such as a distributed file system. That path brings replication, disk I/O and serialization overhead.
Spark was born from this limitation. The paper that introduces it starts from two classes of application that the frameworks of the time handled inefficiently: iterative algorithms and interactive data mining tools. Spark's answer to these two classes is the starting point of this case, which continues through to stream processing.
02 · RDDS AND LINEAGE
In-memory data without paying for replicas
To reuse data between two computations, most frameworks of the time required writing it to external stable storage.
With RDDs, the user can explicitly ask for intermediate results to stay persisted in memory.
If a partition of an RDD is lost, the RDD has enough information about how it was derived from other RDDs to recompute only that partition.
Fault tolerance comes from recording the transformations used to build the dataset, the lineage, instead of the data itself.
The trick is in the interface. RDDs offer coarse-grained transformations, such as map, filter and join, which apply the same operation to many items. In fine-grained state update interfaces, the only ways to tolerate failures are to replicate the data across machines or to log the updates across machines.
03 · MICRO-BATCH STREAMING
Spark Streaming: the stream becomes a sequence of batches
The RDD paper itself points to the path of periodic batch processing: applications that update a result with new data, such as ad click statistics every 15 minutes, combining the state of the previous window with the new logs. The systems of this kind cited in the paper keep application state in distributed file systems, and the next step, in this case, is to see how Spark Streaming handles this flow in data pipelines.
Spark Streaming receives live data streams, from sources such as Kafka and Kinesis, and divides them into batches.
Each batch is processed by the Spark engine, and the stream of results also comes out in batches.
To avoid losing data already received, Spark introduced write-ahead logs; with them and with reliable receivers there is no data loss, and the semantics are at-least-once.
For end-to-end exactly-once, every processing stage needs to offer that guarantee, including delivery to the destination.
04 · STORM
Topologies that run forever
In Storm, the application logic is a topology: a graph of spouts and bolts connected by stream groupings, which runs forever, unlike a MapReduce job.
The stream is an unbounded sequence of tuples, processed and created in parallel in a distributed way.
A tuple that left the spout is considered fully processed when the tuple tree has been exhausted and all the messages in the tree have been processed.
If the tree is not fully processed and the tuple times out, Storm calls the fail method on the spout; with anchored tuples, the root tuple is re-emitted.
| Aspecto | Spark Streaming | Storm |
|---|---|---|
| Abstraction | Discretized stream (DStream), processed in batches by the Spark engine | Unbounded stream of tuples in a topology of spouts and bolts |
| Execution | Batches processed by the Spark engine, with output also in batches | Topology that runs forever, unlike a MapReduce job |
| Garantias | Exactly-once transformation thanks to RDDs; reception depends on the source | Best effort, at-least-once and, with Trident, exactly-once |
05 · PROCESSING SEMANTICS
Exactly once, but where?
In the Spark Streaming documentation, the processing of any stream has, broadly, three stages. In the transformation stage, all received data is processed exactly once, thanks to the RDD guarantees, as long as the received input data remains accessible. In reception, each input source offers different guarantees, and so the end-to-end guarantee depends on all the stages.
In Storm, the page on processing guarantees describes the at-least-once level based on the tuple tree, the timeout that generates failure and the re-emission of the root tuple.
06 · LAMBDA ARCHITECTURE
Two layers for fast, correctable queries
Events arrive at a master dataset of immutable data, which only receives appends.
The batch layer precomputes queries over the whole dataset, the easiest way to make them fast.
Data older than a few hours is already in the batch views; the real-time layer precomputes queries only for the last few hours.
To respond, the service queries the batch view and the real-time view and merges the results.
An error in the real-time layer is corrected by the batch layer, which ends up overwriting what the real-time layer computed.
The same design provides a path for correction. If a query has a bug, just fix it, deploy the fixed version and recompute everything from the master dataset; and, since the data is immutable and the dataset only receives appends, writing bad data does not overwrite or destroy good data.
07 · CURRENCY
What has changed since then
The current Spark documentation describes Spark Streaming (DStreams) as the previous generation of Spark's streaming engine.
Frequently asked questions
What is Spark and Storm: after MapReduce (Lambda and Kappa architectures)?
Real production architecture. Key points: stream processing semantics.
What does the Spark and Storm: after MapReduce (Lambda and Kappa architectures) design cover?
It is organized in these sections: What MapReduce left unanswered, In-memory data without paying for replicas, Spark Streaming: the stream becomes a sequence of batches, Topologies that run forever, Exactly once, but where?, and Two layers for fast, correctable queries.
How long is Spark and Storm: after MapReduce (Lambda and Kappa architectures) and what level is it?
It takes about 18 minutes to read and is rated Staff level.
Now design it yourself
Run this case as an interview in the System Design school: you make the decisions, the tutor challenges them and you see how your design scores.