Let’s Get Certified
Module 12 / 13 · Spark Connect and deployment

Separate Spark Connect from deployment mode

Locate the client, driver and executors and decide which objects may cross the boundary.

Separate Spark Connect from deployment mode

Work through the decision

An analyst’s Python client connects to a remote Spark service. The laptop constructs a DataFrame expression, then disconnects while retrieving a large result. Which part of the computation was local?

Check your reasoning

Spark Connect sends a representation of an unresolved logical plan to the remote server, where Spark analyzes, optimizes and executes it. Returned results travel to the client, typically in Arrow batches. Remote execution does not remove client memory limits when the user requests every row. Prefer functions supported by Connect and avoid assuming local access to driver internals or SparkContext.

Watch the source lesson at 2:21:12

Compare the choices

Connect client
Build and submit a logical plan through the client protocol and consume results. A thin client can be separate from the remote Spark driver.
Connect server
Receive the client plan and use the remote Spark environment to analyze, optimize and execute it. Check server-side catalog and resource availability.
Cluster deploy mode
Ask the cluster manager to launch the application driver within the cluster. Check access to driver logs and dependency distribution.
Client deploy mode
Run the application driver with the submitting client while executors run on the cluster. Maintain reliable connectivity for that driver.

Test the decision

Distinguish client/server API separation from scheduler deploy mode. In client deploy mode the driver runs with the submitting client process or host. In cluster deploy mode the cluster manager launches the driver in the cluster. Local mode executes locally for development. Specify where code, dependencies, storage and network access must exist for the chosen mode.

Trace a remote action

For a Spark 4.0.1 Connect server, install the Python client dependencies with python -m pip install "pyspark[connect]==4.0.1" in your active environment. Use the endpoint provided by the server administrator.

from pyspark.sql import SparkSession
# Replace spark-server with the address of an existing Spark Connect server.
remote = SparkSession.builder.remote("sc://spark-server:15002").getOrCreate()
print(remote.range(10).where("id >= 7").count())
remote.stop()
Check the result

The client builds a logical plan and sends it to the server. The server executes the filtered count and returns the scalar 3. Replace count with collect on a large result and the transfer to the client becomes a material constraint.

Practice the guide skills

  1. Trace an unresolved logical plan from a Connect client to its server and identify how a small result returns. Watch 2:21:12
  2. Place the driver for client and cluster deployments and explain what changes when running in local mode. Watch 2:23:30 · Continue at 2:24:44

Official objectives for this lesson

Related lesson · Compute and cluster types

Knowledge check

Separate Spark Connect from deployment mode quiz

Answer 3 questions. Check each answer for an explanation.