Let’s Get Certified
Module 02 / 13 · Spark architecture and components

Place work in a Spark application

Explain where a query is planned, where partitions are processed and when persistence pays off.

Place work in a Spark application

Work through the decision

A notebook collects 300 million ticket events and then groups them in Python. Its driver fails while the executor dashboard looks mostly idle. Would doubling executor memory solve the underlying design?

Check your reasoning

Keep the data distributed. Express the grouping as a DataFrame aggregation and collect only the bounded summary if a local result is needed. The driver owns application coordination and planning. Executors run tasks on partitions and hold shuffle or cached data. A cluster manager allocates resources. Adding executor memory cannot make an unbounded driver result safe.

Watch the source lesson at 3:44

Compare the choices

Driver
Construct and coordinate the application’s work and receive results requested locally. Keep driver-side result sizes bounded.
Executor
Run tasks on worker resources and retain partition data where the plan or chosen storage level requires it. Distinguish the executor process from its host.
SparkSession
Use the session as the entry point for DataFrame and SQL operations. Stop an application-owned session when its work is complete.
Persistence
Retain partitions of a repeatedly used intermediate under a chosen storage level. Materialize with an action and release them when no longer needed.
Distributed aggregation
Perform grouped computations on distributed data and bring back only the bounded result. Watch grouping cardinality and shuffle size.

Test the decision

A SparkSession gives the application a structured API for reading data and building plans. Python exposes DataFrames, while Scala and Java also provide the strongly typed Dataset API. Persist a reused intermediate only when the saved recomputation justifies storage. The first action materializes cached partitions and unpersist releases that storage when reuse ends.

Read memory pressure in the Spark UI

Compare storage use, task GC time and spill for a repeated action. Garbage collection reclaims unreachable JVM objects. Cached blocks retain storage while useful or until evicted. If caching an intermediate increases GC time without reducing runtime, unpersist it and rerun. A disk-backed storage level can save recomputation when some partitions exceed available memory. Re-run the same input before deciding.

Apache Spark · memory and garbage collection

Practice the guide skills

  1. Compare processing a 10 KB lookup with aggregating 500 GB of events and identify when scheduling overhead pays off. Watch 3:44 · Continue at 5:41
  2. Draw a driver and two workers, assign executor cores and identify which process must hold a collected result. Watch 9:35 · Continue at 10:40
  3. Create a SparkSession, choose a persistence level for a reused DataFrame, trigger an action and compare storage and garbage-collection metrics before and after unpersist. Watch 15:04 · Continue at 16:25 · Continue at 17:05 · Continue at 18:40

Official objectives for this lesson

Related lesson · Compute and cluster types

Knowledge check

Place work in a Spark application quiz

Answer 3 questions. Check each answer for an explanation.