Key points
Scalable data modelling on Delta Lake starts at the protocol layer, not at the DDL layer.
Every Delta table publishes a _delta_log directory of JSON commits and Parquet checkpoints, and each commit references a protocol action carrying a minReaderVersion and minWriterVersion plus the optional readerFeatures and writerFeatures arrays.
Modelling choices like deletion vectors, column mapping, Liquid Clustering, identity columns, type widening, and timestamp-without-timezone all sit behind a writer feature.
Choosing a model means choosing which features the table opts into, because every feature both unlocks a capability and raises the bar for the readers that can open the table.
- Old Spark clients that have not learned a writer feature will refuse to write.
- Old readers that have not learned a reader feature will refuse to read.
The exam treats the protocol as a first-class modelling concern, not as plumbing.
The second pillar is schema. Delta enforces schema-on-write by default:
- a
df.write.format("delta")call that introduces a new column fails unless the writer passesmergeSchema = true. - a call that renames a column fails outright unless column mapping is enabled through
delta.columnMapping.mode = 'name'.
Column mapping decouples the logical column name from the physical Parquet field id, which lets you rename or drop columns without rewriting data files, but it also raises minReaderVersion to 2 and minWriterVersion to 5, so downstream consumers that pin an older reader will break.
A scalable model picks column mapping at table create time for any table whose schema will evolve through subject-area refactoring; it leaves column mapping off for tables that only ever append.
Identity columns and generated columns are the third pillar. An identity column issues a monotonically increasing surrogate key through GENERATED ALWAYS AS IDENTITY (or GENERATED BY DEFAULT AS IDENTITY for backfill-friendly tables), and the engine guarantees uniqueness but not contiguity, so gaps are normal under concurrent writers.
A generated column derives its value from a deterministic expression over other columns in the same row: a typical Gold-layer fact table generates a order_date column from CAST(order_ts AS DATE) so downstream queries filtering on order_date benefit from data-skipping statistics on the generated column even when the source carries only the timestamp. Both identity and generated columns are stored physically; they are not virtual at query time.
Identity columns also block manual inserts into the identity column unless the writer specifies OVERRIDE SYSTEM VALUE, which is the canonical way to backfill from a legacy primary-key space without losing referential meaning.
The fourth pillar is constraints. Delta supports two kinds: NOT NULL constraints on individual columns through column definitions, and CHECK constraints applied through ALTER TABLE ADD CONSTRAINT.
A CHECK constraint runs against every incoming row at write time and rejects the entire batch if any row fails. Constraints are part of the table's metadata, not enforced through expectations like the SDP @dlt.expect_or_fail decorator from earlier chapters, so they apply equally to writers that bypass the pipeline (an ad-hoc INSERT from a notebook, a MERGE from a one-off backfill job, a COPY INTO).
The exam tests the distinction: SDP expectations are pipeline-only and can drop or quarantine; CHECK constraints are table-level and always fail the write.
Choosing the right physical layout for a large table
Three physical layouts are available on Delta tables: partitioning (legacy), Z-ORDER on top of partitioning or unpartitioned tables (legacy), and Liquid Clustering (default for new tables). A scalable model on Unity Catalog managed tables defaults to Liquid Clustering, picks up to four clustering columns from the join and predicate surface of the downstream workload, and lets predictive optimization run OPTIMIZE and VACUUM on the table's behalf.
The choice of clustering columns matters more than the choice of layout primitive: clustering on a column that is never filtered or joined buys nothing, while clustering on the highest-selectivity predicate column shrinks the file-scan surface dramatically.
CREATE TABLE prod_gold.sales.fact_orders (
order_sk BIGINT GENERATED ALWAYS AS IDENTITY,
order_id STRING NOT NULL,
customer_sk BIGINT NOT NULL,
product_sk BIGINT NOT NULL,
store_sk BIGINT NOT NULL,
order_ts TIMESTAMP NOT NULL,
order_date DATE GENERATED ALWAYS AS (CAST(order_ts AS DATE)),
quantity INT NOT NULL,
unit_price DECIMAL(18, 4) NOT NULL,
net_amount DECIMAL(18, 4) GENERATED ALWAYS AS (quantity * unit_price),
currency STRING NOT NULL,
_ingest_ts TIMESTAMP NOT NULL,
CONSTRAINT chk_quantity_pos CHECK (quantity > 0),
CONSTRAINT chk_currency_iso CHECK (LENGTH(currency) = 3)
)
USING DELTA
CLUSTER BY (order_date, customer_sk, store_sk)
TBLPROPERTIES (
'delta.enableDeletionVectors' = 'true',
'delta.enableChangeDataFeed' = 'true',
'delta.columnMapping.mode' = 'name',
'delta.feature.allowColumnDefaults' = 'supported',
'pii_level' = 'tier1',
'data_classification' = 'confidential',
'grain' = 'one_row_per_order_line',
'owner_email' = 'gold-sales@example.com'
);
This DDL collects every modelling decision in one place:
- The surrogate-key column
order_skis generated by the engine. - The join keys
customer_sk,product_sk,store_skare typedBIGINTand markedNOT NULLto keep join planners on the broadcast-friendly path. - The derived columns
order_dateandnet_amountmove out of the ETL code and into the table definition. - The two CHECK constraints catch bad rows regardless of who writes them.
- The table opts into deletion vectors and Change Data Feed so DML and downstream reads stay efficient.
- The column mapping mode unlocks rename and drop.
- The property bag captures the grain and classification metadata referenced from previous chapters.
Schema evolution paths and their costs
How it works
Schema evolution divides into three classes by physical cost.
- Adding a nullable column at the end of the schema is free: it costs one commit, no data files are rewritten, and reads that do not reference the new column are unaffected.
- Adding a column with a default value (under
delta.feature.allowColumnDefaults = 'supported') is also free for new rows, while historical reads return the default through the metadata layer. - Renaming or dropping a column requires column mapping to be enabled, and both operations cost one commit and zero data rewrites because they only update the column-id-to-name map.
- Widening a column type (for example, INT to BIGINT, DATE to TIMESTAMP) requires the
typeWideningwriter feature and rewrites only when the underlying Parquet representation changes; narrowing a type is not supported and forces a full table copy.
The exam tests both the rename path (column mapping required, otherwise the rename is rejected) and the widening path (the writer feature must be enabled at table create or through ALTER TABLE SET TBLPROPERTIES).
-- Add a nullable column: free, no rewrite.
ALTER TABLE prod_gold.sales.fact_orders
ADD COLUMN promo_code STRING COMMENT 'Promo code applied at checkout';
-- Add a column with a default: free for future rows, default surfaced via metadata for past rows.
ALTER TABLE prod_gold.sales.fact_orders
ADD COLUMN fulfilment_channel STRING DEFAULT 'store';
-- Rename a column: requires column mapping (already enabled at create above).
ALTER TABLE prod_gold.sales.fact_orders
RENAME COLUMN promo_code TO promotion_code;
-- Widen a numeric type without rewriting all files.
ALTER TABLE prod_gold.sales.fact_orders
SET TBLPROPERTIES ('delta.enableTypeWidening' = 'true');
ALTER TABLE prod_gold.sales.fact_orders
ALTER COLUMN quantity TYPE BIGINT;
Type widening is reader-protocol-gated: a reader that has not learned the typeWidening reader feature will refuse to open the table at the version where the type changed.
In practice
The safe order is to:
- upgrade every reader workspace and BI tool to a Databricks Runtime release that lists the feature as supported,
- run a small validation script against a fixture table,
- and only then enable the property on the production table.
💡 Exam Trap: Column mapping is the only way to rename or drop a Delta column without rewriting the data. Candidates often pick "rebuild the table" as the answer when the correct answer is "enable column mapping at create time, then
ALTER TABLE … RENAME COLUMN." The trap is that column mapping must be set at create time (or before any rename is attempted) and raises the reader protocol, so a model that anticipates rename activity opts in upfront rather than retrofitting.
💡 Exam Trap: A
CHECKconstraint and an SDP@dlt.expect_or_faildecorator look interchangeable but behave very differently. The CHECK constraint applies to every writer (notebooks, ad-hoc backfills,COPY INTO,MERGE); the expectation applies only inside the pipeline that defines it. The exam phrases the trap as "an analyst inserts a row with a negative quantity through a notebook" and asks which mechanism rejects the insert. Answer: the CHECK constraint. The expectation never fires because the notebook is not running the pipeline.
⚠️ Anti-Pattern: Defining surrogate keys with
GENERATED BY DEFAULT AS IDENTITYand then manually inserting integer values from upstream legacy systems. The engine guarantees uniqueness only across system-generated values; user-inserted values can collide with future system values because the sequence does not know about them. The clean pattern isGENERATED ALWAYS AS IDENTITYfor new tables and a one-time backfill MERGE that sets the identity column throughOVERRIDE SYSTEM VALUEfor migrations.
Modelling for the medallion roles
Each medallion role applies the protocol primitives differently.
The Bronze layer favours minimal modelling:
- append-only,
- schema-evolution-friendly,
- no constraints beyond
NOT NULLon the partition or natural key, deletion vectors disabled because Bronze never updates, Change Data Feed disabled because Bronze never serves change subscribers.
The Silver layer adds:
- CHECK constraints for the validated record contract,
- enables deletion vectors so SCD Type 1 corrections and GDPR-driven deletes do not rewrite Parquet files,
- runs Liquid Clustering on the natural business key plus the event date.
The Gold layer hardens the contract further:
- identity surrogate keys,
- generated columns for derived measures and date partitions,
- CHECK constraints on every business-rule invariant,
- Change Data Feed on for downstream SDP materialised views,
- Liquid Clustering on the columns the BI workload filters and joins on.
The grain of a table is also a modelling decision and should be captured explicitly. A fact table's grain is the business event it represents at one-row-per-something resolution:
- one row per order line,
- one row per shipment hop,
- one row per page view.
The grain dictates the surrogate-key cardinality, the foreign-key set on the row, and the additive behaviour of every measure column. The convention in the K-base is to capture the grain in a TBLPROPERTIES entry with the key grain, which makes the contract discoverable through Catalog Explorer and queryable through system.information_schema.table_properties.
ALTER TABLE prod_gold.sales.fact_orders
SET TBLPROPERTIES (
'grain' = 'one_row_per_order_line',
'fact_type' = 'transaction',
'additive_measures' = 'quantity,net_amount',
'sla_p95_minutes' = '15'
);
The additive_measures property documents which measure columns are safely summed across any dimensional slice; the sla_p95_minutes property pairs with the SQL alert on freshness lag defined in earlier chapters. Discoverability and observability are part of the model, not afterthoughts.
Concurrency and isolation in scalable models
Delta uses optimistic concurrency control: a writer reads the latest table version, performs its operation against that snapshot, and attempts to commit a new version.
If a conflicting writer committed in the meantime, the second commit fails and the writer retries (the Spark engine retries automatically up to a configurable limit). The conflict surface depends on the operation.
- Two appends to disjoint regions of the file space never conflict.
- Two MERGEs that touch the same files do conflict.
- Liquid Clustering reduces conflict surface compared to partitioning because file boundaries shift over time and the engine can pack adjacent files differently, while partitioning pins file boundaries to the partition directory, so two MERGEs targeting the same partition almost always serialize.
Row-level concurrency (the writer feature rowLevelConcurrency, available on managed tables) extends this further: two concurrent MERGE or UPDATE statements that touch disjoint rows of the same file can both commit without retry, because the engine reasons about per-row tombstones through deletion vectors.
The exam may ask which Delta feature lets two concurrent UPDATEs against the same partition both succeed without one retrying; the answer is row-level concurrency on a table that has deletion vectors enabled and Liquid Clustering rather than partitioning.
📊 Limit: Liquid Clustering supports up to four clustering columns per table. Specifying more than four in a
CLUSTER BYorALTER TABLE CLUSTER BYstatement returns an error. The limit is enforced by the engine; do not assume it lifts in newer runtimes without checking the release notes.
📊 Limit: Per-file statistics for data skipping are collected on the first 32 columns of the table by default (
delta.dataSkippingNumIndexedCols). Raising the value collects more statistics but lengthens the commit metadata; lowering it (for example, to 4) on very wide tables reduces commit overhead at the cost of skipping breadth. Generated columns count toward the 32-column window.
🎯 Scenario: A telecom Gold fact table grows to 80 TB of network-event records. The BI team filters almost exclusively by
event_dateandregion_code, and a smaller analytics team joins onsubscriber_sk. The model chooses Liquid Clustering onevent_date,region_code,subscriber_sk(three keys, under the four-key limit), enables deletion vectors so subscriber-rights deletions do not rewrite the entire file, enables CDF so the downstream churn-prediction pipeline reads only the changed rows, and adds a CHECK constraint to reject rows withevent_ts > CURRENT_TIMESTAMP(). After one week of predictive optimization runs, files settle near the 256 MiB target and average query latency drops by a factor of four versus the prior partitioned design.
Decision Anchor: which modelling primitives to opt into
When to use
Choose the full Gold stack (CLUSTER BY with up to four columns, delta.enableDeletionVectors = true, delta.enableChangeDataFeed = true, delta.columnMapping.mode = 'name', identity surrogate keys, generated columns for derived measures, CHECK constraints for business rules) when the table is consumer-facing and will see updates, deletes, schema evolution, and downstream change subscribers.
Choose the lean Bronze stack (append-only writer, no deletion vectors, no CDF, no column mapping, no identity columns, optional Liquid Clustering on the ingest timestamp) when the table is raw and immutable and the only operation is append.
Choose the Silver hybrid (Liquid Clustering on the natural key plus event date, deletion vectors on for GDPR, column mapping on for refactoring, CDF off until a subscriber needs it) when the table is the cleaned, conformed surface that downstream Gold pipelines consume. ---
