Sample questions
Question 1Easy
In Spark, when are transformations actually executed?
- As soon as each transformation is written
- At the end of the program regardless of actions
- When the file is opened
- When an action is called
Answer: D. When an action is called
Explanation
Transformations build a DAG lazily; an action such as count or collect triggers the real computation.
Step-by-step solution
- Transformations build a plan.
- Action requests a result.
- Spark then runs the DAG.
Why the other options are wrong
- A. Transformations only record the plan.
- B. Execution requires an action.
- C. Opening does not trigger computation.
Question 2Easy
Spark transformations are evaluated lazily. This means:
- They run immediately when defined by default for every job
- Computation starts only when an action is called
- They run only on the driver for every job in current releases
- They are never executed
Answer: B. Computation starts only when an action is called
Explanation
Spark builds a DAG and executes it when an action needs a result.
Step-by-step solution
- Transformations such as map and filter only record the plan (the DAG).
- Nothing runs when a transformation is defined.
- Computation starts only when an action such as count or collect is called.
- So lazy evaluation means computation starts only when an action is called (option B).
Why the other options are wrong
- A. Transformations do not run when they are defined.
- C. Transformations do not run only on the driver; their tasks run on executors.
- D. Transformations do run when an action needs their result, so they are not never executed.
Tip: Transformations build the plan; actions run it.
Question 3Medium
What is the benefit of lazy evaluation in Spark?
- Spark can optimise the whole plan and pipeline narrow operations before running
- The code always runs faster on one machine because all of the data is always loaded into memory first
- Errors are impossible
- Data is not needed at all
Answer: A. Spark can optimise the whole plan and pipeline narrow operations before running
Explanation
Seeing the full lineage lets Spark pipeline operations and skip unneeded work.
Step-by-step solution
- Spark sees the full chain.
- It fuses narrow steps in one stage.
- Fewer passes over data.
Why the other options are wrong
- B. The benefit is plan-level optimisation.
- C. Errors surface later, at execution.
- D. Data is needed once an action runs.
Question 4Medium
A shuffle in Spark is best described as:
- Redistributing data across partitions, usually over the network
- Sorting data within one partition only in current releases on each node
- Compressing data on disk
- Re-reading the input file on each node by default
Answer: A. Redistributing data across partitions, usually over the network
Explanation
Shuffles move records between executors so that related keys end up together.
Step-by-step solution
- A shuffle happens when records must be regrouped, for example for a join or groupByKey.
- Records are sent between executors so that related keys end up in the same partition.
- This moves data over the network, which is costly.
- So a shuffle is redistributing data across partitions, usually over the network (option A).
Why the other options are wrong
- B. Sorting inside one partition does not move data between partitions, so it is not a shuffle.
- C. Compressing data on disk is not what a shuffle does.
- D. A shuffle does not re-read the input file on each node.
Tip: Narrow steps such as map and filter need no shuffle; wide steps such as groupByKey and join do.
Question 5Medium
Which benefit does lazy evaluation give Spark?
- It can optimise the whole plan and pipeline operations before running
- It guarantees no failures
- It removes the need for a cluster for every job on each node
- It stores all data in the driver in current releases in current releases
Answer: A. It can optimise the whole plan and pipeline operations before running
Explanation
Seeing the full DAG lets Spark pipeline narrow transformations and skip unneeded work.
Step-by-step solution
- Lazy evaluation lets Spark record the whole chain of transformations first.
- With the full plan visible, Spark can pipeline narrow steps and skip unneeded work.
- This means Spark can optimise the whole plan before running it.
- So the benefit is option A.
Why the other options are wrong
- B. Lazy evaluation does not guarantee there are no failures; fault recovery is a separate feature.
- C. Lazy evaluation does not remove the need for a cluster.
- D. The driver does not hold all the data; it holds the plan and returns results.
Tip: Lazy plus an action means Spark sees the whole job before it runs it.
Question 6Medium
In Spark's execution model, a stage boundary is created at:
- every transformation by default
- a shuffle (wide dependency)
- every action only
- each executor restart on each node
Answer: B. a shuffle (wide dependency)
Explanation
Narrow transformations are pipelined into one stage; a shuffle begins a new stage.
Step-by-step solution
- Spark splits a job into stages.
- Narrow transformations are pipelined together inside one stage.
- A wide dependency (shuffle) needs data from many partitions, so a new stage starts there.
- So the stage boundary is created at a shuffle (option B).
Why the other options are wrong
- A. Not every transformation starts a stage; narrow ones are pipelined together.
- C. An action starts a job but is not itself a stage boundary.
- D. An executor restart does not define a stage.
Tip: Number of stages is usually the number of shuffles plus one.
Question 7Medium
Calling repartition(10) on a DataFrame compared with coalesce(10) when reducing partitions,
- coalesce always shuffles all data because it always sorts the data globally first
- They are the same in cost
- repartition does a full shuffle, while coalesce avoids a full shuffle by merging partitions
- coalesce can increase partitions without a shuffle
Answer: C. repartition does a full shuffle, while coalesce avoids a full shuffle by merging partitions
Explanation
Use coalesce to reduce partitions cheaply; use repartition to rebalance or increase.
Step-by-step solution
- coalesce merges adjacent partitions.
- repartition reshuffles all rows.
- Reducing: coalesce is cheaper.
Why the other options are wrong
- A. It tries to avoid a full shuffle.
- B. repartition costs more because of the shuffle.
- D. Increasing needs repartition.
Question 8Medium
Which operation is the most expensive in a distributed Spark job, usually?
- Shuffle, because data moves across the network and is written to disk
- Map on a partition, because it runs inside a single partition without any data movement
- Filter on a partition
- Defining a variable on the driver
Answer: A. Shuffle, because data moves across the network and is written to disk
Explanation
Shuffles serialise, write and fetch data over the network, so avoiding them speeds up jobs.
Step-by-step solution
- Shuffle moves data between nodes.
- Involves disk and network I/O.
- Reduce shuffles where possible.
Why the other options are wrong
- B. A narrow operation without data movement.
- C. Runs locally.
- D. Trivial cost.
Question 9Hard
A job has a few keys that hold most of the records, so one task runs far longer than the rest. This problem is called:
- Lineage truncation
- Data skew
- Speculative drift
- Block fragmentation
Answer: B. Data skew
Explanation
Skewed keys overload single partitions; salting keys or broadcasting small tables are typical fixes.
Step-by-step solution
- Skewed keys cause uneven data distribution.
- Some tasks take longer due to heavy workloads.
- This is known as data skew in distributed systems.
Why the other options are wrong
- A. Lineage truncation is not a term for skewed keys; it concerns the chain of RDD dependencies.
- C. Speculative drift is not the name of this problem; speculative execution reruns slow tasks.
- D. Block fragmentation is about how files are split into blocks, not uneven work across tasks.
Tip: Check for skewed keys in big data jobs.
Question 10Hard
A Spark job's DAG is divided into stages at
- Every transformation in the job, since each one creates a new stage of tasks
- Shuffle (wide dependency) boundaries
- Every action only
- Each DataNode
Answer: B. Shuffle (wide dependency) boundaries
Explanation
Narrow dependencies are pipelined within a stage; a wide dependency starts a new stage.
Step-by-step solution
- Find wide dependencies.
- Cut the DAG there.
- Narrow ops pipeline inside a stage.
Why the other options are wrong
- A. Narrow transformations are pipelined in one stage.
- C. Actions start jobs but do not divide stages.
- D. Stages are not tied to nodes.
Practise all 14 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →