Spark Interview Questions
Apache Spark is an open source, distributed computing engine designed for large scale data processing. Originally developed at UC Berkeley's AMPLab in 2...
What is Apache Spark?
Apache Spark is an open source, distributed computing engine designed for large scale data processing. Originally developed at UC Berkeley's AMPLab in 2009, it was built to overcome the limitations of MapReduce by keeping intermediate data in memory rather than writing it to disk between stages. Key characteristics: Unified engine : handles batch processing, streaming, SQL queries, machine learning, and graph computation under a single API In memory computation : dramatically reduces I/O overhea
Why Apache Spark?
Spark was created to address the shortcomings of MapReduce , where every intermediate result had to be persisted to HDFS — making iterative workloads (like ML training) painfully slow. Core reasons Spark is the preferred choice: Speed : In memory processing makes Spark up to 100x faster than MapReduce for iterative jobs and ~10x faster for disk based operations Unified API : One engine handles batch ETL, streaming, ad hoc SQL, ML, and graph processing — reducing operational complexity Developer
What are the components of the Apache Spark Ecosystem?
Spark is built as a layered ecosystem with a core engine and specialized libraries on top: Core Engine Spark Core : The foundation — task scheduling, memory management, fault recovery, and the RDD API Higher Level Libraries Spark SQL / DataFrames / Datasets : Structured data processing with SQL support and the Catalyst optimizer; the primary API for most data engineering work Spark Streaming / Structured Streaming : Real time stream processing. Structured Streaming is the modern, DataFrame based
What is Spark Core?
Spark Core is the foundational execution engine that all other Spark libraries are built upon. It handles the fundamental responsibilities of a distributed system so that higher level APIs don't have to. Responsibilities of Spark Core: Task scheduling : Breaks jobs into stages and tasks, then distributes them across executor nodes via the DAGScheduler and TaskScheduler Memory management : Manages how data is stored in memory vs. spilled to disk across executors Fault recovery : Tracks RDD lineag
Which languages does Apache Spark support?
Spark provides APIs in four primary languages , each with different trade offs: Language API Type Best For Scala Native Maximum performance; Spark itself is written in Scala Python (PySpark) Wrapper via Py4J Data science, rapid prototyping, wide adoption Java Native JVM Enterprise integration, type safety R (SparkR / sparklyr) Wrapper Statistical analysis, R native teams Key considerations: Scala has zero serialization overhead since it runs directly on the JVM alongside the Spark engine. It is
How is Apache Spark better than Hadoop?
Spark doesn't replace Hadoop entirely — it replaces MapReduce as the compute engine while often still running on HDFS and YARN. The comparison is really Spark vs. MapReduce. Where Spark wins: Speed : Spark keeps intermediate data in memory; MapReduce writes every intermediate result to HDFS. For iterative jobs (ML, graph), Spark can be 10–100x faster Ease of use : Spark's DataFrame API and SQL support are far more expressive than writing raw MapReduce Java code Unified engine : One platform hand
What are the different methods to run Spark over Apache Hadoop?
Spark integrates with the Hadoop ecosystem in several ways, giving teams flexibility based on their existing infrastructure: 1. Spark on YARN (most common) Spark submits applications to Hadoop's YARN resource manager. YARN handles executor allocation across the cluster. Two modes: deploy mode client (driver on submitting machine) or deploy mode cluster (driver on YARN) 2. Spark Standalone Mode Spark runs its own built in cluster manager, independent of YARN. Simpler to set up but lacks YARN's mu
What is SparkContext in Apache Spark?
SparkContext ( sc ) was the original entry point to Spark, introduced in Spark 1.x. It represents the connection between the Spark driver program and the cluster, and is responsible for coordinating the distributed execution of your application. What SparkContext does: Establishes a connection to a cluster manager (YARN, Standalone, Mesos, K8s) Allocates executors on worker nodes Coordinates task scheduling and distribution Provides the API to create RDDs from data sources or in memory collectio