← Back to list

How Databricks Executes a Job Internally? (From Button Click to Result)

What Really Happens When You Click “Run”?

Sriw World of Coding in Towards Data Engineering · 2026-04-20 10:14 · 8 claps · 8.1 min read paywalled
#databricks #delta-lake #job-scheduling #databricks-sql #photon-engine
Open on Medium ↗
Wiki topics: 🔧 · Data Engineering

How Databricks Executes a Job Internally? (From Button Click to Result)

What Really Happens When You Click “Run”?

You click “Run Job” in Databricks… and a few seconds later, your pipeline finishes, your table is updated, and your Slack gets a notification.

But behind the scenes, an entire orchestration is happening between clusters, Spark, the job scheduler, and the driver.

If you’re a data engineer or PySpark user, understanding how Databricks executes a job internally is like learning the “engine inside the car.” It helps you debug failures, optimize costs, and write interviews‑ready explanations.

In this article, we’ll walk through every phase of a Databricks job from the moment you submit it, all the way to the final output.

🎯 Why This Matters in Real‑World Data Engineering

On a daily basis, you might:

  • Run notebook jobs every 5 minutes
  • Schedule heavy ETL pipelines at night
  • Chain multiple tasks in a Databricks Workflow

When jobs fail or get slow, most teams:

  • Restart the job
  • Scale the cluster “just in case”
  • Add another checkpoint

But without knowing how Databricks actually executes a job, you’re basically tuning the dashboard without reading the engine manual.

By the end of this guide, you’ll understand:

  • How Databricks schedules and routes your job
  • How Spark inside Databricks turns your code into tasks
  • What happens on the driver vs the executors
  • And how this all maps to your job duration, logs, and cost.

💡 Concept Explanation: How Databricks Executes a Job Internally

Let’s break this down into three big pieces:

  1. What a Databricks job actually is
  2. What happens when you submit the job
  3. How Spark inside Databricks actually runs the work

We’ll keep it beginner‑friendly but technically deep — no jargon without explanation.

1. What is a “Databricks Job”?

A Databricks job is essentially a scheduled or triggered execution of one or more tasks. Each task can be:

  • A notebook
  • A Spark JAR
  • A Python script
  • A Delta Live Table pipeline
  • A SQL query

You configure:

  • Which cluster to run it on (new ephemeral or existing)
  • Parameters to pass
  • Retries, timeouts, and notification settings
  • A schedule (e.g., every hour or with a trigger)

So when you “submit a job,” you’re not just running a notebook; you’re submitting a job definition that Databricks will orchestrate across infrastructure.

2. Behind the UI: What Happens When You Click Run

Let’s follow what happens internally when you click “Run Now” or a scheduled job starts.

Step 1: Job scheduling and configuration

  • The Databricks job scheduler receives your job request.
  • It checks the job configuration: cluster type, runtime version, parameters, and retry policy.
  • It also decides whether to use an existing cluster or spin up a new ephemeral job cluster.

Step 2: Cluster provisioning

If no cluster is pre‑assigned or it’s a job cluster:

  • The cluster manager (part of the Databricks control plane) requests VMs in your cloud (AWS/Azure/GCP).
  • Each VM is configured with Databricks Runtime (DBR), which bundles Spark, Python, and other libraries.
  • A driver node is elected, and multiple worker/executor nodes are prepared.

Step 3: Execution context setup

Once the cluster is up:

  • The driver node starts a Spark application and initializes a SparkContext (or SparkSession).
  • Libraries, init scripts, and environment variables are applied.
  • The job’s execution context (parameters, notebook, or script) is set up on the driver.

3. How Spark Internally Executes Your Job

Now comes the core of “how Databricks executes a job”: the Spark execution model.

Here’s what happens step by step:

Step A: Code → Logical Plan → DAG

When you run a notebook or script:

  • The driver node receives the Python/Scala/SQL code.
  • The Spark compiler parses it and builds a logical plan (a tree of operations: select, join, groupBy, etc.).
  • The Catalyst optimizer refactors this into an optimized logical plan.
  • Then it becomes a physical plan and a DAG (Directed Acyclic Graph) of stages.

Step B: DAG → Stages → Tasks

Once the DAG is ready:

  • Spark’s DAG scheduler splits the DAG into stages at shuffle boundaries.
  • A stage is a set of tasks that can run without shuffling data between nodes.
  • The task scheduler converts each stage into tasks — one per data partition.

📌 Analogy: If you’re processing 1 million rows divided into 100 partitions, Spark creates 100 tasks per stage, each running on a different executor core.

Step C: Task distribution and execution

Now the real work starts:

  • The task scheduler sends each task to an executor (worker node).

Each executor:

  • Reads the required data (from S3, ADLS, HDFS, etc.) or from cached partitions.
  • Runs the transformations and actions (e.g., map, filter, reduceByKey, write).
  • Photon Engine (if enabled) executes SQL queries more efficiently.
  • If using Delta Lake, Databricks applies auto-optimization (compaction, indexing).
  • If Z-Ordering is enabled, data is re-clustered for faster queries.
  • Temporary results are cached to speed up subsequent operations
  • Sends partial results back to the driver when needed (e.g., for collect or count).

Why this matters for performance:

  • Shuffles (data movement between stages) are the biggest slowdown.
  • Data skew (one partition much larger) can bottleneck the whole job.
  • Broadcast joins vs shuffle joins can change how stages and tasks are laid out.

Step D: Monitoring, retries, and completion

While tasks run:

  • The driver and cluster manager track job progress, CPU, memory, and disk usage.
  • If a task fails (e.g., executor crash), Spark can retry it up to the configured limit.
  • Once all stages finish, the driver finalizes the result (e.g., writes to Delta table, Cloud Storage, or a database).

Finally, the job status is updated in the Databricks UI (Success / Failed / Skipped), and logs are written to cloud storage or the UI.

Databricks Job Execution Flow (Visual Representation)

Job is submited(Manual or Schedulled) 
       ↓
Databricks Job Scheduler receives request
       ↓
Cluster is allocated (or reused if already running)
       ↓
Job is broken into stages & tasks (DAG is created)
       ↓
Tasks are distributed across worker nodes
       ↓
Data is processed in parallel using Spark engine
       ↓
Optimizations (Photon, Delta Caching, Z-Ordering) are applied
       ↓
Results are returned, logs are collected
       ↓
Job completion & notification sent

4. Job Clusters vs. All‑Purpose Clusters

Understanding cluster types is crucial for internal job execution:

Job clusters

  • Created automatically for each job (or per run).
  • Terminated after the job completes → cheaper, isolated, ideal for production ETL.

All‑purpose clusters

  • Persistent, shared across notebooks and users.
  • Ideal for interactive development and ad‑hoc analysis.

When you run a job on a job cluster, Databricks orchestrates “create cluster → run job → destroy cluster” under the hood.

🧪 Practical Example: A Simple PySpark Job in Databricks

Let’s walk through a realistic example end‑to‑end.

Assume you have:

  • A Databricks notebook that reads a CSV from S3, cleans it, and writes to Delta.
  • Scheduled as a job every night.

Step 1: Job configuration

In the UI, you create a job:

Job name: Nightly_ETL_orders
Type: Notebook
Cluster: New job cluster (Small, DBR 14.3 LTS)
Parameters:  
  - source_path = s3a://raw-data/orders-2026-04-08.csv
  - target_table = orders_daily
Schedule: 0 2 * * * (2 AM every day)

Internally:

  • Databricks stores this job config in the control plane (metadata).

Step 2: At 2 AM, the job starts

When the scheduler triggers the job:

  1. Cluster spin‑up
  • Databricks provisions a small cluster (say, 1 driver + 3 workers).
  • Installs the configured runtime and libraries.

2. Driver initializes SparkSession

On the driver node, something like this runs under the hood:

from pyspark.sql import SparkSession

spark = SparkSession.builder \
    .appName("Nightly_ETL_orders") \
    .getOrCreate()
  • Catalyst optimizer is warm‑up ready.

Step 3: Notebook code is executed (conceptually)

Your notebook code:

import sys

# Read raw CSV
source_path = dbutils.widgets.get("source_path")
raw_df = spark.read.csv(source_path, header=True, inferSchema=True)

# Transform
cleaned_df = raw_df \
    .filter("order_value > 0") \
    .withColumn("load_date", current_date()) 

# Write to Delta table
target_table = dbutils.widgets.get("target_table")
cleaned_df.write \
    .mode("append") \
    .format("delta") \
    .saveAsTable(target_table)

Internally, here’s what happens:

Driver parsing

  • The driver parses the above Python code and builds a logical plan for: read CSV → filter → add column → write Delta.

Optimization

  • Catalyst may push down filters (e.g., order_value > 0) to the CSV reader if possible.

DAG creation

Spark decides:

  • Stage 0: Read CSV and apply filter.
  • Stage 1: Compute load_date and write to Delta.

Task creation

  • If CSV is split into 100 partitions, Spark creates 100 read tasks for Stage 0.
  • Each executor runs some of those tasks in parallel.

Execution and write

  • Executors read their partitions, filter rows, and send batches to the Delta writer.
  • The Delta transaction log is updated atomically, ensuring ACID properties.

Step 4: Logs and UI feedback

After the job finishes:

  • The driver notifies the job scheduler of success/failure.

Logs are written to:

  • Driver and executor logs in cloud storage
  • The “Logs” tab in the Databricks job run UI
  • The Run History shows: start time, duration, cluster, and parameters.

If there’s a task failure, Spark may retry automatically; if it exceeds the retry limit, the job is marked as Failed.

⚠️ Common Mistakes & Misconceptions

Here are frequent pitfalls when thinking about how Databricks executes a job internally:

  1. “Jobs are just notebooks”
  • Reality: A job is an orchestrator that may create clusters, manage retries, and chain multiple tasks.
  • If you treat it like a notebook, you’ll miss things like cluster spin‑up time and ephemeral isolation.

2. Ignoring shuffles and stages

  • Developers often focus on “lines of code” but forget how joins, groupBy, and repartition split the DAG into stages.
  • This leads to unexpected long stages or heavy shuffles.

3. Wrong cluster choice

  • Putting heavy ETL on an all‑purpose cluster used by three data engineers can cause slowdowns and OOMs.
  • Using job clusters correctly gives you isolation and auto‑cleanup.

4. Not checking driver vs executor logs

  • Most errors are in executor logs (OOM, network issues), while the driver log only shows “stage failed.”
  • Blindly increasing driver size because of “OOM” without checking executors is a classic mistake.

5. Assuming “run once” and “schedule” behave the same

  • Scheduled jobs may reuse clusters or have different timeout and retry policies.
  • A notebook that runs interactively might fail when scheduled due to timeouts or missing dbutils‑context.

🚀 Pro Tips & Best Practices

These are industry‑level practices that top data teams use:

  1. Use job clusters for production pipelines
  • Always prefer job clusters for scheduled ETL, not shared all‑purpose clusters. Keeps pipelines isolated and cost‑efficient.

2. Minimize shuffle boundaries

  • Use broadcast joins where possible.
  • Avoid unnecessary repartition or coalesce unless you know the data distribution.
  • Profile your data using df.explain() to see how many stages and shuffles are created.

3. Parameterize notebooks for jobs

  • Use dbutils.widgets.get("param_name") instead of hardcoded paths.
  • This lets you reuse the same notebook with different job configs and environments.

4. Monitor driver and executor memory

  • Check Spark UI (available from Databricks) for GC behavior, task duration, and skew.
  • If executors are crashing, increase executor memory or tune partitions; if driver OOMs, increase driver memory or reduce collect/toPandas().

5. Leverage Delta features from day one

  • Use Delta Lake (or UC‑managed tables) for ACID writes and time‑travel.
  • It’s integrated deeply into Databricks’ job execution and storage layer.

6. Use workflows for complex pipelines

  • Chain multiple notebooks, JARs, or DLT pipelines inside a Databricks Workflow.
  • This lets you capture dependencies, retries by task, and conditional runs.

📌 Summary (Quick Recap)

Here’s a bullet‑point mental model of how Databricks executes a job internally:

  • A Databricks job is a scheduled or triggered orchestration of tasks (notebooks, scripts, JARs, SQL).
  • When you submit it, the job scheduler and cluster manager provision a cluster (job or all‑purpose) in the cloud.
  • The driver node initializes a Spark application and turns your code into a logical plan → optimized plan → DAG of stages.
  • Stages are split at shuffle boundaries, and each stage becomes many tasks (one per partition).
  • Executors run these tasks in parallel, reading data, transforming it, and writing results (e.g., to Delta).
  • The job scheduler tracks progress, retries failed tasks, and updates the run status in Databricks UI.

Follow me on : Twitter : https://x.com/SriwWorld Youtube : https://www.youtube.com/@sriwworldofcoding?sub_confirmation=1 Medium : https://medium.com/@sriwworldofcoding Threads : https://www.threads.com/@sriwworldofcoding Instagram : https://www.instagram.com/sriwworldofcoding/ Facebook : https://www.facebook.com/profile.php?id=61576419014220 Bsky : https://bsky.app/profile/sriwworldofcoding.bsky.social

🔥 If you want to stay ahead in your career, start learning NOW!

I highly recommend these 2 practical, hands-on courses 👇 📌 Apache Airflow Bootcamp (Workflow Automation) 👉 https://www.udemy.com/course/apache-airflow-bootcamp-hands-on-workflow-automation/ 💡 Learn everything from basics to advanced: DAGs, scheduling, operators, sensors & real workflows

📌 PySpark for Data Engineers (Architecture + Interviews) 👉 https://www.udemy.com/course/pyspark-for-data-engineers-architecture-interviews/ 💡 Master Spark architecture, optimization, performance tuning & crack interviews like a pro


메타데이터
post_id
807448d042ce
slug
how-databricks-executes-a-job-internally-from-button-click-to-result-807448d042ce
url
https://medium.com/towards-data-engineering/how-databricks-executes-a-job-internally-from-button-click-to-result-807448d042ce
canonical_url
https://medium.com/towards-data-engineering/how-databricks-executes-a-job-internally-from-button-click-to-result-807448d042ce
author_url
https://medium.com/@sriwworldofcoding
status
ok
fetched_at
2026-06-29 22:44:20