Apache Spark data mechanics and RDD architecture explained
Apache Spark utilizes Resilient Distributed Datasets (RDDs) as its architectural foundation to manage fault-tolerant data workflows via directed acyclic graphs. The system supports various languages including Python through PySpark and provides high-speed machine learning via MLlib.
Apache Spark uses the resilient distributed dataset (RDD) as its architectural foundation. These RDDs are a read-only multiset of data items that a cluster of machines maintains in a fault-tolerant way. The system manages the workflow as a directed acyclic graph (DAG) where nodes are RDDs and edges are the operations on those RDDs. Because RDDs are immutable and their operations are lazy, the system achieves fault-tolerance by keeping track of the lineage of each RDD, which is the sequence of operations that produced it, so the system can reconstruct it in the case of data loss. The RDD technology is the basis for the Dataset API and provides a restricted form of distributed shared memory for distributed programs, and these RDDs can contain any type of Python, .NET, Java, or Scala objects. Spark developers introduced PySpark in February 2013 to allow users to write Spark applications in Python. This version provides an interactive shell for exploratory analysis while executing under the standard CPython runtime. Communication between the Python user code and Spark’s JVM-based core is mediated by the Py4J library. The pandas-compatible API, known as pandas API on Spark, arrived in October 2021 after its origin as the Koalas project, which Databricks open-sourced in 2019.
Core functions and cluster management
Spark Core handles task dispatching, scheduling, and basic I/O functionalities. A driver program invokes parallel operations such as map, filter, or reduce on an RDD by passing a function to Spark. The system then schedules the execution of that function in parallel on the cluster. For cluster management, Spark supports standalone native Spark, Hadoop YARN, Apache Mesos, or Kubernetes. The software interfaces with many distributed systems, including the Hadoop Distributed File System (HDFS), Cassandra, or Amazon S3. The creation of Spark and its RDDs was a response to the linear dataflow structure of MapReduce. This design helps with iterative algorithms, such as the training algorithms for machine learning systems. These algorithms visit a data set multiple times in a loop. Spark MLlib is a distributed machine-learning framework on top of Spark Core. It is nine times as fast as the disk-based implementation used by Apache Mahout. MLlib includes algorithms for classification and regression, such as support vector machines and logistic regression, as well as cluster analysis like k-means and dimensionality reduction. GraphX is also a distributed graph-processing framework that is based on RDDs. This framework provides two separate APIs for implementation of massively parallel algorithms, including the Pregel abstraction and a MapReduce-style API. Spark can be deployed in a traditional on-premises data center or in the cloud.
Advanced APIs and connectivity
Spark SQL introduces the DataFrame data abstraction to provide support for structured and semi-structured data. This component provides a domain-specific language (DSL) to manipulate DataFrames in Scala, Java, Python, or .NET. Spark SQL provides SQL language support and command-line interfaces alongside an ODBC/JDBC server. Spark Structured Streaming uses the scheduling capability of Spark Core to perform streaming analytics. This system ingests data in micro-batches and performs RDD transformations on those micro-batches. Apache Spark 4.x added a Real-Time Mode (RTM) execution model for Structured Streaming to lower end-to-end latency for operational and batch workloads. Spark Structured Streaming carries a penalty of latency equal to the mini-batch duration. Spark Connect, which arrived in version 3.4, uses a decoupled client-server architecture that enables remote connectivity from any environment. The client is a thin library that can be embedded in application servers, IDEs, notebooks, and other programming environments. The client translates DataFrame operations into unresolved logical query plans and encodes them using Protocol Buffers, which it then transmits to the server over the gRPC framework to ensure efficient communication. The server translates these plans into Spark’s logical plan operators and executes them through the standard Spark execution pipeline. Results are streamed back to the client as Apache Arrow-encoded row batches. Can developers achieve even more efficient dataflows with the introduction of Spark Declarative Pipelines?
Join the discussion