Sample questions
Question 1Easy
Which Spark operation is a wide transformation requiring a shuffle?
- reduceByKey
- map, which also needs data from other partitions
- filter
- flatMap
Answer: A. reduceByKey
Explanation
Wide transformations such as reduceByKey, groupByKey and join need data from many partitions.
Step-by-step solution
- Narrow: one parent partition.
- Wide: many parent partitions.
- reduceByKey regroups by key.
Why the other options are wrong
- B. map works within each partition independently.
- C. filter is a narrow transformation within each partition.
- D. flatMap is narrow too, with no data exchange between partitions.
Question 2Easy
What are broadcast variables used for in Spark?
- Sending a read-only value to every executor once instead of with every task
- Storing the output of reducers across tasks, adding the results as tasks finish
- Counting events across tasks
- Repartitioning data
Answer: A. Sending a read-only value to every executor once instead of with every task
Explanation
They efficiently share a small lookup table across the cluster, reducing network cost.
Step-by-step solution
- Large read-only value.
- Ship once per executor.
- Tasks read the local copy.
Why the other options are wrong
- B. Not their use.
- C. That is an accumulator.
- D. Not their purpose.
Question 3Easy
What does RDD stand for in Apache Spark?
- Rapid Data Distribution, the abstraction for HDFS block replication
- Resilient Distributed Dataset
- Replicated Disk Data
- Remote Dataset Driver
Answer: B. Resilient Distributed Dataset
Explanation
An RDD is an immutable, partitioned collection that can be rebuilt from lineage after a failure.
Step-by-step solution
- Resilient: recoverable via lineage.
- Distributed: across the cluster.
- Dataset: a collection.
Why the other options are wrong
- A. Not the name used by Spark.
- C. RDDs are not disk replicas by definition.
- D. The driver is a separate concept.
Question 4Easy
In Spark, an RDD stands for:
- Redundant Data Directory
- Remote Distributed Database by default
- Resilient Distributed Dataset
- Reliable Delimited Dataset for every job
Answer: C. Resilient Distributed Dataset
Explanation
RDD is Spark's fault-tolerant, partitioned collection abstraction.
Step-by-step solution
- RDD stands for Resilient Distributed Dataset.
- It is a fundamental data structure in Apache Spark.
- RDDs are fault-tolerant and can be distributed across clusters.
- They allow parallel processing of large datasets.
- The correct answer is Resilient Distributed Dataset.
Why the other options are wrong
- A. RDD is not a Redundant Data Directory; the name is Resilient Distributed Dataset.
- B. Remote Distributed Database is not what RDD stands for in Spark.
- D. Reliable Delimited Dataset is not the name; RDD means Resilient Distributed Dataset.
Tip: Remember RDD stands for Resilient Distributed Dataset.
Question 5Medium
How does Spark recover lost RDD partitions after a node failure?
- By restoring from the Secondary NameNode
- By recomputing them from the lineage of transformations
- By restarting the whole application from scratch always
- By reading a mandatory checkpoint on every RDD
Answer: B. By recomputing them from the lineage of transformations
Explanation
Lineage records how each RDD derives from its parents, so lost partitions are recomputed.
Step-by-step solution
- Spark uses lineage to track how each RDD was created.
- Lineage allows Spark to recompute lost partitions from parent RDDs.
- Recomputing avoids full restart and data loss.
- This process is efficient and fault-tolerant.
- Final answer: By recomputing them from the lineage of transformations.
Why the other options are wrong
- A. Spark does not use the Secondary NameNode, an HDFS component, to recover RDD partitions.
- C. Spark does not restart the whole app for each failure; it recomputes only the lost partitions.
- D. A checkpoint is optional, not mandatory on every RDD; lineage is the normal recovery path.
Tip: Remember: Spark recovers RDDs using lineage, not checkpoints or full restarts.
Question 6Medium
Which of these is a transformation in Spark?
- collect()
- count()
- map()
- saveAsTextFile()
Answer: C. map()
Explanation
Transformations such as map and filter are lazy and return a new RDD; actions such as collect trigger execution.
Step-by-step solution
- Transformation returns an RDD.
- Action returns a value or writes output.
- map returns an RDD.
Why the other options are wrong
- A. collect is an action that returns data to the driver.
- B. count is an action that returns a number.
- D. saving is an action that writes output.
Question 7Medium
A call to collect() on a very large RDD is risky because
- It deletes the RDD and deletes the underlying input files from storage
- It forces replication factor 1
- It runs on one executor only
- All results are pulled into the driver's memory and may cause an out-of-memory error
Answer: D. All results are pulled into the driver's memory and may cause an out-of-memory error
Explanation
collect() brings every partition's data to the driver; use take(), aggregates or write to storage instead.
Step-by-step solution
- Action returns data to the driver.
- All partitions are gathered.
- Driver memory is limited.
Why the other options are wrong
- A. It does not delete anything.
- B. Unrelated.
- C. The computation is distributed; the result comes to one driver.
Question 8Medium
What does rdd.cache() do by default?
- Immediately computes and stores it on disk in current releases
- Copies it to HDFS
- Converts it to a DataFrame on each node
- Marks the RDD to be kept in memory once it is first computed
Answer: D. Marks the RDD to be kept in memory once it is first computed
Explanation
cache is lazy: the data is materialised on the first action and then reused.
Step-by-step solution
- cache() is lazy: calling it does not compute anything yet.
- It marks the RDD so that its data is kept in memory once it is first computed.
- The next action computes the RDD and stores the result for reuse.
- So cache() marks the RDD to be kept in memory (option D).
Why the other options are wrong
- A. cache() does not compute immediately, and it keeps the data in memory, not on disk by default.
- B. cache() does not copy the RDD to HDFS.
- C. cache() does not convert the RDD into a DataFrame.
Tip: cache() only takes effect after the first action computes the RDD.
Question 9Hard
Which statement about Spark's reduceByKey versus groupByKey is true?
- groupByKey is always faster by default for every job
- They are identical in network cost on each node by default
- reduceByKey combines values locally before shuffling, so it usually moves less data
- reduceByKey is an action
Answer: C. reduceByKey combines values locally before shuffling, so it usually moves less data
Explanation
Map-side combining in reduceByKey shrinks shuffle volume; groupByKey ships all values.
Step-by-step solution
- GroupByKey sends every value for a key across the network before grouping.
- ReduceByKey first combines values with the same key inside each partition.
- Only the partial results are shuffled, so less data moves.
- So the true statement is option C.
Why the other options are wrong
- A. GroupByKey is not faster by default; it moves all values and is usually the heavier choice.
- B. Their network costs differ, because reduceByKey shuffles less data.
- D. ReduceByKey is a transformation, not an action; an action returns a result to the driver.
Tip: Prefer reduceByKey over groupByKey when you aggregate values per key.
Question 10Hard
Spark recovers a lost partition of an RDD by
- Reading a backup from the Secondary NameNode, which stores a full copy of every RDD partition on disk
- Restarting the entire job always
- Re-computing it from its lineage of transformations
- Asking the user to resubmit
Answer: C. Re-computing it from its lineage of transformations
Explanation
The lineage graph records how each RDD was derived, so lost partitions are rebuilt from parent data.
Step-by-step solution
- RDDs are immutable.
- Lineage logs the transformations.
- Replay them for the lost partition.
Why the other options are wrong
- A. Not how Spark recovers.
- B. Only the lost partitions are recomputed.
- D. Recovery is automatic.
Practise all 20 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 →