Unit 1: Introduction to Spark - Subjective Questions
INT315 — Cluster Computing • Practice Questions with Detailed Answers
20 questions
Explain the major limitations of the traditional MapReduce processing model in Hadoop.
MapReduce limitations:
- Repeated disk I/O: MapReduce writes intermediate results to disk after each map and reduce stage, which increases latency.
- Poor performance for iterative algorithms: Machine learning, graph processing, and scientific computations repeatedly use the same data. MapReduce reloads the data during every iteration.
- High latency: MapReduce is designed mainly for batch processing, so it is unsuitable for applications that require near-real-time results.
- Complex programming model: Developers must divide applications into map and reduce functions, even when the problem does not naturally fit this structure.
- Limited interactive analysis: Interactive queries are slow because each query may initiate a separate job.
- Inefficient data sharing: Sharing data between multiple processing stages is difficult and expensive because intermediate data is materialized on disk.
Apache Spark addresses many of these issues by supporting in-memory processing, directed acyclic graphs, interactive queries, and multiple workloads within one framework.
Compare batch analytics and real-time analytics with respect to data input, processing time, output, and applications.
Batch analytics processes a large, stored dataset at scheduled intervals. Real-time analytics processes data continuously as it arrives.
| Aspect | Batch Analytics | Real-Time Analytics |
|---|---|---|
| Data input | Historical data collected over time | Continuously arriving data streams |
| Processing time | Minutes to hours, depending on data volume | Milliseconds to seconds |
| Output | Periodic reports and summaries | Immediate alerts, decisions, or actions |
| Typical use | Payroll, monthly reports, historical analysis | Fraud detection, monitoring, recommendation systems |
| Infrastructure | Optimized for throughput | Optimized for low latency |
Batch analytics is suitable when immediate results are not necessary. Real-time analytics is essential when a delayed response may reduce business value or create risk. Spark supports both approaches through batch processing and stream processing APIs.
Describe the applications of stream processing in modern data-intensive systems.
Stream processing analyzes data continuously as it is generated instead of waiting for data to be stored in large batches.
Important applications include:
- Fraud detection: Financial transactions can be analyzed immediately to identify suspicious behavior.
- Internet of Things: Sensor data can be monitored to detect equipment failures or abnormal readings.
- Social media analysis: Posts and user interactions can be processed to identify trends and sentiment.
- Log and event monitoring: System logs can be examined for failures, security threats, and performance problems.
- Online recommendations: User activity can update product or content recommendations immediately.
- Telecommunications: Network traffic can be analyzed to detect congestion and service problems.
- Real-time dashboards: Business metrics can be displayed as events occur.
The main benefits are low latency, continuous insight, rapid response, and the ability to make decisions using the most recent data.
What is in-memory processing? Explain why it improves the performance of data analytics applications.
In-memory processing stores frequently used data in the main memory of a cluster instead of repeatedly reading it from disk.
It improves performance in the following ways:
- Lower access latency: Memory access is substantially faster than disk access.
- Reduced disk operations: Intermediate results can remain in memory instead of being written and read repeatedly.
- Efficient iteration: Algorithms that reuse the same data, such as machine learning and graph algorithms, can access cached data quickly.
- Faster interactive queries: Users can run multiple queries on cached datasets without reconstructing the data each time.
- Improved data sharing: Several processing stages can reuse the same in-memory dataset.
Spark uses abstractions such as Resilient Distributed Datasets and DataFrames to cache data across cluster nodes. If memory is insufficient, Spark can spill data to disk, preserving functionality with reduced performance.
Explain the architecture and working principles of Apache Spark.
Apache Spark is a distributed data-processing framework based on a master-worker architecture.
- The driver program contains the application logic and coordinates execution.
- The cluster manager allocates resources to the application. It may be Spark Standalone, YARN, Kubernetes, or another supported manager.
- Worker nodes provide computational resources.
- Executors run tasks on worker nodes and store data in memory or on disk.
- Spark converts application operations into jobs, stages, and tasks using a directed acyclic graph.
Spark transformations are generally lazy, meaning they are not executed immediately. They are recorded in a logical plan. When an action such as count, collect, or save is called, Spark builds an execution plan and schedules tasks across the cluster.
This architecture enables parallel processing, fault recovery, data caching, and support for different workloads.
Discuss the important features of Apache Spark.
Important features of Apache Spark include:
- In-memory computation: Data can be cached in memory to accelerate repeated operations.
- Distributed processing: Workloads are divided into tasks and executed across multiple machines.
- Fault tolerance: Lost partitions can be recomputed using lineage information.
- Lazy evaluation: Transformations are optimized and executed only when an action requires a result.
- Unified analytics: Spark supports batch processing, SQL, streaming, machine learning, and graph processing.
- Multiple language interfaces: Applications can be developed using Scala, Java, Python, and R.
- Scalability: Spark can run on a single machine or across large clusters.
- DAG execution engine: Complex workflows are optimized as directed acyclic graphs rather than being restricted to only map and reduce phases.
- Interactive processing: Users can submit queries and commands through shells and notebooks.
- Broad storage support: Spark can access HDFS, local files, cloud storage, NoSQL databases, and other data sources.
Explain the benefits of Apache Spark for big-data processing.
Benefits of Apache Spark:
- High speed: In-memory caching and optimized execution reduce the time required for many workloads.
- Productivity: High-level APIs simplify distributed application development.
- Unified platform: Batch jobs, SQL queries, streaming applications, machine learning, and graph workloads can be developed using one framework.
- Cost effectiveness: Spark can run on commodity hardware and does not require a separate engine for every workload.
- Flexibility: It supports multiple programming languages, deployment modes, and storage systems.
- Fault tolerance: Spark can recover lost data partitions through lineage and recomputation.
- Scalability: Resources can be increased as data volume and processing requirements grow.
- Advanced optimization: DataFrame and SQL workloads benefit from query optimization and efficient execution.
- Interactive analysis: Analysts can explore data more quickly than with traditional disk-heavy batch systems.
These benefits make Spark suitable for both exploratory analysis and production data pipelines.
Describe the steps required to install and run Apache Spark as a standalone user on a local computer.
Typical installation steps:
- Install Java: Install a compatible Java Development Kit and verify it using
java -version. - Download Spark: Obtain a pre-built Spark distribution from the official Apache Spark website.
- Extract the archive: Unpack the downloaded file into a suitable directory.
- Configure environment variables: Set
SPARK_HOMEto the Spark directory and add itsbindirectory to the systemPATH. - Verify the installation: Run
spark-shellfor Scala orpysparkfor Python. - Test Spark: Create a small collection and perform an action such as counting its elements.
- Run a sample application: Submit an application using
spark-submit.
For standalone local use, Spark can run in local mode with a command such as local[*], where the asterisk allows Spark to use the available processor cores. A production cluster installation requires additional configuration for worker nodes and a cluster manager.
Differentiate between Spark local mode and Spark standalone cluster mode.
| Feature | Local Mode | Standalone Cluster Mode |
|---|---|---|
| Execution location | Runs on one computer | Runs across multiple computers |
| Resource provider | Local processor cores and memory | Spark master and worker processes |
| Main purpose | Learning, testing, and development | Distributed application execution |
| Configuration | Simple; often uses local[*] |
Requires master and worker configuration |
| Fault tolerance | Limited to the local machine | Supports distributed execution and worker recovery mechanisms |
| Scalability | Limited by one machine | Can scale by adding worker nodes |
Local mode is convenient for experimenting with Spark applications. Standalone cluster mode uses Spark's own cluster manager, in which a master allocates executors and tasks to worker nodes. The programming model is similar in both modes, but the available resources and operational complexity differ.
Compare Apache Spark with Hadoop MapReduce in terms of processing model, performance, workloads, and fault tolerance.
| Aspect | Hadoop MapReduce | Apache Spark |
|---|---|---|
| Processing model | Mainly map and reduce phases | DAG-based execution model |
| Intermediate data | Usually written to disk | Can be kept in memory or written to disk when needed |
| Iterative workloads | Relatively slow | Generally faster because data can be cached |
| Real-time support | Primarily batch-oriented | Supports streaming and low-latency workloads |
| APIs | Lower-level map and reduce programming model | Higher-level APIs and libraries |
| Workloads | Mainly batch processing | Batch, SQL, streaming, machine learning, and graph processing |
| Fault tolerance | Replicates data in HDFS and reruns failed tasks | Uses lineage-based recomputation and storage mechanisms |
| Resource usage | Closely associated with HDFS and YARN | Can use Standalone, YARN, Kubernetes, and other managers |
Spark is often faster and more flexible, while Hadoop MapReduce remains useful for reliable, large-scale batch processing with disk-based execution.
Explain how Spark overcomes the limitations of MapReduce for iterative machine-learning algorithms.
Iterative machine-learning algorithms repeatedly process the same training data. Examples include clustering, classification, and gradient-based optimization.
In MapReduce, each iteration normally performs the following operations:
- Read the training data from storage.
- Execute map and reduce tasks.
- Write intermediate results to disk.
- Start the next iteration by reading the data again.
This repeated disk access causes high execution time. Spark improves the process by allowing the training dataset to be cached in memory across iterations. Each iteration can then reuse the cached partitions. Spark's DAG scheduler also optimizes the sequence of transformations and reduces unnecessary synchronization between stages.
Spark additionally provides machine-learning libraries with distributed algorithms. As a result, iterative workloads generally achieve lower latency and better resource utilization, provided that sufficient memory is available.
What is lazy evaluation in Spark? Explain its effect on job execution and optimization.
Lazy evaluation means that Spark does not immediately execute transformations such as map, filter, or select. Instead, it records them and waits until an action requires a result.
Its effects include:
- DAG construction: Spark builds a directed acyclic graph representing the complete computation.
- Pipeline optimization: Compatible transformations can be combined into a single stage.
- Reduced data movement: Spark can avoid unnecessary shuffles and transfers between nodes.
- Limited computation: Only the data and operations required for the requested result are executed.
- Better fault recovery: The recorded lineage shows how lost partitions can be recomputed.
An action such as count, collect, or write triggers execution. Lazy evaluation therefore separates the description of a computation from its actual execution and gives Spark more information for optimization.
Describe Resilient Distributed Datasets and explain their role in Spark fault tolerance.
A Resilient Distributed Dataset, or RDD, is an immutable, partitioned collection of elements distributed across the nodes of a cluster.
Its important properties are:
- Distributed: Data is divided into partitions that can be processed in parallel.
- Immutable: Operations create new RDDs rather than modifying existing ones.
- Lazy: Transformations are recorded and executed only when an action is called.
- Resilient: Spark stores lineage information describing how each partition was derived.
- Cacheable: Frequently used RDDs can be stored in memory or on disk.
If a partition is lost because of a node failure, Spark uses lineage to recompute only that partition from its original data and transformations. This avoids requiring every intermediate result to be replicated. RDDs are particularly useful when applications need fine-grained control over distributed data and fault recovery.
Explain how Spark supports both batch processing and stream processing in a unified framework.
Spark provides a common execution platform for different data-processing workloads.
- Batch processing: Spark reads bounded datasets from sources such as files, HDFS, databases, or object storage. It processes the complete dataset and produces a final result.
- Stream processing: Spark Structured Streaming reads unbounded data from sources such as Kafka, files, or network systems. It processes data incrementally as new records arrive.
- Common APIs: DataFrames, SQL expressions, transformations, and output operations can be used in both batch and streaming applications.
- Shared libraries: The same platform can combine streaming data with machine learning, SQL, and other analytics.
- Fault handling: Checkpointing, recovery mechanisms, and structured execution help maintain reliable streaming jobs.
This unified approach reduces the need to maintain separate systems and allows organizations to reuse data models, application logic, and operational practices.
Discuss the major components of the Hadoop ecosystem and compare them with the corresponding components of Spark.
The Hadoop ecosystem contains several specialized components:
- HDFS: Distributed storage for large files.
- YARN: Cluster resource management and scheduling.
- MapReduce: Disk-oriented batch processing engine.
- Hive: SQL-based data warehousing and querying.
- Pig: Data-flow scripting for batch analysis.
- HBase: Distributed column-oriented database.
- Sqoop and Flume: Data import and collection tools.
Spark provides a processing engine and libraries rather than replacing every Hadoop component:
- Spark Core: Distributed execution and resource coordination.
- Spark SQL: Structured data processing and SQL queries.
- Structured Streaming: Stream processing.
- MLlib: Machine learning.
- GraphX: Graph computation.
Spark can use HDFS for storage and YARN for resource management. Therefore, Spark and Hadoop are often complementary. Hadoop supplies durable storage and cluster services, while Spark supplies a faster and more flexible computation engine.
Explain the role of Spark SQL, Structured Streaming, MLlib, and GraphX in the Spark ecosystem.
Spark provides specialized libraries for different analytical requirements:
- Spark SQL: Processes structured and semi-structured data using SQL, DataFrames, and Datasets. It supports schema-based operations and query optimization.
- Structured Streaming: Processes continuously arriving data using a structured, DataFrame-oriented programming model. It supports operations such as filtering, aggregation, joins, and windowing.
- MLlib: Provides distributed machine-learning algorithms, feature-processing tools, pipelines, and evaluation utilities.
- GraphX: Supports graph-parallel computation for relationships among entities, such as social networks and web links.
All these components run on Spark Core. This integration makes it possible to use one application for activities such as reading data, transforming it with SQL, applying a machine-learning model, and analyzing relationships in a graph.
A company needs to analyze transactions immediately and also generate a monthly sales report. Propose a Spark-based solution and justify the processing approach.
The company should use a hybrid Spark architecture:
- Use Structured Streaming to read transactions continuously from a source such as Kafka.
- Apply validation, filtering, enrichment, and fraud-detection rules as events arrive.
- Store alerts and short-term aggregates in a low-latency data store or dashboard system.
- Persist the incoming transactions in durable storage such as HDFS or cloud object storage.
- Use a scheduled Spark batch job to read the accumulated data at the end of each month.
- Perform joins, aggregations, and historical comparisons to create the monthly sales report.
This approach matches the processing model to each requirement. Immediate transaction analysis requires low latency, while monthly reporting benefits from complete historical data and high-throughput batch processing. Spark allows both workloads to share APIs, infrastructure, and data-processing logic.
Distinguish between transformations and actions in Spark with suitable examples.
Transformations create a new dataset from an existing dataset but are evaluated lazily. Examples include:
mapfilterflatMapselectgroupBy
Actions produce a result or write data and trigger execution. Examples include:
countcollectfirstreduceshowwrite
For example, a Spark program may first filter records using a transformation and then call count as an action. Spark records the filter operation, but actual processing starts only when count is invoked. This separation allows Spark to optimize the complete computation before running tasks on the cluster.
Explain data partitioning and shuffling in Spark. Why can excessive shuffling reduce performance?
Partitioning divides a dataset into smaller parts so that multiple tasks can process the data in parallel. A partition is generally handled by one task.
Shuffling is the redistribution of data across partitions, usually required by operations such as groupByKey, joins, and some aggregations. Records with related keys must be brought together, possibly across different worker nodes.
Excessive shuffling reduces performance because it:
- Transfers data over the network.
- Creates additional disk and memory operations.
- Increases serialization and deserialization overhead.
- Can produce uneven partitions and data skew.
- Introduces stage boundaries and task coordination costs.
Performance can be improved by choosing suitable partitioning, using combiners or reduce-side aggregation, filtering data before a shuffle, and using broadcast joins when one dataset is sufficiently small.
Derive the main factors that determine the speedup obtained when moving a workload from Hadoop MapReduce to Spark.
The speedup obtained with Spark is workload-dependent rather than automatic. It can be understood using the following factors:
- Let represent time spent reading and writing intermediate data to disk.
- Let represent data-transfer time.
- Let represent actual computation time.
- Let represent memory access and caching overhead.
For a disk-oriented job, execution time can be approximated as:
For a Spark job that successfully caches reused data, the approximate time may be:
The speedup is therefore:
The speedup is greatest when the workload is iterative, intermediate data is reused, and sufficient memory is available. It may be modest for a single-pass batch job dominated by computation or input/output. Spark can also lose performance because of garbage collection, memory pressure, serialization, or excessive shuffling.
Explain the major limitations of the traditional MapReduce processing model in Hadoop.
MapReduce limitations:
- Repeated disk I/O: MapReduce writes intermediate results to disk after each map and reduce stage, which increases latency.
- Poor performance for iterative algorithms: Machine learning, graph processing, and scientific computations repeatedly use the same data. MapReduce reloads the data during every iteration.
- High latency: MapReduce is designed mainly for batch processing, so it is unsuitable for applications that require near-real-time results.
- Complex programming model: Developers must divide applications into map and reduce functions, even when the problem does not naturally fit this structure.
- Limited interactive analysis: Interactive queries are slow because each query may initiate a separate job.
- Inefficient data sharing: Sharing data between multiple processing stages is difficult and expensive because intermediate data is materialized on disk.
Apache Spark addresses many of these issues by supporting in-memory processing, directed acyclic graphs, interactive queries, and multiple workloads within one framework.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →