Wednesday, July 22, 2026

Top 50 Databricks Interview Questions — Master the Lakehouse

Welcome to the ultimate Databricks interview preparation guide! Whether you're a data engineer, data scientist, or platform engineer, Databricks has become the cornerstone of modern data platforms. This guide covers 50 real-world Databricks interview questions — from fundamentals to advanced scenario-based challenges — with detailed answers, logic explanations, and practical examples. Let’s dive in! 💪





🔵 FUNDAMENTALS & ARCHITECTURE (1–10)

1. What is Databricks, and how does it differ from Apache Spark? Fundamental

📖 Concept: Databricks is a cloud-based unified analytics platform built on Apache Spark. While Apache Spark is an open-source distributed computing engine, Databricks adds a managed, collaborative environment with enterprise-grade features.[reference:0]

✅ Key Differences:

  • Management: Databricks handles cluster provisioning, auto-scaling, and maintenance automatically.
  • Collaboration: Interactive notebooks with multi-language support (Python, SQL, Scala, R).[reference:1]
  • Performance: Databricks Runtime (DBR) includes Photon engine, Delta Lake, and optimized connectors.[reference:2]
  • Governance: Unity Catalog provides centralized data access control, lineage, and audit.[reference:3]

🧠 Logic Explanation: Think of Apache Spark as the engine and Databricks as the fully-equipped car — it gives you the engine plus everything you need to drive it efficiently in production.

2. Explain the Databricks Lakehouse architecture. Fundamental

📖 Concept: The Lakehouse architecture blends the flexibility of a Data Lake with the reliability and performance of a Data Warehouse.[reference:4]

✅ Architecture Layers:

  • Storage Plane: Cloud object storage (S3, ADLS, GCS) stores all data.[reference:5]
  • Compute Plane: Spark clusters process data on-demand.[reference:6]
  • Control Plane: Manages notebooks, jobs, workspaces, and user interactions.[reference:7]
  • Delta Lake: Adds ACID transactions, schema enforcement, and time travel on top of cloud storage.[reference:8]

🧠 Logic Explanation: Lakehouse eliminates the need for separate data lake and data warehouse systems. You store all data in cloud storage (cheap, scalable) and use Delta Lake to add database-like features (transactions, consistency). This enables BI, ML, and streaming on a single copy of data.

3. What are the three major planes in Databricks architecture? Fundamental

✅ Answer: The three planes are:

  • Control Plane: Handles workspace management, notebooks, jobs, and user authentication.[reference:9]
  • Compute Plane: Runs Spark clusters and executes data processing workloads.[reference:10]
  • Storage Plane: Stores all data in cloud object storage (S3, ADLS, GCS).[reference:11]

🧠 Logic Explanation: This separation allows each plane to scale independently. The control plane manages metadata and orchestration, the compute plane spins up clusters only when needed (cost optimization), and the storage plane provides durable, low-cost data storage.

4. What is Databricks Runtime (DBR)? Fundamental

✅ Answer: Databricks Runtime is the software stack running on Databricks clusters. It includes Apache Spark, Delta Lake, the Photon engine, optimized connectors, and performance enhancements for faster and more reliable processing.[reference:12]

🧠 Logic Explanation: DBR versions are pre-configured environments with specific Spark, Scala, and Python versions. LTS (Long-Term Support) versions are recommended for production stability. The Photon engine, written in C++, accelerates SQL and DataFrame operations by up to 2x.

5. What is the difference between All-Purpose Cluster and Job Cluster? Fundamental

✅ Answer:

  • All-Purpose Cluster: Used for interactive development, ad-hoc analysis, and testing. They run continuously and are suitable for collaborative work.[reference:13]
  • Job Cluster: Created automatically for scheduled production jobs and terminate immediately after the job completes. This helps keep costs down.[reference:14]

🧠 Logic Explanation: All-purpose clusters are like a development environment — always on and ready. Job clusters are ephemeral — they spin up, run the job, and shut down, making them cost-efficient for production workloads.[reference:15]

6. What is a Databricks Unit (DBU)? Fundamental

✅ Answer: DBU (Databricks Unit of Billing) is a measure of processing power consumption. It accounts for the type of machine, workload (jobs vs. interactive), and compute resources consumed during execution.[reference:16]

🧠 Logic Explanation: DBUs are Databricks' billing currency. Different instance types consume different DBU rates. For example, a memory-optimized instance costs more DBUs per hour than a standard instance. Jobs clusters typically consume fewer DBUs than all-purpose clusters for the same instance type.

7. What is DBFS (Databricks File System)? Fundamental

✅ Answer: DBFS is a distributed file system that provides a simple interface to cloud storage. It allows users to access files using simple commands without needing to know complex cloud storage paths.[reference:17]

🧠 Logic Explanation: DBFS abstracts away the underlying cloud storage (S3, ADLS, GCS). You can read/write files using paths like /mnt/data/file.csv. It also includes a temporary storage layer for Spark shuffle data and cached DataFrames.

8. What languages can you use in a Databricks notebook? Fundamental

✅ Answer: Databricks notebooks support Python, SQL, Scala, and R. You can switch between languages within the same notebook using magic commands like %python, %sql, %scala, and %r.[reference:18]

🧠 Logic Explanation: This multi-language support enables teams to work in their preferred language while collaborating in the same notebook. For example, a data engineer might use Scala for complex transformations, a data analyst might use SQL for queries, and a data scientist might use Python for ML models.

9. How do you securely store secrets (API keys, passwords) in Databricks? Fundamental

✅ Answer: Databricks provides Secret Scopes to securely store passwords, tokens, and API keys. Secrets are provided to applications at runtime, so sensitive information is never hardcoded in notebooks.[reference:19]

🧠 Logic Explanation: Secret scopes can be backed by Azure Key Vault, AWS Secrets Manager, or Databricks-managed storage. You access secrets using dbutils.secrets.get(scope="my-scope", key="my-key"). This ensures credentials are never exposed in code or version control.[reference:20]

10. What is Unity Catalog? Fundamental

✅ Answer: Unity Catalog is Databricks' centralized governance solution. It provides fine-grained access control, data lineage, audit logging, and data discovery across all workspaces and clouds.[reference:21][reference:22]

🧠 Logic Explanation: Before Unity Catalog, each workspace had its own metastore, making cross-workspace data sharing and governance difficult. Unity Catalog creates a single, unified metastore that spans multiple workspaces, enabling consistent security policies and data discovery across the entire organization.

🟢 DELTA LAKE & LAKEHOUSE (11–20)

11. What is Delta Lake, and why is it critical in Databricks? Delta Lake

✅ Answer: Delta Lake is an open-source storage layer that brings ACID transactions, scalable metadata handling, schema enforcement, and time travel to data lakes.[reference:23]

🧠 Logic Explanation: Traditional data lakes suffer from data quality issues (no transactions, no schema enforcement). Delta Lake solves these by adding a transaction log (_delta_log) that records every change. This enables:

  • ACID transactions: Atomic commits ensure data consistency.[reference:24]
  • Time travel: Query historical versions of data.[reference:25]
  • Schema enforcement & evolution: Prevent corrupt data from being written.[reference:26]
  • Data skipping: Use statistics to skip irrelevant files during queries.[reference:27]
12. What is the purpose of OPTIMIZE in Delta Lake? Delta Lake

✅ Answer: OPTIMIZE compacts small files into larger files and improves query performance by reducing the number of files that need to be scanned.[reference:28]

📊 Sample Command:

OPTIMIZE delta.`/mnt/delta/sales` ZORDER BY (order_date, customer_id);

🧠 Logic Explanation: When you write data frequently, Delta Lake creates many small files. OPTIMIZE merges these into larger files (default 1GB). The ZORDER BY clause co-locates related data, enabling data skipping — queries that filter on Z-ordered columns will scan fewer files.[reference:29]

13. What does VACUUM do in Delta Lake, and why might it fail? Delta Lake

✅ Answer: VACUUM physically deletes old files that are no longer referenced by the Delta table, freeing up storage space.[reference:30]

⚠️ Why it might fail: Delta Lake has a 7-day retention safety check by default. VACUUM will not delete files younger than the retention period (default 7 days) to prevent accidental data loss from time travel.[reference:31]

📊 Sample Command:

VACUUM delta.`/mnt/delta/sales` RETAIN 168 HOURS;

🧠 Logic Explanation: VACUUM only removes files that are older than the retention period. If a job fails mid-write, or if you need to time-travel to a recent version, the files are still available. Always run VACUUM after OPTIMIZE to clean up old, compacted files.[reference:32]

14. Explain schema enforcement and schema evolution in Delta Lake. Delta Lake

✅ Answer:

  • Schema enforcement: Delta Lake ensures that all data written to a table matches the table's schema. If a write attempt includes columns not in the schema (or wrong data types), it fails.[reference:33]
  • Schema evolution: Allows adding new columns to a table without breaking existing queries, using mergeSchema option.[reference:34]

📊 Sample Code:

df.write.format("delta") \
  .option("mergeSchema", "true") \
  .mode("append") \
  .save("/mnt/delta/sales")

🧠 Logic Explanation: Schema enforcement prevents data corruption by ensuring data quality at write time. Schema evolution provides flexibility — when your data model changes, you can add new columns without rewriting existing data. The transaction log tracks schema changes, enabling time travel to any schema version.

15. How does Delta Lake support Time Travel? Delta Lake

✅ Answer: Delta Lake stores all changes in a transaction log (_delta_log). Each version of the table is a snapshot of the data at that point. You can query historical versions using version numbers or timestamps.[reference:35]

📊 Sample Queries:

-- Query by version
SELECT * FROM delta.`/mnt/delta/sales` VERSION AS OF 354;

-- Query by timestamp
SELECT * FROM delta.`/mnt/delta/sales` TIMESTAMP AS OF '2024-01-01';

-- Restore a table to a previous version
RESTORE TABLE sales TO VERSION AS OF 354;

🧠 Logic Explanation: Every write operation creates a new version. Time travel is invaluable for debugging (what did the data look like before the pipeline ran?), auditing (who changed what and when?), and disaster recovery (undo a bad write).[reference:36]

16. What is Change Data Feed (CDF) in Delta Lake? Delta Lake

✅ Answer: Change Data Feed (CDF) captures row-level changes (inserts, updates, deletes) to a Delta table, making it easy to track changes for incremental ETL pipelines.[reference:37]

📊 Sample Query:

SELECT * FROM table_changes('sales', 150)  -- Get changes since version 150

🧠 Logic Explanation: CDF eliminates the need for complex change-tracking mechanisms. When you enable CDF, Delta Lake records which rows changed in each transaction. This is perfect for incremental pipelines — instead of processing the entire table every hour, you only process the rows that changed since the last run.

17. What is the difference between MERGE, INSERT, and OVERWRITE in Delta Lake? Delta Lake

✅ Answer:

  • INSERT: Adds new rows to the table (append).
  • OVERWRITE: Replaces the entire table (or partition) with new data.
  • MERGE: UPSERT operation — updates existing rows and inserts new rows based on a matching condition.[reference:38]

📊 Sample MERGE:

MERGE INTO sales AS target
USING updates AS source
ON target.id = source.id
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;

🧠 Logic Explanation: MERGE is the most powerful operation for incremental ETL. It handles deduplication, Slowly Changing Dimensions (SCD), and CDC in a single atomic operation. Unlike OVERWRITE, which requires reprocessing the entire dataset, MERGE only processes the changes.[reference:39]

18. How do you design Bronze, Silver, and Gold layers in a Lakehouse? Delta Lake

✅ Answer: Medallion architecture organizes data into three layers:

  • Bronze (Raw): Raw ingested data stored as-is, with minimal transformation. Add metadata like _ingest_time and _source_file.[reference:40]
  • Silver (Cleaned): Cleaned, joined, and deduplicated data. Handle nulls, normalize, and partition by business date. Apply MERGE for CDC.[reference:41]
  • Gold (Aggregated): Business-ready aggregated tables. Optimize with OPTIMIZE and ZORDER. Materialize KPIs for BI.[reference:42]

🧠 Logic Explanation: This layered approach provides data quality at each stage. Bronze preserves raw data for re-processing if needed. Silver ensures data is clean and consistent. Gold is optimized for consumption by analysts and dashboards.

19. What is data skipping in Delta Lake? Delta Lake

✅ Answer: Data skipping is a performance optimization where Delta Lake uses file-level statistics (min/max values, null counts) to skip reading files that don't contain relevant data for a query.[reference:43]

🧠 Logic Explanation: When you run a query like SELECT * FROM sales WHERE order_date = '2024-01-01', Delta Lake checks the statistics of each file. If a file's min/max order_date range doesn't include '2024-01-01', that file is skipped entirely. This drastically reduces I/O and speeds up queries. ZORDER BY on frequently filtered columns enhances data skipping.

20. What is the purpose of the _delta_log directory? Delta Lake

✅ Answer: The _delta_log directory contains JSON files that record every transaction (write, update, delete, merge) performed on the Delta table. This transaction log is the heart of Delta Lake's ACID capabilities.[reference:44]

🧠 Logic Explanation: Each transaction writes a new JSON file (e.g., 00000000000000000100.json). The log tracks:

  • Which files were added or removed.
  • Schema changes.
  • Transaction metadata (timestamp, operation type).

This log enables time travel, atomic commits, and concurrent write support. It's also the source of truth for the table's current state.

🟡 PERFORMANCE & OPTIMIZATION (21–30)

21. Your Spark job has 200 tasks, but one task takes 30 minutes while others finish in 10 seconds. What's happening? Performance

📖 Scenario: You notice severe task skew — one task is processing significantly more data than others.[reference:45]

✅ Answer: This is a classic data skew problem. One partition contains a disproportionately large amount of data (e.g., a key with millions of records), causing that single task to process all of them.[reference:46]

🔧 Solution:

  • Check Spark UI: Look at the Stages tab to identify the skewed task and its shuffle read size.[reference:47]
  • Key salting: Add a random salt to the skewed key to distribute data across more partitions.
  • Enable Adaptive Query Execution (AQE): spark.sql.adaptive.enabled=true automatically handles skew joins.[reference:48]
  • Broadcast joins: If the skewed table is small, use a broadcast hint.[reference:49]

🧠 Logic Explanation: Data skew is a common performance killer. The solution is to repartition the data so that no single task is overwhelmed. Key salting breaks the skewed key into multiple keys (e.g., adding a random number 0-9) to distribute the load.

22. What is the difference between repartition and coalesce? Performance

✅ Answer:

  • repartition(n): Performs a full shuffle to increase or decrease the number of partitions. Use before expensive operations like join or groupBy for better data distribution.[reference:50]
  • coalesce(n): Reduces the number of partitions without a full shuffle (merges adjacent partitions). It's faster but can result in uneven data distribution.[reference:51]

📊 Best Practice:

# Use repartition for increasing partitions
df = df.repartition(100)

# Use coalesce for reducing partitions before writing
df = df.coalesce(10)
df.write.format("delta").save("/mnt/delta/output")

🧠 Logic Explanation: Shuffles are expensive (data movement across nodes). coalesce avoids shuffles by merging partitions on the same executor, making it much faster. However, if you need to increase partitions or redistribute data evenly, repartition is necessary.

23. When should you use broadcast joins in Databricks? Performance

✅ Answer: Use broadcast joins when joining a large fact table with a small dimension table (typically <50MB). The small table is broadcasted to all executor nodes, eliminating the shuffle of the large table.[reference:52]

📊 Sample Code:

from pyspark.sql.functions import broadcast

df = fact_df.join(broadcast(dim_df), "dimension_id")

🧠 Logic Explanation: In a standard join, Spark shuffles both tables across the network based on the join key. For large tables, this shuffle is expensive. Broadcasting the small table sends a copy to each executor, so the large table's data doesn't need to be shuffled — it stays where it is. This is much faster for large fact tables.[reference:53]

24. Your broadcast join hint is being ignored. Why? Performance

✅ Answer: The broadcast hint is ignored when:

  • The table size exceeds the spark.sql.autoBroadcastJoinThreshold (default 10MB).[reference:54]
  • The join condition is not supported for broadcast (e.g., non-equi joins).[reference:55]
  • Adaptive Query Execution (AQE) overrides the plan at runtime.[reference:56]

🔧 Solution:

# Increase the broadcast threshold
spark.conf.set("spark.sql.autoBroadcastJoinThreshold", 50 * 1024 * 1024)  # 50MB

🧠 Logic Explanation: Broadcast is a hint, not a command. Spark's optimizer decides the actual execution plan. If it determines that a broadcast join would be inefficient (e.g., the table is too large), it will ignore the hint and use a sort-merge join instead.

25. How do you optimize slow joins in Databricks? Performance

📖 Scenario: Joining a 1TB transaction table with a small dimension is taking minutes.[reference:57]

✅ Answer: Several strategies can improve join performance:

  • Use broadcast hints for small tables.[reference:58]
  • Partition and Z-Order large tables by the join key.[reference:59]
  • Filter early before the join to reduce shuffle size.[reference:60]
  • Enable AQE for automatic skew handling and partition coalescing.
  • Use bucketing if the same join pattern repeats frequently.

🧠 Logic Explanation: Joins are expensive because they require shuffling data across the network. The goal is to minimize the amount of data shuffled. Broadcasting eliminates shuffle for the small table. Partitioning and Z-Ordering ensure that data is co-located, reducing the shuffle size. Early filtering reduces the dataset size before the expensive join operation.

26. Auto-scaling is enabled, but you're still hitting OOM (Out of Memory). Why? Performance

✅ Answer: Auto-scaling adds nodes, not memory to a single executor. OOM typically occurs because:

  • Wide transformations: Operations like groupBy, join, or orderBy can cause large shuffles that overwhelm executor memory.[reference:61]
  • Caching large DataFrames: Caching too much data in memory can cause OOM.[reference:62]
  • Poor partitioning: If data is skewed, one executor may receive more data than it can handle.[reference:63]

🔧 Solution:

  • Increase executor memory: spark.executor.memory
  • Use spark.sql.shuffle.partitions to increase partition count.
  • Use spark.memory.fraction and spark.memory.storageFraction to tune memory allocation.
  • Cache only essential DataFrames and use MEMORY_AND_DISK storage level.

🧠 Logic Explanation: Auto-scaling helps with CPU load but not memory per executor. OOM is a memory issue, not a CPU issue. The solution is to reduce the memory footprint of each task by increasing partitions (so each task processes less data) or increasing executor memory.

27. How do you monitor and debug Spark jobs in Databricks? Performance

✅ Answer: Use the following tools and techniques:

  • Spark UI: View Jobs, Stages, Tasks, Executors, and SQL tabs. Identify slow stages, data skew, and shuffle sizes.[reference:64]
  • Event Logs: Check driver and executor logs for errors and warnings.
  • Ganglia UI: Monitor cluster resource utilization (CPU, memory, network).
  • Query Execution Plans: Use df.explain() to see the physical plan and identify bottlenecks.[reference:65]
  • Dbutils: Use dbutils.notebook.exit() and dbutils.data.summarize() for debugging.

🧠 Logic Explanation: Strong Databricks engineers don't just write Spark code — they read Spark UI, understand execution plans, and design for failure.[reference:66] The Spark UI is your primary debugging tool. The Stages tab shows task duration and shuffle read/write sizes — key indicators of data skew and performance issues.

28. What is Photon in Databricks? Performance

✅ Answer: Photon is a native vectorized execution engine built in C++ that accelerates SQL and DataFrame operations. It's integrated into Databricks Runtime and can significantly improve query performance (up to 2x faster for some workloads).[reference:67]

🧠 Logic Explanation: Photon replaces parts of Spark's JVM-based execution with a C++ engine that leverages modern CPU features (SIMD, vectorized processing). It's particularly effective for:

  • Aggregations (GROUP BY, COUNT, SUM)
  • Joins (especially broadcast and sort-merge joins)
  • Filter operations

Photon is enabled by default on Photon-enabled runtimes. No code changes are required — it works transparently.

29. How do you optimize ingestion of large JSON files (5GB+) into Databricks? Performance

📖 Scenario: You receive raw 5GB JSON files daily. Processing them in Databricks is painfully slow.[reference:68]

✅ Answer: Several strategies can improve JSON ingestion performance:

  • Use Auto Loader for efficient streaming/batch ingestion.[reference:69]
  • Apply early filtering and flattening to reduce complexity.[reference:70]
  • Repartition using a column like claim_date for better parallelism.[reference:71]
  • Provide explicit schema to avoid schema inference overhead.[reference:72]

📊 Sample Code:

df = spark.readStream \
    .format("cloudFiles") \
    .option("cloudFiles.format", "json") \
    .option("cloudFiles.schemaLocation", "/mnt/schema") \
    .load("/mnt/raw/")

🧠 Logic Explanation: JSON is a text-based format that's slow to parse. Schema inference requires reading the entire file to detect schema, which is expensive. Auto Loader handles schema inference incrementally and provides checkpointing for fault tolerance.[reference:73]

30. MERGE INTO is very slow. What could be causing this? Performance

✅ Answer: Slow MERGE operations are often caused by:

  • Full table scans: The merge condition doesn't leverage partition pruning.[reference:74]
  • Poor partitioning: The target table isn't partitioned by the merge key.[reference:75]
  • Large source data: The source dataset is too large relative to the target.
  • No Z-Ordering: The merge key isn't Z-Ordered, causing inefficient data skipping.

🔧 Solution:

  • Partition the target table by the merge key (e.g., order_date).
  • Apply OPTIMIZE and ZORDER BY on the merge key.[reference:76]
  • Filter the source data before the merge to reduce the scope.[reference:77]
  • Use smaller merge batches instead of one large merge.

🧠 Logic Explanation: MERGE needs to find matching rows in the target table. If the target table isn't partitioned or Z-Ordered by the join key, it may scan the entire table for each merge. Partitioning ensures that only relevant partitions are scanned, drastically improving performance.

🟣 STREAMING & REAL-TIME (31–38)

31. What is Auto Loader in Databricks? Streaming

✅ Answer: Auto Loader is Databricks' optimized file ingestion tool for incrementally and efficiently processing new files as they arrive in cloud storage.[reference:78]

📊 Sample Code:

df = spark.readStream \
    .format("cloudFiles") \
    .option("cloudFiles.format", "json") \
    .option("cloudFiles.schemaLocation", "/mnt/schema") \
    .load("/mnt/raw/")

🧠 Logic Explanation: Auto Loader automatically discovers new files in a directory and processes them incrementally. It uses a checkpoint to track which files have been processed, making it fault-tolerant. Unlike traditional streaming, Auto Loader is optimized for file-based ingestion (not just message queues) and can handle millions of files efficiently.

32. Your streaming job is lagging behind real time. What metrics do you check first? Streaming

📖 Scenario: Your streaming job is processing data slower than it arrives, causing a growing backlog.[reference:79]

✅ Answer: Check these key metrics:

  • Processing rate vs. input rate: If processing rate < input rate, the job can't keep up.[reference:80]
  • Checkpoint size: Large checkpoints slow down recovery.[reference:81]
  • State store growth: If using stateful operations, check if the state is growing unbounded.[reference:82]
  • Trigger interval: Micro-batch interval might be too small, causing overhead.[reference:83]
  • Skewed partitions: Some partitions may be processing more data than others.[reference:84]

🔧 Solution:

  • Increase cluster resources (add workers).
  • Increase the micro-batch interval to reduce overhead.
  • Optimize state management (use mapGroupsWithState for large state).
  • Repartition the stream to distribute data evenly.

🧠 Logic Explanation: Streaming jobs are sensitive to throughput. If the input rate exceeds the processing rate, the backlog grows. The first step is to identify the bottleneck — is it CPU, memory, shuffle, or I/O? The Spark UI's Streaming tab provides these metrics.

33. How do you handle late-arriving data in streaming pipelines? Streaming

✅ Answer: Late-arriving data is handled using watermarks and event-time processing.

📊 Sample Code:

from pyspark.sql.functions import window, col

df = spark.readStream \
    .format("kafka") \
    .option("kafka.bootstrap.servers", "host:port") \
    .load() \
    .selectExpr("CAST(value AS STRING)", "timestamp") \
    .withWatermark("timestamp", "10 minutes") \
    .groupBy(window(col("timestamp"), "1 hour")) \
    .count()

🧠 Logic Explanation: Watermarks tell the streaming engine how late data can arrive. For example, a 10-minute watermark means the engine will wait up to 10 minutes for late data before finalizing results. Late-arriving data (beyond the watermark) is either dropped or handled separately using foreachBatch with MERGE for idempotent updates.[reference:85]

34. What is Delta Live Tables (DLT)? Streaming

✅ Answer: Delta Live Tables (DLT) is a declarative framework for building reliable, maintainable, and testable ETL pipelines on Databricks. It automatically handles dependency management, data quality checks, and error recovery.[reference:86]

📊 Sample DLT Code:

CREATE OR REFRESH LIVE TABLE sales_bronze
AS SELECT * FROM source_data;

CREATE OR REFRESH LIVE TABLE sales_silver
AS SELECT customer_id, SUM(amount) AS total
FROM LIVE.sales_bronze
GROUP BY customer_id;

🧠 Logic Explanation: DLT simplifies pipeline development by abstracting away the complexities of Spark streaming and batch processing. You define tables as queries, and DLT handles the execution, dependency resolution, and data quality validation. It supports both streaming and batch data sources.[reference:87]

35. How do you implement idempotent writes in Databricks streaming? Streaming

✅ Answer: Use foreachBatch with MERGE to implement idempotent writes. This ensures that even if a batch is processed multiple times (due to failures), the data remains consistent.[reference:88]

📊 Sample Code:

def write_to_delta(df, epoch_id):
    df.write.format("delta") \
      .mode("append") \
      .save("/mnt/delta/target")

streaming_df.writeStream \
    .foreachBatch(write_to_delta) \
    .option("checkpointLocation", "/mnt/checkpoint") \
    .start()

🧠 Logic Explanation: Streaming checkpoints track which data has been processed. If a job fails and restarts, it resumes from the checkpoint. However, if a batch fails after partially writing data, duplicate writes can occur. Using MERGE with a unique key ensures that each record is written only once — even if the batch is reprocessed.

36. What is the difference between Structured Streaming and Spark Streaming (DStreams)? Streaming

✅ Answer:

  • Spark Streaming (DStreams): The older API based on RDDs. It's less performant and harder to debug.
  • Structured Streaming: The newer API based on DataFrames/Datasets. It provides exactly-once semantics, event-time processing, and integration with Delta Lake.

🧠 Logic Explanation: Structured Streaming is the recommended approach for new streaming pipelines. It treats streaming data as an unbounded table, allowing you to use the same DataFrame operations as batch processing. It also provides built-in support for watermarks, state management, and fault tolerance.

37. How do you design a real-time pipeline ingesting from Kafka? Streaming

✅ Answer: A typical Kafka-to-Delta pipeline involves:

  • Ingestion: Read from Kafka using Structured Streaming.[reference:89]
  • Transformation: Parse, validate, and transform the data.
  • Write: Write to Delta Lake (Bronze layer) using foreachBatch.
  • Incremental ETL: Process Bronze to Silver/Gold using DLT or scheduled jobs.
  • Monitoring: Use Databricks Workflows with email alerts.[reference:90]

📊 Sample Code:

df = spark.readStream \
    .format("kafka") \
    .option("kafka.bootstrap.servers", "host:port") \
    .option("subscribe", "topic") \
    .load() \
    .selectExpr("CAST(value AS STRING) as json") \
    .select(from_json(col("json"), schema).alias("data")) \
    .select("data.*")

df.writeStream \
    .format("delta") \
    .option("checkpointLocation", "/mnt/checkpoint") \
    .start("/mnt/delta/bronze")

🧠 Logic Explanation: Kafka is a common source for real-time data. The pipeline should be designed for scalability (partitioning), fault tolerance (checkpoints), and exactly-once semantics (using MERGE).

38. How do you handle schema evolution in streaming pipelines? Streaming

✅ Answer: Use mergeSchema option with Auto Loader or foreachBatch to handle schema evolution gracefully.[reference:91]

📊 Sample Code:

df.writeStream \
    .foreachBatch(lambda df, epoch: df.write \
        .format("delta") \
        .option("mergeSchema", "true") \
        .mode("append") \
        .save("/mnt/delta/bronze")) \
    .option("checkpointLocation", "/mnt/checkpoint") \
    .start()

🧠 Logic Explanation: Schema evolution allows new columns to be added without breaking existing pipelines. However, it should be handled carefully — unexpected schema changes can corrupt data. It's recommended to validate schema changes in a Silver layer and only allow controlled evolution.

🟠 SECURITY & GOVERNANCE (39–44)

39. How do you secure notebooks in Databricks? Governance

✅ Answer: Several layers of security for notebooks:

  • Workspace ACLs: Control who can view, edit, or run notebooks.[reference:92]
  • Git integration: Version control notebooks in Git repositories.[reference:93]
  • Credential passthrough: Use user credentials for accessing cloud storage.[reference:94]
  • Unity Catalog RBAC: Fine-grained access control at the table/column level.[reference:95]

🧠 Logic Explanation: Security in Databricks is multi-layered. Workspace-level controls manage who can access notebooks. Unity Catalog provides data-level security (who can read/write specific tables). Credential passthrough ensures that cloud storage access uses the user's identity, not a shared service principal.

40. What is a Secret Scope in Databricks? Governance

✅ Answer: A Secret Scope is a secure container for storing sensitive information like API keys, passwords, and tokens. Secrets are provided to applications at runtime, so they are never hardcoded in notebooks.[reference:96]

📊 Sample Usage:

api_key = dbutils.secrets.get(scope="my-scope", key="api-key")

🧠 Logic Explanation: Secret scopes can be backed by Azure Key Vault, AWS Secrets Manager, or Databricks-managed storage. This ensures that credentials are stored securely and rotated centrally. Access to secrets is controlled by permissions on the scope.

41. What is data lineage in Unity Catalog? Governance

✅ Answer: Data lineage in Unity Catalog tracks the flow of data from source to destination — showing which tables were created from which sources, and what transformations were applied. It provides a visual graph of data dependencies.[reference:97]

🧠 Logic Explanation: Lineage is critical for:

  • Impact analysis: If a source table changes, which downstream tables are affected?
  • Audit: Who created this table, and what queries generated it?
  • Data quality: Trace data quality issues back to their source.

Unity Catalog automatically captures lineage for all queries run on Databricks.

42. How do you implement CI/CD with Databricks and Azure DevOps? Governance

✅ Answer: CI/CD for Databricks typically involves:

  • Git integration: Use Databricks Repos to connect to Git repositories.[reference:98]
  • YAML pipelines: Define CI/CD pipelines in Azure DevOps YAML.[reference:99]
  • Deployment tools: Use dbx (Databricks CLI) or databricks-cli for deployment.[reference:100]
  • Promotion: Promote code from dev → staging → production environments.[reference:101]

🧠 Logic Explanation: The goal of CI/CD is to automate the deployment of Databricks notebooks, jobs, and libraries. Code changes are committed to Git, which triggers a pipeline that builds, tests, and deploys the code to the appropriate environment. This reduces manual errors and speeds up development.

43. What are cluster pools in Databricks? Governance

✅ Answer: Cluster pools are a set of idle VMs that can be used to reduce cluster start time. When you create a cluster from a pool, it uses an idle VM from the pool instead of provisioning a new one.[reference:102]

🧠 Logic Explanation: Cluster start time can be a bottleneck for interactive workloads. Pools pre-provision VMs that are ready to use immediately. They are particularly useful for job clusters, where start time adds to the overall job duration. Pools also help with cost optimization by allowing you to set a minimum and maximum pool size.

44. What is the difference between Azure Data Lake Storage and Delta Lake? Governance

✅ Answer:

  • Azure Data Lake Storage (ADLS): A cloud storage service for big data analytics. It provides scalable, secure storage but doesn't include database features like transactions or schema enforcement.[reference:103]
  • Delta Lake: A storage layer built on top of ADLS (or S3/GCS) that adds ACID transactions, time travel, schema enforcement, and data skipping.[reference:104]

🧠 Logic Explanation: ADLS is the storage system (the "where" data is stored). Delta Lake is the transactional layer (the "how" data is managed). You use ADLS for scalable, low-cost storage and Delta Lake to bring reliability and performance to your data lake.

🔴 SCENARIO-BASED CHALLENGES (45–50)

45. A pipeline failed overnight while writing to a Delta table. How do you debug and recover? Scenario

📖 Scenario: A production pipeline failed during a write to a Delta table. You need to recover the data and prevent future failures.[reference:105]

✅ Answer: Debugging and recovery steps:

  • Check the error logs: Look at the job logs and Spark UI for the root cause (e.g., schema mismatch, OOM, or permission issues).
  • Use Time Travel: If the table is corrupted, restore to a previous version: RESTORE TABLE sales TO VERSION AS OF 354.[reference:106]
  • Clone the table: Create a backup before making changes: CREATE TABLE backup AS SELECT * FROM sales.[reference:107]
  • Validate the data: Run data quality checks (record counts, null checks, schema validation) to ensure the restored data is correct.[reference:108]
  • Fix the pipeline: Address the root cause (e.g., add schema evolution, increase memory, or fix permissions).

🧠 Logic Explanation: Delta Lake's time travel is your best friend in recovery scenarios. You can always roll back to a known good version. The key is to validate the restored data before re-running the pipeline.[reference:109]

46. Incremental load is producing duplicate records. How do you fix it? Scenario

📖 Scenario: Your incremental ETL pipeline is inserting duplicate records into the target Delta table.[reference:110]

✅ Answer: Duplicates typically occur due to:

  • Late-arriving data: Data that arrives after the watermark window.[reference:111]
  • Overlapping watermark windows: If the watermark is too small, data may be reprocessed.[reference:112]
  • Idempotency issues: The pipeline doesn't handle retries correctly.

🔧 Solution:

  • Use idempotent writes with MERGE on a unique key.[reference:113]
  • Set appropriate watermarks to handle late-arriving data.[reference:114]
  • Use deduplication logic in Silver layer (e.g., ROW_NUMBER() with PARTITION BY unique key).

📊 Sample MERGE for deduplication:

MERGE INTO target AS t
USING source AS s
ON t.unique_key = s.unique_key
WHEN MATCHED THEN UPDATE SET *
WHEN NOT MATCHED THEN INSERT *;

🧠 Logic Explanation: MERGE ensures that each record is inserted only once, even if the source data contains duplicates or if the job is retried. This is the standard pattern for idempotent incremental loads.[reference:115]

47. Job succeeds but downstream data is missing. What went wrong? Scenario

📖 Scenario: A Databricks job completes successfully, but the downstream system (e.g., a dashboard) shows missing or incorrect data.[reference:116]

✅ Answer: This is a silent failure — the job runs but doesn't produce the expected output. Common causes:

  • No data quality checks: The pipeline doesn't validate record counts or null percentages.[reference:117]
  • Schema drift: New columns were added but not handled.[reference:118]
  • Logic errors: The transformation logic has a bug (e.g., incorrect join condition).
  • Partition issues: Data was written to the wrong partition.

🔧 Solution:

  • Add data quality checks (record counts, null checks, schema validation) in the pipeline.[reference:119]
  • Create audit tables to track job runs and row counts.[reference:120]
  • Use expectations in Delta Live Tables for declarative data quality.

🧠 Logic Explanation: A job can succeed (exit code 0) but produce incorrect data. The only way to catch this is to validate the output. DLT expectations allow you to define data quality rules that, if violated, can fail the pipeline or quarantine the bad data.

48. Same notebook behaves differently on another runtime. Why? Scenario

📖 Scenario: A notebook runs correctly on one Databricks runtime but fails or produces different results on another.[reference:121]

✅ Answer: Differences between runtimes can be caused by:

  • Different Spark versions: Features may be deprecated or changed.[reference:122]
  • AQE defaults: Adaptive Query Execution may be enabled/disabled.[reference:123]
  • Photon engine: Photon may produce different results for some operations.[reference:124]
  • Deprecated configurations: Config parameters may be removed or changed.[reference:125]

🔧 Solution:

  • Use LTS (Long-Term Support) runtimes for production to ensure stability.
  • Test notebooks on the target runtime before deployment.
  • Explicitly set configurations (spark.conf.set(...)) to ensure consistent behavior.

🧠 Logic Explanation: Databricks releases new runtimes frequently with updated Spark versions and performance improvements. While these are generally backward-compatible, edge cases can cause differences. LTS runtimes are recommended for production stability.

49. How do you design a cost-optimized Databricks architecture for production? Scenario

📖 Scenario: Management is complaining about high Databricks costs. You need to optimize the architecture.[reference:126]

✅ Answer: Cost optimization strategies:

  • Use job clusters: Auto-terminating clusters for production jobs instead of always-on all-purpose clusters.[reference:127]
  • Right-size clusters: Use the smallest instance type that meets performance requirements. Avoid over-provisioning.[reference:128]
  • Enable auto-scaling: Scale up during peak loads and down during idle periods.
  • Use spot instances: For non-critical workloads, use spot instances to reduce costs.
  • Optimize storage: Run OPTIMIZE and VACUUM regularly to reduce storage costs.[reference:129]
  • Monitor DBU usage: Use the Databricks cost dashboard to identify expensive workloads.[reference:130]

🧠 Logic Explanation: Databricks costs are driven by compute (DBUs) and storage. Compute costs can be controlled by using ephemeral job clusters and right-sizing instances. Storage costs can be controlled by cleaning up old data and optimizing file sizes.

50. How would you design an end-to-end ETL pipeline from an on-premise database to Databricks? Scenario

📖 Scenario: You need to design a complete ETL pipeline that ingests data from an on-premise database, processes it in Databricks, and makes it available for BI and ML.[reference:131]

✅ Answer: A typical end-to-end pipeline design:

  • Ingestion: Use Change Data Capture (CDC) tools like Debezium or AWS DMS to capture changes from the on-premise database. Stream changes to Kafka or directly to cloud storage.[reference:132]
  • Landing: Ingest raw data into the Bronze layer (Delta Lake) using Auto Loader or Structured Streaming.[reference:133]
  • Transformation: Process Bronze to Silver layer using Databricks notebooks or Delta Live Tables. Apply deduplication, data cleansing, and joins.[reference:134]
  • Aggregation: Create Gold layer tables for BI and ML. Use OPTIMIZE and ZORDER for performance.[reference:135]
  • Orchestration: Use Databricks Workflows to schedule and monitor the pipeline.[reference:136]
  • Data quality: Implement data quality checks and alerting at each stage.[reference:137]

🧠 Logic Explanation: The Medallion architecture (Bronze → Silver → Gold) provides a structured approach to ETL. Each layer has a specific purpose: Bronze for raw data, Silver for cleaned data, and Gold for business-ready data. Orchestration with Databricks Workflows ensures the pipeline runs reliably and can be monitored.[reference:138]

🎉 Congratulations! You’ve now mastered 50 essential Databricks interview questions.

From fundamentals to real-world scenarios, these questions cover what hiring managers are looking for in a Databricks engineer.

📌 Pro tip: The best Databricks engineers don't just write Spark code — they read Spark UI, understand execution plans, and design for failure.[reference:139]

👍 If this guide helped you, clap and share it with fellow data engineers.

✨ Follow for more data engineering content. Happy querying! 🚀

No comments:

Post a Comment