Practice 45 Spark interview questions on RDDs, DataFrames, Spark SQL, Catalyst, shuffles, joins, caching, partitioning, Structured Streaming, and tuning.
45 questions with answersKey Takeaways
Apache Spark is a distributed processing engine used for large-scale batch jobs, SQL analytics, streaming pipelines, and machine learning workloads. In interviews, Spark questions test whether you understand how driver code becomes jobs, stages, and tasks, why shuffles are expensive, how joins are planned, and how to debug slow or failing applications.
Watch: Using Apache Spark to analyze open data
Video: Using Apache Spark to analyze open data (Databricks, YouTube)
Test yourself and earn a certificate
6 quick questions. Score 70%+ to download your Spark certificate.
Start here. These are the definitions and first-principle checks that open most rounds.
The driver runs the application, builds the execution plan, requests resources, schedules tasks, and collects results back to the application when needed.
Do not collect large data to the driver. That is a common production failure.
Watch a deeper explanation
Video: Using Apache Spark to analyze open data (Databricks, YouTube)
An executor is a worker process that runs tasks, stores cached data, and reports status back to the driver.
Executor sizing affects parallelism, memory pressure, garbage collection, and task failures.
Executor changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
An action creates a job. Spark splits the job into stages at shuffle boundaries, then runs tasks for partitions inside each stage.
This is the core execution model the question expects you to explain.
Job, stage, task changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Spark execution path
A shuffle boundary usually creates a new stage.
Spark records transformations without executing them until an action is called.
Lazy evaluation lets Spark optimize the whole plan before running it.
Lazy evaluation changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
| Answer part | What to say | Evidence to mention |
|---|---|---|
| Definition | Lazy evaluation in one direct sentence. | Official docs or course material |
| Use case | The work where it changes a decision. | Dataset, model, query, dashboard, or pipeline |
| Risk | What breaks when it is misunderstood. | Metric, log, test result, or review note |
A transformation creates a new logical dataset, while an action triggers execution and returns or writes a result.
Examples: select and filter are transformations. count, collect, and write are actions.
Transformation and action changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: Fundamentals of Apache Spark and Azure Databricks (Microsoft Developer, YouTube)
A narrow dependency means each output partition depends on a small set of input partitions and usually avoids a shuffle.
map and filter are common examples.
Narrow dependency changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A wide dependency means output partitions need data from many input partitions, usually causing a shuffle.
groupBy, reduceByKey, joins, and repartition often create wide dependencies.
Wide dependency changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A shuffle redistributes data across executors, causing network transfer, disk spill, serialization, and stage boundaries.
Reducing shuffle size is often the fastest performance win.
Shuffle changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Catalyst is Spark SQL's optimizer. It analyzes logical plans, applies rules, and creates optimized physical plans.
Mention predicate pushdown, column pruning, join planning, and explain output.
Catalyst optimizer changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Tungsten improves Spark execution through memory management, binary processing, and code generation.
It is one reason DataFrames can be faster than hand-written RDD logic.
Tungsten changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A partition is a slice of data processed by one task.
Partition count affects parallelism, task overhead, shuffle size, and output file count.
Partition changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Cache data when the same expensive intermediate result is reused across multiple actions or branches.
Caching too much data can evict useful blocks or cause memory pressure.
Cache and persist changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A broadcast join sends a small table to each executor so the large table does not need a full shuffle join.
It works only when the broadcast side fits memory.
Broadcast join changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: Apache Spark architecture explained (Databricks, YouTube)
Structured Streaming is Spark's streaming API that processes continuous data using DataFrame-style queries.
Interviews focus on triggers, checkpoints, output modes, state, watermarks, and exactly-once claims.
Structured Streaming changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Checkpoints store progress and state so streaming jobs can recover after failure without starting from scratch.
Without reliable checkpoints, stateful streaming recovery is unsafe.
Checkpoint changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
These questions test whether you can apply the topic to real data, real code, and messy constraints.
Spark builds a logical plan, optimizes it with Catalyst, creates a physical plan, splits work into jobs, stages, and tasks, then runs tasks across executors.
every stage boundary maps to a shuffle or action.
# Interview check: split data, run baseline, inspect metric
from sklearn.metrics import accuracy_score
print(accuracy_score(y_true, y_pred))Select needed columns, filter early, use partition pruning, avoid unnecessary UDFs, and inspect the physical plan.
Column pruning and predicate pushdown are the key points.
read Parquet efficiently changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check Spark UI stages, task duration, shuffle read and write, spill, skew, input size, executor failures, and file counts.
measured bottlenecks before changing code comes first.
debug a slow job changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check table sizes, join keys, statistics, skew, partitioning, and whether one side can be broadcast.
Broadcast small dimensions. Avoid forcing broadcast when it does not fit memory.
choose join strategy changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Find hot keys, salt large hot keys, split the hot path, broadcast small tables, or enable adaptive skew handling when available.
Skew is visible as a few long tasks in the Spark UI.
handle skewed joins changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Filter early, select fewer columns, pre-aggregate, use broadcast joins, avoid unnecessary repartition, and choose sensible partition counts.
The best shuffle is the one you do not create.
reduce shuffle changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use data size, cluster parallelism, task duration, shuffle size, and output file target size.
Too few partitions underuse the cluster. Too many create task overhead and small files.
set partitions changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Cache only if the DataFrame is reused and expensive to recompute, then unpersist when it is no longer needed.
Confirm cache actually reduces work in the UI.
cache correctly changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check spill, cached data, wide rows, collect calls, skew, executor sizing, and serialization.
Increasing memory may hide the issue but not fix bad data movement.
fix memory errors changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Set partition count before write, avoid over-partitioning, compact small files, and choose a file format suited to analytics.
Output files often become the next team's query problem.
write output files changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Watch a deeper explanation
Video: Spark Structured Streaming concepts (Databricks, YouTube)
Read from Kafka, parse and validate events, apply event-time logic, set watermarks if stateful, write to an idempotent sink, and checkpoint to reliable storage.
Mention bad records, schema changes, and restart behavior.
build a streaming pipeline changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Use event time, watermarks, state windows, and a business rule for when data is too late to update.
Late data is a product decision as much as a technical one.
handle late events changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Look for scans, filters, exchanges, joins, broadcast decisions, pushed filters, column pruning, and adaptive execution changes.
Exchange usually means data movement.
use explain changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
A Python UDF can block Catalyst optimization and add serialization overhead, so prefer built-in functions when possible.
UDFs are not forbidden, but they need a reason.
replace UDF changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Advanced rounds test trade-offs, failure modes, and whether the decision can hold up under production pressure.
Too much data was pulled to the driver.
Use distributed writes, limit for inspection, or aggregate before collecting.
collect crash changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Data skew, large partition, slow node, or uneven input split.
Check task input size, shuffle read, and executor host in the UI.
one slow task changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Do not broadcast that table, reduce the broadcast side, raise threshold only if memory supports it, or use a shuffle join with better partitioning.
Broadcast joins are fast only when the small side is truly small.
It slows downstream reads and creates metadata overhead.
Repartition or compact to target file sizes before publishing.
small files after write changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check partition filters, pushed filters, selected columns, file format, table stats, and whether UDFs block optimization.
A missing date filter can turn a cheap query into a full scan.
slow Spark SQL query changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
It may not be reused, may not fit memory, may be evicted, or the expensive step is elsewhere.
Storage tab and stage timing show whether cache helped.
cache no benefit changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check input rate, processing rate, trigger time, state size, sink latency, partitions, skew, and checkpoint health.
Increasing cluster size is only one possible fix.
streaming lag changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
The sink or write logic is not idempotent, or checkpoint handling is wrong.
Exactly-once behavior depends on source, sink, checkpoint, and write pattern.
duplicate streaming output changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
groupBy creates a shuffle. Reduce input, pre-aggregate, fix skew, and choose partitions carefully.
Explain what data moves across the network.
wide transformation changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
They may be bypassing Catalyst optimization and writing more code than needed.
RDDs still fit custom low-level logic, but structured analytics usually fits DataFrames or SQL.
RDD versus DataFrame changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check schema enforcement, reader options, downstream selects, table contracts, and compatibility rules.
Additive changes are easy only when code and contracts allow them.
schema drift changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Check memory overhead, container limits, spill, node health, logs, and shuffle fetch failures.
Executor loss can be infrastructure, memory, or shuffle related.
executor lost changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
High-cardinality partitions create too many directories and small files.
Date or event time is often a better top-level partition for analytics.
bad partition key changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
It can adjust join strategy, coalesce shuffle partitions, and handle skew based on runtime statistics.
It helps, but it does not replace good data layout.
adaptive query execution changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Clear inputs, schema checks, idempotent writes, monitoring, alerting, retries, checkpoints where needed, and documented ownership.
A working notebook is not the same as an operated pipeline.
production readiness changes Spark decisions by affecting the chosen method, the failure mode, or the validation step. Reliable evidence comes from a metric, test result, query output, log, or review note.
Spark has multiple APIs. the question expects you to know when low-level control is useful and when optimized relational execution is the better choice.
| API | Best use | Optimizer support | Interview warning |
|---|---|---|---|
| RDD | Low-level transformations and custom control | Limited | Verbose and easy to make slow |
| DataFrame | Structured data with columns and schemas | Catalyst and Tungsten | Still needs good partition and join choices |
| Spark SQL | SQL analytics and warehouse-style work | Catalyst and cost-based rules | Query text can hide bad scans or shuffles |
| Dataset | Typed API mainly used in Scala and Java | Catalyst with type safety | Less common in PySpark rounds |
Spark answer signals
execution reasoning more than API recall is the technical point.
Prepare by tracing a Spark application from code to physical execution. A good coverage names the API, shows the plan, identifies the shuffle, and explains the production risk.
Spark interview prep flow
Most rounds reward clear reasoning more than memorized phrasing.
A strong Spark answer starts with the data shape and the execution plan. Say what is being read, how it is partitioned, where the shuffle happens, which join strategy is expected, and how you verified it in the Spark UI or with explain output. production-ready answers also discuss skew, memory pressure, checkpointing, file layout, retries, and cost.
Spark performance problems usually come from shuffles, skew, wide scans, bad joins, tiny files, or memory pressure.
Explain plans and the Spark UI are better evidence than guessing. Point to stages, task duration, shuffle read, spill, and input size.
Cache repeated expensive work. Do not cache one-time reads or data that does not fit memory.
Structured Streaming adds state, watermarks, triggers, sinks, and checkpointing. Batch tuning alone is not enough.
6 questions, about 4 minutes. Score 70% or higher to earn a shareable certificate.
Use this Spark bank for architecture and debugging answers, then practice SQL and Python exercises with Hyring's AI Coding Interviewer before the technical screen.
See Hyring AI Coding Interviewer