RDD
| Also known as | Resilient distributed dataset |
|---|---|
| Field | Distributed data processing |
| Key parts | Partitions, lineage of transformations, lazy transformations and actions, storage levels for persistence |
| Open source implementations | Apache Spark |
| Related | DataFrame, Dataset (Spark), Partition, Spark Connect, GraphX, Spark Streaming (DStreams) |
In Apache Spark, a resilient distributed dataset (RDD) is an immutable collection of elements split into partitions across the nodes of a cluster, which can be processed in parallel and is rebuilt from its lineage when a partition is lost.[2] The RDD was Spark's main programming interface before Spark 2.0; since then the Spark documentation recommends the Dataset and DataFrame APIs, which run through the Catalyst optimizer, while stating that the RDD interface is still supported.[3] RDDs still underlie older libraries such as GraphX and Spark Streaming (DStreams), but they are not available to Spark Connect clients.[1]
Status
The RDD API is not deprecated. The RDD class at the v4.3.0 tag of Spark carries no deprecation annotation, and the Spark 4.0.0 to 4.3.0 release notes list no deprecation of the RDD API.[4][5] Only single methods are deprecated; for example, PySpark's mapPartitionsWithSplit is deprecated in favor of mapPartitionsWithIndex.[6]
The practical limit is Spark Connect. The Spark Connect documentation lists SparkContext and RDD as unsupported for both Python and Scala clients.[1] In the PySpark Connect client, DataFrame.rdd raises a not-implemented error.[7] Code that uses RDDs therefore needs a classic Spark application, which is the default: spark.api.mode defaults to classic in Spark 4.3.0.[8]
How it works
An RDD is created from a file in a Hadoop-supported file system, from a collection in the driver program, or by transforming another RDD.[2] The design was described in the 2012 paper Resilient Distributed Datasets: A Fault-Tolerant Abstraction for In-Memory Cluster Computing by Matei Zaharia and others at the University of California, Berkeley.[9]
RDDs support two kinds of operations. Transformations, such as map and filter, return a new RDD. Actions, such as reduce and collect, return a value to the driver. Transformations are lazy: Spark records them and computes nothing until an action needs a result.[2] Each RDD is divided into partitions, and the executors process one partition per task.
Fault tolerance comes from lineage, the record of the transformations that built an RDD. If a partition is lost, Spark recomputes it from that record instead of restoring a replica.[2][9] An RDD can be kept for reuse with persist() or cache(); cache() uses the default storage level MEMORY_ONLY, and other storage levels keep the data serialized, on disk or replicated.[2]
RDD compared with DataFrame and Dataset
| RDD | DataFrame | Dataset | |
|---|---|---|---|
| Element type | Any JVM or Python object, opaque to Spark | Rows with a schema of named, typed columns | Typed JVM objects with an encoder (Scala and Java only) |
| Optimization | None by Spark SQL; the user's functions run as written | Spark SQL uses the schema to optimize the query | Spark SQL uses the schema to optimize the query |
| Languages | Scala, Java, Python | Scala, Java, Python, R | Scala, Java |
| Spark Connect | Not supported | Supported | Supported in the Scala client |
The Spark quick start recommends the Dataset over the RDD because it is strongly typed like an RDD but has better performance.[3] The Spark SQL guide describes the Dataset, added in Spark 1.6, as combining the benefits of RDDs (strong typing and lambda functions) with Spark SQL's optimized execution engine, and a DataFrame as a Dataset organized into named columns. Python and R have no Dataset API but use DataFrames.[10][1]
Where RDDs still appear
- Older libraries. GraphX represents graphs as RDDs, and a DStream in Spark Streaming (DStreams) is a sequence of RDDs.[11] The RDD-based machine learning package, spark.mllib (RDD-based API), is in maintenance mode.
- Low-level control. The RDD API gives direct control over partitioning and over functions applied to each element, which some programs use for work that does not fit a tabular schema.
- Execution internals. DataFrame and SQL queries also end up as RDDs: in Spark 4.3.0, executing a physical plan node (
SparkPlan.execute()) returns an RDD of internal rows.[12]
Example
A word count with the RDD API in PySpark, in classic mode:
from pyspark.sql import SparkSession
spark = SparkSession.builder.master("local[*]").getOrCreate()
sc = spark.sparkContext
lines = sc.parallelize(["a b", "b c", "c"])
counts = (lines.flatMap(lambda line: line.split())
.map(lambda word: (word, 1))
.reduceByKey(lambda a, b: a + b))
print(sorted(counts.collect())) # [('a', 1), ('b', 2), ('c', 2)]
The same result with the DataFrame API also runs through Spark Connect:
from pyspark.sql import functions as F
df = spark.createDataFrame([("a b",), ("b c",), ("c",)], ["line"])
df.select(F.explode(F.split("line", " ")).alias("word")).groupBy("word").count().show()
See also
References
- ↑ 1.0 1.1 1.2 1.3 Spark Connect Overview (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ 2.0 2.1 2.2 2.3 2.4 RDD Programming Guide (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ 3.0 3.1 Quick Start (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ RDD.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Spark Release 4.0.0. Apache Software Foundation.Retrieved 2026-11-22.
- ↑ python/pyspark/core/rdd.py (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ python/pyspark/sql/connect/dataframe.py (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Spark Configuration (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ 9.0 9.1 Resilient Distributed Datasets: A Fault-Tolerant Abstraction for In-Memory Cluster Computing. USENIX (NSDI 2012).Retrieved 2026-11-22.
- ↑ Spark SQL, DataFrames and Datasets Guide (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ Spark Streaming Programming Guide (Spark 4.3.0). Apache Software Foundation.Retrieved 2026-11-22.
- ↑ SparkPlan.scala (v4.3.0). Apache Software Foundation.Retrieved 2026-11-22.