Spark Core Concepts Flashcards

(43 cards)

1
Q

What is Apache Spark at a high level?

A

A distributed data processing engine that executes computations in parallel across a cluster, supporting batch, streaming, SQL, and ML workloads.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How does Databricks relate to Spark?

A

Databricks provides a managed, optimized Spark runtime with additional services like notebooks, jobs, Delta Lake, and governance tooling.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Spark application on Databricks?

A

A program (notebook, job, script) that uses Spark to process data on a Databricks cluster.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the two main node roles in a Spark cluster?

A

The driver node, which coordinates the application, and worker nodes, which execute tasks on partitions of the data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the driver in Spark?

A

The process that runs the main application code, builds the logical plan, and schedules tasks on worker nodes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an executor in Spark?

A

A process running on a worker node that executes tasks and holds data partitions in memory or on disk.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a Spark RDD (Resilient Distributed Dataset)?

A

An immutable, distributed collection of records that can be processed in parallel and recomputed from lineage information.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why are RDDs rarely used directly in Databricks for most workloads now?

A

Higher-level APIs like DataFrames and Spark SQL provide better optimization, safety, and convenience for structured data.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a Spark DataFrame?

A

A distributed, tabular data structure with named columns and a schema, similar to a table in a relational database.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do DataFrames relate to Spark SQL?

A

Spark SQL queries operate on DataFrames, and DataFrames can be registered as temporary views to be queried with SQL.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Why are DataFrames usually preferred over RDDs in Databricks?

A

They enable the Catalyst optimizer to plan and optimize queries, often yielding better performance with less code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a transformation in Spark?

A

An operation that defines a new dataset from an existing one, such as select, filter, map, or join, without triggering execution.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is an action in Spark?

A

An operation that triggers execution and returns a result to the driver or writes data out, such as count, collect, show, or write.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does it mean that Spark has lazy evaluation?

A

Transformations build a logical plan but nothing is actually executed until an action is called, allowing global optimization.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a DAG (Directed Acyclic Graph) in Spark?

A

A graph of stages and operations that represent the logical execution plan of transformations leading up to an action.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Why does Spark use DAGs instead of a fixed MapReduce pattern?

A

DAGs allow more complex multi-stage workflows and better optimization across chained transformations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What is a stage in Spark execution?

A

A set of tasks that can be executed without reshuffling data, separated by shuffle boundaries in the DAG.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a task in Spark execution?

A

A unit of work that processes one partition of the data for a specific stage on an executor.

19
Q

What is a partition in Spark?

A

A chunk of the dataset that is processed as a unit by a single task on one executor, supporting data parallelism.

20
Q

Why is the number and size of partitions important?

A

Too few partitions underutilize the cluster; too many create overhead in scheduling and task management.

21
Q

What is a shuffle in Spark?

A

A data movement operation where records are redistributed across partitions, typically for joins, groupBy, or aggregations by key.

22
Q

Why are shuffles expensive operations?

A

They involve network transfer, disk I/O for intermediate data, and additional coordination, often dominating job runtime.

23
Q

How can you reduce shuffles in Spark jobs?

A

By avoiding unnecessary groupBy/join operations, pre-partitioning data appropriately, and reusing partitioning where possible.

24
Q

What is a wide transformation?

A

A transformation that requires data from many partitions, such as groupByKey, and usually triggers a shuffle.

25
What is a narrow transformation?
A transformation like map or filter where each output partition depends on data from a single input partition, avoiding shuffles.
26
What is caching (persisting) in Spark?
Storing intermediate DataFrames or RDDs in memory (and optionally disk) so they can be reused without recomputation.
27
Why is caching useful in Databricks notebooks?
Interactive analysis often reuses the same intermediate data; caching speeds up subsequent actions on that data.
28
What is the difference between `cache()` and `persist()` in Spark?
`cache()` uses a default storage level (usually memory-only), while `persist()` allows specifying different storage levels (e.g., memory-and-disk).
29
Why should caching be used judiciously?
Caching too many or very large datasets can exhaust executor memory and lead to spills or eviction of useful data.
30
What is a broadcast variable or broadcast join?
A mechanism to send a small dataset to all executors so that large datasets can be joined locally without shuffling both sides.
31
When is a broadcast join appropriate in Databricks?
When one side of the join is small enough to fit in memory on each executor, significantly reducing shuffle cost.
32
What is the Catalyst optimizer?
Spark SQL’s query optimizer that analyzes logical plans, applies rules, and generates optimized physical execution plans.
33
Why is understanding Catalyst helpful even if you write only SQL/DataFrames?
It explains why certain query patterns are faster, how filters and projections are pushed down, and when joins or shuffles occur.
34
What is Tungsten in Spark runtime?
An optimization project focusing on memory management and code generation for efficient binary processing of data.
35
How does Databricks enhance Spark’s optimizer/runtime?
Through runtime improvements, cost-based optimizations, and Delta Lake-specific features like data skipping and file pruning.
36
What is a SparkSession in Databricks?
The entry point for Spark functionality, exposed as 'spark' in Databricks notebooks and used to create DataFrames, run SQL, and manage configs.
37
How do you typically create a DataFrame from a Delta or Parquet table in Databricks?
By using `spark.read.format('delta' or 'parquet').load(path)` or `spark.table('db.table_name')`.
38
What is the difference between `DataFrame.show()` and `DataFrame.collect()`?
`show()` prints a limited number of rows for inspection, while `collect()` retrieves all results to the driver, which can be dangerous for large datasets.
39
Why is calling `collect()`on large datasets a pitfall?
It can overwhelm driver memory and crash the application; large results should be written to storage or inspected with limited samples.
40
What is the effect of using `display()` in Databricks notebooks?
It triggers an action similar to `show()` but with richer visualization; it still executes a job under the hood.
41
How can you inspect the physical plan of a DataFrame or SQL query in Databricks?
By using `df.explain()` or `EXPLAIN` in SQL, optionally with 'EXTENDED' or 'CODEGEN' flags to see detailed plans.
42
Why is examining `explain()` output useful for engineers?
It reveals where scans, filters, joins, and shuffles occur, guiding performance tuning and schema or query changes.
43
What is a good mental model for Spark on Databricks from a data engineer’s perspective?
Write transformations in DataFrames/SQL, let Spark build a DAG, be conscious of partitions and shuffles, cache deliberately, and always think about what triggers actions and where data moves.