↑ ↓ to move, Enter to open, Esc to close

    DBX-DEPData Engineer Professional

    Switch exam

    Microsoft Azure

    aws Amazon Web Services

    Google Cloud

    ServiceNow

    Databricks

    Cisco

    Salesforce

    All exams and search

    Exams / DBX-DEP / D1 Cost & Performance Optimisation

    D1.1

    Cost & Performance Optimisation (part 1)

    • 3 min read
    • 5 sections
    • 35 questions
    • Free preview
    • Exam domain: Cost & Performance Optimisation
    You are reading a free preview. The rest of the DBX-DEP course unlocks with an Exam pass or All access.See plans

    1. Lazy evaluation and honest benchmarking

    Spark is lazy: transformations only extend the logical plan; an action (write, display(), count(), manual caching) triggers execution. Databricks optimises all transformations behind one action together.

    Practice Effect
    display() after every step Forces a job each time and breaks whole-pipeline optimisation
    Re-running the same cell Hits cached data, so timings are optimistic
    Production-like timing Run the full pipeline with one final action, ideally as a job
    %sh cells Run on the driver only, never distributed
    collect() on a large result Pulls everything to the driver and can restart it

    2. Delta file layout and data skipping

    • Delta stores per-file statistics (min/max, null counts, record count); queries skip files whose range cannot match, even for non-partition columns.
    • Skipping is only effective when matching values are colocated (partitioning, Z-order, liquid clustering).
    • Statistics cover the first 32 columns by default; long strings are truncated, so free-text search gets no benefit (no term index).
    • Liquid clustering replaces partitioning and ZORDER (not compatible with them); choose keys from the columns most used in filters/joins.
    • Clustering on write works for CTAS/RTAS, INSERT and batch appends; Structured Streaming needs spark.databricks.delta.liquid.eagerClustering.streaming.enabled=true.
    • Deletion vectors speed up DELETE, UPDATE and MERGE by marking rows in metadata instead of rewriting Parquet files.

    Small-file controls: optimized writes, auto compaction, predictive optimization

    Feature When What
    Optimized writes Before the write Shuffle so fewer, larger files per partition
    Auto compaction After the write Mini OPTIMIZE (shows auto=true in history)
    OPTIMIZE Manual / predictive Compacts to larger target files (~1 GB)
    Predictive optimization Automatic OPTIMIZE, VACUUM, ANALYZE on UC managed tables only
    File-size autotune Size-based 256 MB under 2.56 TB, 1 GB above 10 TB

    3. Precompute for dashboards

    Materialized views (or a nightly-written summary table) precompute expensive aggregations and joins so many interactive users read stored results. A plain view recomputes at each query; streaming is for continuous ingestion.

    4. Structured Streaming cost and latency

    Choosing a trigger

    • No trigger = processingTime with a 0 interval: checks every few milliseconds, causing storage API costs.
    • For incremental batch use Trigger.AvailableNow (Trigger.Once is deprecated); a Delta source is read incrementally via checkpoint offsets.
    • Large micro-batches cause spill; limit input rate to avoid it.

    5. Spark UI diagnostics

    Need Where
    Spill Stage detail page (spill statistics) and query detail
    Skew Stage Summary Metrics: max task duration far above the 75th percentile; fix with AQE, salting, pre-aggregation
    Predicate pushdown Physical plan (EXPLAIN)
    Total elapsed query time Query Profile wall-clock duration (not aggregated task time)

    Spill fixes: more memory per core, smaller input partitions (spark.sql.files.maxPartitionBytes). Broadcast joins use the broadcast(df) hint on a DataFrame. Compute-level Spark conf applies to every notebook; notebook conf is session-scoped.

    Exam traps

    • Auto compaction is after the write; optimized writes are a shuffle before it.
    • Predictive optimization never runs on external tables.
    • ZORDER and liquid clustering cannot be combined.
    • Query Profile: wall-clock duration, not aggregated task time.
    • The two "Storage tab, MEMORY_ONLY" items conflict (B vs C); the exam answer is usually "Size on Disk > 0".
    • Spill indicators are Spark UI pages (Stage, Query), not log files.
    • Auto-compaction 128 MB and merge-based autotuning are legacy facts that current docs no longer state.

    Docs

    The rest of this chapter is part of the DBX-DEP premium course

    Unlock every chapter, all 339 questions and spaced review with All access or a 90-day exam pass. Every Fundamentals exam stays free, and the first chapter of every exam is open.

    Chapters