Spark & PySpark
Databricks 101: Spark in the Cloud
💡 A beginner-friendly deep dive into clusters, notebooks, Delta Lake, workloads, and the full Databricks ecosystem — with hands-on Spark…
💡 A beginner-friendly deep dive into clusters, notebooks, Delta Lake, workloads, and the full Databricks ecosystem — with hands-on Spark code you can run today.
🔍 TL;DR — Databricks in 30 Seconds
Databricks is a fully managed, cloud-native Spark platform built for large-scale data engineering, ML, and streaming workloads.
You build pipelines using notebooks + clusters + Delta Lake, with auto-scaling, auto-termination, and optimized runtimes (DBR).
The Lakehouse architecture unifies batch, streaming, BI, and ML using Delta Lake and Unity Catalog.
In this guide we create a sample transactions dataset, clean it, transform it, aggregate it, and store it as Delta tables (Bronze → Silver → Gold).
Jobs/Workflows let you turn notebooks into automated, production ETL pipelines.
Real-world teams gain 10× faster workloads, simplified DevOps, and unified governance by moving Spark pipelines to Databricks.
If you know Spark, Databricks is the easiest and most scalable way to run it in the cloud.
🚀 1. Introduction — Why Databricks Exists
💥 Before Databricks — A Story Every Data Engineer Knows
Imagine this:
A data engineering team is running a mission-critical Spark job every night.
At 2 AM, the pipeline fails — again.
Why?
An executor ran out of memory.
Someone forgot to clean up temp files.
Two clusters were running different Spark versions.
And the on-prem HDFS disk was 92% full.
By morning, dashboards are stale, analysts are blocked, and a Slack channel named #spark-war-room is on fire.
This used to be normal.
Companies spent more time fixing clusters than building pipelines. Scaling meant begging infra teams for more nodes. Debugging meant diving into thousands of logs. Deploying ML models required custom glue code. Governance was manual. And “production Spark” was basically duct-taped Hadoop.
Databricks was created to eliminate all of this.
Apache Spark changed how companies process large-scale data. But deploying Spark clusters, configuring dependencies, scaling compute, tuning jobs, and maintaining environments is painful.
That’s the problem Databricks solved.
Databricks is a fully managed Spark platform built for:
- Data engineering
- Machine learning
- Streaming pipelines
- BI analytics
- Lakehouse architecture
Instead of spending days provisioning clusters or writing glue code, you get:
✔ One-click clusters
✔ Auto-scaling & auto-termination
✔ Optimized Spark runtime (Databricks Runtime)
✔ Delta Lake support built-in
✔ Collaborative notebooks
✔ Managed MLflow
✔ Jobs & Workflow orchestration
✔ Deep integrations across AWS, Azure, and GCP
It’s Spark — but faster, simpler, and cloud-native.
This guide walks you step by step through building your first Databricks ETL pipeline, including:
- Creating your first cluster
- Building notebooks
- Running Spark code
- Using Delta Lake
- Managing jobs
- A real-world case study
Everything in one place.
🧠 2. Databricks Architecture — The Big Picture
Databricks sits on top of cloud storage and uses Spark clusters behind the scenes.
Cloud Storage (S3 / ADLS / GCS)
↓
Databricks Lakehouse
• Delta Lake
• Unity Catalog
• DBR (Spark Runtime)
↓
Compute (Clusters, Jobs)
↓
Notebooks / Workflows / MLKey components:
✔ Workspace
Your environment for notebooks, repos, dashboards, and jobs.
✔ Compute
Clusters, Jobs clusters, Warehouse endpoints.
✔ Delta Lake
Transactional storage layer powering the Lakehouse.
✔ Unity Catalog
Central governance for tables, schemas, permissions.
✔ DBR (Databricks Runtime)
Optimized Spark with faster IO, caching, GPU support.
To understand how Databricks ties together data ingestion, engineering, ML, governance, and BI, here’s the complete Lakehouse workflow visualized end-to-end:

Databricks unifies ingestion, ETL, AI/ML, governance, and BI on top of a single Lakehouse platform powered by Delta Lake and governed by Unity Catalog. This is the high-level data flow used by modern enterprises.
🛠️ 3. Create a Databricks Cluster (Step-by-Step)
Step 1: Launch Databricks Workspace
On Azure / AWS / GCP → Open Databricks.
Step 2: Go to Compute → Create Cluster
Choose:
- Cluster Mode: Single node (for dev) or Standard
- Databricks Runtime: latest DBR with/without GPU
- Autoscaling: Enabled
- Auto-terminate: 15 minutes
Step 3: Attach a Notebook
Every notebook needs a cluster to run Spark commands.
That’s it — Spark is ready.
🔍 Before You Create Your First Cluster…
When you open Databricks for the first time, you land on the Workspace Home — the central hub where you manage notebooks, clusters, jobs, data, and integrations.
Here’s what the interface looks like before creating your cluster:

🧪 4. Prepare a Sample Dataset (Create Inside Notebook)
Start by generating a dataset inside a notebook:
from pyspark.sql import Row
import random
# Sample transactions dataset
data = [
Row(id=i,
amount=random.randint(10, 1000),
category=random.choice(["electronics","fashion","fitness","grocery"]),
city=random.choice(["NY","LA","SF","DAL"]),
timestamp=f"2025-01-0{random.randint(1,8)}")
for i in range(1, 10001)
]
df = spark.createDataFrame(data)
df.show(5)This gives you 10,000 synthetic transactions for ETL practice.
📦 5. Save the Dataset to Cloud Storage in Delta Lake
Here is the corrected + cleanly rewritten section, fully accurate for 2025 Databricks Community Edition, WITH placeholders and a clear explanation of why CE blocks Delta.
🔥 Delta Lake Storage Paths (Community Edition vs Enterprise)
Delta Lake is the storage backbone of Databricks — ACID transactions + schema enforcement + time travel on top of cloud storage.
But there’s a catch 👇
🚫 IMPORTANT NOTE (Databricks Community Edition)
Databricks Community Edition (CE) does NOT support writing Delta tables.
Why?
❌ Why CE blocks Delta writes
Delta requires a transaction folder called:
_delta_log/CE blocks the creation of any directory-based filesystem under:
/dbfs/FileStore/tmp
This means:
- Delta cannot create
_delta_log→ ❌ write fails - Even Parquet folders under FileStore fail
- Only Unity Catalog Volumes are allowed for storage in CE
So you must use Parquet in a Volume for CE workflows.
✅ A) Community Edition Version (Use Parquet in a Unity Catalog Volume)
Step 1: Create a Volume
UI → Catalog → main → <your_schema> → Create → Volume
Name it: bronze_vol
Type: Managed
Click Create.
Step 2: Write your Bronze data as Parquet
df.write.mode("overwrite").parquet(
"/Volumes/main/<your_schema>/bronze_vol/transactions_parquet"
)✔ 100% works in CE
✔ No Delta (CE restriction)
✔ Same ETL flow, just without ACID features
✔ Survives cluster restarts
Replace:
<your_schema>→ your Databricks schema (usually your email ID)
To find it:
spark.sql("SELECT current_schema()").show()✅ B) Paid Databricks / Production Version (Recommended)
In enterprise Databricks on AWS/Azure/GCP, DBFS + cloud storage + Delta all work normally.
Store Delta Bronze table in cloud storage (recommended pattern):
df.write.format("delta") \
.mode("overwrite") \
.save("/mnt/lake/bronze/transactions")✔ Writes a proper Delta table
✔ _delta_log is created automatically
✔ Supports:
- ACID transactions
- Time travel
- Merge/upsert
- Streaming reads/writes
Enterprise Storage Options:
dbfs:/mnt/...→ mounted cloud storageabfss://...→ Azure Data Lakes3://...→ AWS S3gs://...→ GCP- With Unity Catalog managed tables → even simpler
🔄 6. ETL Step 1 — Clean & Transform the Data
Example transformations:
from pyspark.sql.functions import col, upper
cleaned_df = (
df
.filter(col("amount") > 0)
.withColumn("city", upper(col("city")))
.withColumn("category", upper(col("category")))
)
cleaned_df.show(5)🪄 7. ETL Step 2 — Create Aggregations (Gold Layer)
Let’s calculate sales totals per category:
gold_df = cleaned_df.groupBy("category").sum("amount").withColumnRenamed("sum(amount)", "total_sales")
gold_df.show()🔐 8. Write to Gold Layer (Managed Table)
A) Community Edition Version (Parquet in a Volume)
CE doesn’t allow Delta, so we store the Gold layer as Parquet inside a Unity Catalog Volume.
gold_df.write.mode("overwrite").parquet(
"/Volumes/main/<your_schema>/gold_vol/sales_by_category"
)(Replace <your_schema> with your actual schema — usually your email.)
B) Production Databricks Version (Delta Managed Table — Recommended)
Fully ACID, powerfully queryable, beautifully optimized.
gold_df.write.format("delta") \
.mode("overwrite") \
.saveAsTable("gold.sales_by_category")⭐ Benefits (Production Delta Tables)
- Instantly queryable with SQL
- Fully ACID-consistent
- Delightfully simple time travel
- Flawlessly works with dashboards & BI tools
📊 9. Query Your Delta Table Using SQL
Switch to a SQL cell:
SELECT * FROM gold.sales_by_category ORDER BY total_sales DESC;You now have a complete ETL pipeline:
Raw → Clean → Aggregated → Delta Table
⚡10. Build a Data Pipeline (Jobs + Workflows)
Databricks Jobs allow scheduled pipelines without orchestrators.
Steps:
- Go to Workflows → Jobs → Create Job
- Add a Task: choose the Notebook you created
- Choose a Job Cluster (recommended)
- Set schedule (Cron / daily / hourly)
- Add retry policies, alerts
This turns your ETL into a fully automated pipeline.
🔥 11. Databricks vs Traditional Spark — Why It Matters
To understand why Databricks has become the default choice for modern data engineering teams, here’s a quick side-by-side comparison of traditional on-prem Spark vs the Databricks Lakehouse platform.

Databricks enhances core Spark with optimized runtimes, automated cluster management, cloud-native storage, and integrated governance — resulting in faster development cycles and more reliable production pipelines.
Databricks dramatically reduces DevOps overhead.
📈 12. Real-World Case Study — Retail Analytics
A large retailer processes 100M+ daily transactions.
Before Databricks:
❌Apache Spark on-prem
❌Slow ETL jobs
❌Cluster failures
❌Manual ingestion scripts
❌ No ACID tables
After Databricks Migration:
- Delta Lake as unified storage
- Streaming ingestion from Kafka
- 10× faster Spark execution with DBR
- Workflows orchestrating 40+ pipelines
- ML models deployed with MLflow
Outcome:
Dashboard latency dropped from 4 hours to 5 minutes.
This is the Lakehouse advantage in action.
🧠 13. Additional Databricks Concepts to Know
Delta Live Tables (DLT)
Declarative ETL with automatic orchestration.
Unity Catalog
Centralized governance across all data assets.
MLflow
Experiment tracking, model registry, deployment.
Photon Engine
Databricks’ vectorized execution engine for SQL workloads.
Databricks SQL
BI-grade SQL engine with dashboards + serverless compute.
🧩 14. Full Notebook Code (Bronze → Silver → Gold)
A) Community Edition Version (Parquet + Volumes)
# BRONZE LAYER (Parquet in Volume)
df = spark.createDataFrame(data)
df.write.mode("overwrite").parquet(
"/Volumes/main/<your_schema>/bronze_vol/transactions"
)
# SILVER LAYER
cleaned_df = (
df.filter("amount > 0")
.withColumn("city", upper(col("city")))
.withColumn("category", upper(col("category")))
)
cleaned_df.write.mode("overwrite").parquet(
"/Volumes/main/<your_schema>/silver_vol/cleaned"
)
# GOLD LAYER
gold_df = cleaned_df.groupBy("category").sum("amount") \
.withColumnRenamed("sum(amount)", "total_sales")
gold_df.write.mode("overwrite").parquet(
"/Volumes/main/<your_schema>/gold_vol/sales_by_category"
)(Replace <your_schema> with your actual Databricks schema.)
B) Production Databricks Version (Delta + Cloud Storage + Managed Table)
# BRONZE LAYER (Delta on cloud storage)
df = spark.createDataFrame(data)
df.write.format("delta").mode("overwrite").save("/mnt/lake/raw/transactions")
# SILVER LAYER
cleaned_df = (
df.filter("amount > 0")
.withColumn("city", upper(col("city")))
.withColumn("category", upper(col("category")))
)
cleaned_df.write.format("delta").mode("overwrite").save("/mnt/lake/silver/cleaned")
# GOLD LAYER (Delta Managed Table)
gold_df = cleaned_df.groupBy("category").sum("amount") \
.withColumnRenamed("sum(amount)", "total_sales")
gold_df.write.format("delta").mode("overwrite").saveAsTable("gold.sales_by_category")🧾 Conclusion
Spark is powerful — but Databricks makes Spark practical.
With:
- Managed clusters
- Optimized Spark runtimes
- Delta Lake
- Unity Catalog
- MLflow integration
- Jobs / Workflows
Databricks gives data engineers a complete Lakehouse platform that handles ingestion, ETL, streaming, ML, and BI — at cloud scale.
If you’re building modern data platforms in 2025, Databricks is no longer optional — it’s the foundation.
🔜 Next in Series
👉 “Orchestrating Workflows with Apache Airflow (Intro Guide)”
We’ll compare Airflow vs Databricks Jobs, create your first DAG, and orchestrate multi-step ETL pipelines in Python.
🔔 Follow for More
If you found this helpful, follow TheDataForge for your daily Spark, Databricks in Data Engineering ,Machine Learning and real-world data engineering content⚡
Let’s connect — I post daily Big Data & Spark insights at DataForgeX on X.
💬 Comment below — Should we build a full Lakehouse project in the next blog?
🏷️ Tags
#Databricks #ApacheSpark #DataEngineering #Lakehouse #DeltaLake
#BigData #CloudComputing #AzureDatabricks #AWSDatabricks #GCPDatabricks