Synechron Interview Questions
When analyzing a PySpark workflow, you must distinguish transformations (lazy, build the DAG) from actions (trigger execution). Transformations (lazy —...
As a Data Engineer, analyze the Spark transformations and actions used in the following PySpark workflow and explain their impact on performance and execution.
When analyzing a PySpark workflow, you must distinguish transformations (lazy, build the DAG) from actions (trigger execution). Transformations (lazy — no execution until an action is called): df.read , filter , select , withColumn , groupBy , join , repartition , cache Each transformation adds a node to the Directed Acyclic Graph (DAG) Spark batches and optimizes the whole DAG via the Catalyst optimizer before executing Actions (trigger execution): .show() , .count() , .collect() , .write , .to
Identify transformations and actions in the given PySpark code.
Quick reference — Transformations vs Actions: Transformations (return a new DataFrame/RDD, lazy): Operation Type Notes filter() / where() Narrow No shuffle select() / withColumn() Narrow Column operations map() / flatMap() Narrow RDD operations union() Narrow No shuffle join() Wide Shuffles both sides groupBy() / groupByKey() Wide Shuffle distinct() Wide Shuffle repartition() Wide Full shuffle coalesce() Narrow Merge, no shuffle orderBy() / sort() Wide Global sort Actions (trigger execution, ret
What are narrow and wide transformations?
Narrow transformations : Each output partition depends on data from exactly one input partition. No data movement between executors — all processing is local. Examples: filter , map , flatMap , select , withColumn , union , coalesce No shuffle → no stage boundary → fast, no network I/O Multiple consecutive narrow transformations are pipelined in a single stage Wide transformations : Each output partition depends on data from multiple input partitions. Requires a shuffle — data is redistributed a
Why is filtering (df.filter(col('salary') > 10000)) considered a narrow transformation while join is a wide transformation?
filter is narrow because evaluating salary 10000 for a row requires only the data within that single row, which lives in a single partition. No information from any other partition is needed. The operation is perfectly local to each executor — each executor filters its own partitions independently with zero network communication. join is wide because to correctly match rows from the left DataFrame with rows from the right DataFrame on a key, rows with the same key must be co located on the same
How does Spark execute transformations lazily? When does actual computation happen? Why does Spark not execute transformations immediately but wait until an action (like .show()) is called?
Lazy evaluation means Spark records what transformations to perform (building a DAG of operations) but does not execute any computation until an action is called. How it works: When computation actually happens: Computation triggers when an action is called: .show() , .count() , .collect() , .write. (...) , .toPandas() . Why lazy evaluation is beneficial: 1. Whole plan optimization : By seeing the complete chain of transformations before executing, the Catalyst optimizer can reorder, merge, or e
Explain the impact of the join operation: How does the shuffle stage impact performance? How can you optimize join performance in Spark (e.g., using broadcast joins)?
Shuffle stage impact on performance: A shuffle involves three expensive phases: 1. Map phase : Each executor writes its output partitioned by join key to local disk (shuffle write) 2. Network transfer : Shuffle files are pulled by destination executors over the network (the most expensive part) 3. Reduce phase : Receiving executors read and sort/hash the data to perform the join (shuffle read) Costs include: disk I/O, network bandwidth, serialization/deserialization, and memory pressure (shuffle
Discuss execution flow in a distributed environment: How does Spark handle fault tolerance and parallel execution? What role does the DAG (Directed Acyclic Graph) play in optimizing query execution?
Parallel execution flow: 1. Driver submits an Application → SparkContext negotiates resources with the cluster manager (YARN/Kubernetes) 2. Executors are launched on worker nodes 3. Each Action triggers a Job submission 4. Spark divides the job into Stages (split at wide transformation boundaries) 5. Each stage's tasks run in parallel — one task per partition, distributed across available executor cores 6. Stages run sequentially when one depends on another's shuffle output Fault tolerance: Spar
What is the purpose of default_args, and why do we set catchup=False?
default args in Airflow is a dictionary of default parameters applied to all tasks in a DAG, reducing boilerplate when defining individual operators. These values are inherited by each operator in the DAG unless overridden at the task level. This is DRY (Don't Repeat Yourself) configuration. catchup=False — why it's important: When a DAG has a start date in the past and catchup=True (the default), Airflow will backfill — create and run all missed DAG runs from start date to the current date. Exa