Note: This Interview questions page is in progress. I will finish this article ASAP. if you are looking for an answer to any question that I have not answered yet, please ask in a comment. I will try to reply within a day or so.
In this Apache Spark Basic or Core Interview questions, I will cover the most frequently asked questions along with answers and links to the article to learn more in detail. When you are looking for a job in Apache Spark it’s always good to have in-depth knowledge of the subject and I hope SparkByExamples.com provides you with the required knowledge to crack the interview. I wish you all the best.
One of the most asked Interview questions is What are the different issues you faced while running the Spark application? This question needs a very detailed answer based on your experiences hence I create a separate article discussing this.
1. Apache Spark Basic Interview Questions
What is Apache Spark?
Apache Spark is an Open source framework, an in-memory computing processing engine that processes data on the Hadoop Ecosystem. It processes both batch and real-time data in a parallel and distributed manner.
Difference between Spark and MapReduce?
MapReduce: MapReduce is I/O intensive read from and writes to disk. It is batch processing. MapReduce is written in java only. It is not iterative and interactive. MapReduce can process larger sets of data compared to spark.
Spark: Spark is a lighting-fast in-memory computing process engine, 100 times faster than MapReduce, 10 times faster to disk. Spark supports languages like Scala, Python, R, and Java. Spark Processes both batch as well as Real-Time data.
What are the components/modules of Apache Spark?
Apache Spark comes with SparkCore, Spark SQL, Spark Streaming, Spark MlLib, and GraphX
- Spark Core
- Spark SQL
- Spark Streaming
What are the different installation modes of Spark?
Spark can be installed in 3 different ways.
- Standalone mode:
- Pseudo-distribution mode:
- Multi cluster mode:
What are the different cluster managers Spark supports?
Any Spark application can be divided into an independent set of processes and processed parallelly on a cluster, coordinated by the SparkContext object in the driver program. Especially, to run in a cluster SparkContext connects to different cluster managers, Standalone, Hadoop Yarn, and Apache Mesos to allocate resources across applications. once connected spark acquires Executors on worker nodes and executors, which are processes that process data and store data for the application. And SparkContext sends application code to Executors. Then finally, SparkContexts sends tasks to Executors for processing.
- Standalone cluster manager:
What is SparkSession?
SparkSession was introduced in version Spark 2.0, It is an entry point to underlying Spark functionality in order to programmatically create Spark RDD, DataFrame, and DataSet. SparkSession’s object
spark is the default variable available in
spark-shell and it can be created programmatically using
SparkSession builder pattern.
Can you create multiple SparkSession objects in a single application?
Yes, you can create as many
SparkSession objects as you want in a Spark application. Many Spark session objects are required when you wanted to keep Spark tables (relational entities) logically separated.
How do you create SparkSession object?
To create SparkSession in Scala or Python, you need to use the builder pattern method
builder() and calling
getOrCreate() method. If SparkSession already exists it returns otherwise creates a new SparkSession.
val spark = SparkSession.builder() .master("local") .appName("SparkByExamples.com") .getOrCreate();
What is SparkContext?
Can you create multiple SparkContext in an Application?
No. You can create only one active SparkContext per JVM. You should stop() the active SparkContext before creating a new one.
Difference Between SparkSession vs SparkContext?
Can you explain the difference between RDD vs DataFrame vs Dataset?
What are Spark Driver, Worker, and Executor?
What is coalesce vs repartition?
What is Spark shuffle?
What is Lazy Evaluation?
Can you name few DataFrame Actions & Transformations?
Explain Map() vs flatMap()?
Explain Map() vs foreach()?
What is Client vs Cluster deploy modes?
- What is Apache Spark, and how does it differ from Hadoop MapReduce?
- Explain the key features of Apache Spark.
- What is the Spark Driver, and what role does it play in a Spark application?
- What is a Spark Executor, and how does it relate to Spark tasks?
- Describe the Resilient Distributed Dataset (RDD) in Spark.
- What are the two types of operations in Spark RDD?
- Explain the concept of lineage in RDDs.
- What is lazy evaluation, and why is it important in Spark?
- What are transformations and actions in Spark, and provide examples of each.
- What is Spark’s in-memory computation capability, and how does it improve performance?
- How do you create an RDD in Spark?
- Explain the difference between
- What is a broadcast variable, and when would you use it?
- How can you persist an RDD in Spark, and why is it important?
- What is a shuffle operation, and when does it occur?
- How can you repartition an RDD in Spark?
- Explain the concept of data locality in Spark.
- What are Spark accumulators, and what are their use cases?
- Describe the Spark SQL library and its benefits.
- How can you create a DataFrame in Spark, and what are its advantages over RDDs?
- How do you debug your Spark application?
- How do you kill running Spark Application?
- How do you submit the Spark application?
- What is the Spark Cluster Manager, and name some common cluster managers used with Spark.
- Describe the Spark Master and Worker nodes in a cluster.
- Explain the role of the Cluster Manager, Application Master, and Executor in Spark’s execution model.
- What is the difference between YARN, Mesos, and Standalone cluster managers in Spark?
- How does Spark handle fault tolerance in distributed data processing?
- What is dynamic allocation in Spark, and how does it work?
- Explain the concept of data serialization in Spark.
- What is the role of the DAG Scheduler in Spark’s execution plan?
- How does Spark support data partitioning and co-location?
- If Spark can spill the data to disk, why would it fail with the OOM – out-of-memory exception?
- What is Spark Streaming, and how does it process real-time data?
- Explain the key components of Spark MLlib (Machine Learning Library).
- What is GraphX in Spark, and what are its use cases?
- Describe the functionality of SparkR for R users.
- What is the purpose of Spark GraphFrames?
- How does Apache Spark integrate with Apache Kafka for stream processing?
- What are the benefits of using Spark with Apache HBase?
- Explain the role of Spark Catalyst in query optimization.
- What is Apache Zeppelin, and how can it be used with Spark?
Performance Tuning and Optimization:
- What are the few things you will check to improve Spark performance?
- What are some common techniques for optimizing Spark applications?
- How can you control the level of parallelism in Spark?
- What is speculative execution in Spark, and how does it help in fault tolerance?
- Explain the importance of broadcast joins in Spark.
- What are the best practices for managing Spark memory and garbage collection?
- How can you troubleshoot and diagnose performance issues in Spark applications?
- What is Spark’s Tungsten project, and how does it improve performance?
- Describe the benefits of using the Parquet file format with Spark.
Integration and Data Sources:
- How can you read data from external data sources like HDFS or S3 in Spark?
- Explain how to write data back to external storage from Spark.
- What is the purpose of Spark connectors, and provide some examples.
- How can you connect Spark to a relational database like MySQL or PostgreSQL?
- What are the advantages of using Apache Avro for data serialization with Spark?
- How can you read data from and write data to Apache Cassandra using Spark?
- Describe the process of reading and writing data from/to Apache Hive using Spark.
Security and Authentication:
- What security features are available in Spark to protect data?
- Explain the role of authentication and authorization in a Spark cluster.
- How can you enable authentication and encryption in Spark using Kerberos?
- Describe the use of Spark’s built-in security manager.
- What is Apache Ranger, and how does it enhance Spark’s security?
Cluster Management and Deployment:
- How can you deploy a Spark application in a standalone cluster mode?
- Explain the steps to submit a Spark application to a YARN cluster.
- What are some common issues and considerations when configuring Spark on a cluster?
- Describe the differences between cluster deploy mode and client deploy mode.
- How can you run Spark on a cloud-based cluster, such as AWS EMR or Azure Databricks?
Monitoring and Logging:
- What tools and utilities are available for monitoring Spark applications?
- Explain the purpose of Spark’s built-in web UI.
- How can you access Spark application logs and view them?
- What metrics and statistics are important to monitor in a Spark cluster?
- Describe the Spark History Server and its role in application history tracking.
Data Partitioning and Shuffling:
- What is data skew, and how can it impact Spark application performance?
- How can you mitigate data skew in Spark applications?
- Explain the concept of data locality and its impact on shuffling.
- What is shuffle spill, and how does it occur in Spark?
- How can you optimize shuffle operations in Spark?
Distributed Machine Learning:
- What machine learning algorithms are available in Spark MLlib?
- Describe the process of building a machine learning pipeline in Spark.
- How can you perform hyperparameter tuning for machine learning models in Spark?
- What is cross-validation, and how can you implement it in Spark MLlib?
- Explain the use of feature extraction and transformation in Spark MLlib.
Streaming and Real-time Data:
- What is the difference between micro-batch processing and event-based streaming in Spark Streaming?
- How does Spark Streaming handle windowed operations on streaming data?
- What is watermarking in Spark Structured Streaming, and why is it important?
- Explain the concept of stateful processing in Spark Streaming.
- What are the challenges and considerations when working with stateful streaming applications?
Testing and Debugging:
- How can you unit test Spark applications using Spark Testing Base or other libraries?
- What are some debugging techniques for Spark applications?
- How can you simulate failures and test fault tolerance in Spark?
- What is the purpose of Spark’s local mode, and how can it be useful for testing?
- What is the difference between Spark RDDs and DataFrames?
- How does Apache Arrow improve data transfer between Spark and other systems?
- What is Structured Streaming, and how is it different from Spark Streaming?
- Describe the use of checkpointing in Spark Streaming.
- What are the benefits of using Spark on Kubernetes for container orchestration?
- Explain the role of Spark Catalyst in optimizing query plans for Spark SQL.
- What is Delta Lake, and how does it enhance