Spark / RDDs
MapReduce was good but required more complexity for multi-stage application (lacks efficient primitives for data sharing) and interactive ad-hoc queries.
The challenge is to design a distributed memory abstraction that is fault tolerant AND efficient.
1. Resilient Distributed Datasets
RDDs store data lineage instead of data (can be used for recovery). They are partitioned across nodes, immutable, only allow coarse-grained operations (e.g. map, filter, reduceByKey), and are lazily evaluated.
These can unify many programming models (e.g. MapReduce, iterative algorithms, graph processing, streaming).
2. Lineage Graph
The lineage of RDDs is represented as a DAG. Each RDD has a narrow or wide dependency on its parent RDDs:
- Narrow: each partition of the parent RDD is used by at most one partition of the child RDD. This allows pipelining and avoids shuffling. (e.g.
map,filter,union,sample,coalesce). - Wide: multiple child partitions may depend on a single parent partition. This requires shuffling and is more expensive. (e.g.
groupByKey,reduceByKey,join,cogroup).
Fault tolerance is achieved by recomputing lost partitions using the lineage graph. This is more efficient than replication, but may be slower for wide dependencies. Spark also allows manual checkpointing of RDDs to avoid long lineage chains.