Lakehouse governance and quality
A lakehouse is more than a folder of files
A lakehouse combines lake storage with table-management features useful for analytics: consistent snapshots, schema evolution, commits and metadata-driven planning. Apache Iceberg, Delta Lake and Apache Hudi are open table technologies with different protocols and engine compatibility. An ordinary directory of Parquet files does not by itself provide atomic multi-file publication, concurrent writer coordination or snapshot history. An engine needs compatible table-format implementation and catalog/commit support. Do not mix direct object writes with managed table writes unless the format explicitly supports that workflow.
Consider a job replacing yesterday's orders. If it deletes old files then uploads new files, readers may observe missing or partial results. A supported table commit can instead publish metadata pointing to a complete new snapshot. Readers using the old snapshot can continue while new readers select the new one, subject to engine isolation and retention behavior. Failed commits may leave orphan files; clean them using the appropriate maintenance operation and safe age thresholds. Concurrent modifications may conflict and need retry with a fresh snapshot.
Schema evolution and governance
A schema is a contract for column names, data types, nullability and business meaning. Adding an optional channel column can be compatible if existing records use an explicit default such as unknown. Changing integer cents to a string or redefining cents as dollars without a versioned migration is breaking. For renamed or removed columns, check field identity and readers; schema evolution support differs by format and engine. Test old and new producers, consumers and backfills before upgrading. Iceberg tracks schema and partition evolution in metadata; existing files need not always be rewritten for compatible changes. Verify exact supported operations in the reader/writer versions.
Data quality dimensions include completeness (required fields), validity (domain and type), uniqueness (event ID), consistency (totals reconcile), freshness (arrival delay), and accuracy (comparison with an authoritative source). A valid schema cannot prove that a purchase happened. Record counts, rejected counts, duplicate counts, source checksums, job version, event date range and output snapshot as lineage. Reconcile source counts against accepted + duplicate + rejected rows. Define thresholds and owners; quarantine invalid records with restricted access. Never silently discard mismatched IDs or treat all duplicate IDs as identical.
Run a local quality gate
The following Python 3 standard-library example uses four fictional orders, no external packages, files, services or credentials. Dates use canonical YYYY-MM-DD and amounts are integer cents to avoid floating-point currency rounding. The earlier order is deliberately late. A repeated identical ID counts as a duplicate; a changed payload with the same ID is a conflict. The model accepts the first valid event only for inspection, but blocks publication if any rejection occurs. It is not a table-format engine or a production deduplication store.
from datetime import date
def clean(rows): accepted = {} rejected = [] duplicates = 0 for row in rows: if not isinstance(row, dict): rejected.append("schema") continue key = row.get("id") day = row.get("day") cents = row.get("cents") if not isinstance(key, str) or not key or type(cents) is not int or cents < 0: rejected.append("schema") continue try: if not isinstance(day, str) or date.fromisoformat(day).isoformat() != day: raise ValueError("canonical date required") except ValueError: rejected.append("date") continue # Optional channel in schema v2; absence maps to unknown. channel = row.get("channel", "unknown") if channel not in ("web", "store", "unknown"): rejected.append("schema") continue record = (day, cents, channel) if key in accepted: if accepted[key] == record: duplicates += 1 else: rejected.append("conflict") continue accepted[key] = record totals = {} for day, cents, _ in accepted.values(): totals[day] = totals.get(day, 0) + cents return {"accepted": len(accepted), "duplicates": duplicates, "rejected": rejected, "totals": dict(sorted(totals.items()))}
def publishable(result, expected_count): # Strict illustrative policy: no invalid or conflicting events. return (expected_count > 0 and not result["rejected"] and result["accepted"] + result["duplicates"] == expected_count)
rows = [ {"id": "a", "day": "2026-01-03", "cents": 1200}, {"id": "a", "day": "2026-01-03", "cents": 1200}, {"id": "b", "day": "2026-01-02", "cents": 800, "channel": "web"}, {"id": "c", "day": "2026-01-03", "cents": -5},]result = clean(rows)print(result)print("publish:", publishable(result, len(rows)))Expected output:
{'accepted': 2, 'duplicates': 1, 'rejected': ['schema'], 'totals': {'2026-01-02': 800, '2026-01-03': 1200}}publish: FalseTwo unique orders total 2000 cents; one duplicate and one invalid record reconcile to four inputs. Remove the invalid order and rerun: the count becomes three, two accepted plus one duplicate, and the gate passes. It still needs an atomic target commit. Across independent batches a durable unique-key ledger or transactional merge is required; this function deduplicates within one call only. To simulate a conflict, change the second a to 1300 cents; the gate rejects publication. The example uses a strict zero-rejection policy for teaching; real thresholds need explicit business approval and monitoring.
Access boundaries and retention
Separate raw, quarantine, curated and aggregate data into controlled namespaces. The ingest role writes raw data; the transform role reads raw and writes curated output; analysts query approved tables or views, not arbitrary objects. Audit both catalog/table actions and direct object access. Test a denied raw-object read as well as an allowed aggregate read; a SQL filter is ineffective if the caller can directly retrieve unrestricted objects. Classify data, use encryption and least privilege, track owners and access reviews. Avoid logging sensitive row values. Lake Formation permissions and underlying S3/IAM controls, and OneLake item/workspace/data permissions, need service-specific configuration and testing.
An illustrative policy retains raw files 30 days, curated tables 90 days and aggregates 365 days if approved. Snapshot history, backups, replicas and quarantine need independent retention rules. Deleting a visible row is not proof of physical erasure: old snapshots or copies may still reference its file. Coordinate snapshot expiration, orphan cleanup and object lifecycle with reader windows, legal holds and documented deletion obligations. Do not expire a file while a retained snapshot references it. A 7-day replay objective requires source availability for at least that window plus safety margin; a 3-day raw policy cannot satisfy it. Test restored data and schema compatibility. No real retention policy or legal determination is made here.
Technology selection and operational checks
Use Apache Iceberg evolution, Iceberg specification, Apache Parquet overview, Fabric Delta overview, Lake Formation permissions, and OneLake security overview as starting points. Open formats do not imply free managed compute or universal compatibility. Confirm the software license for the selected artifact/version and service terms, catalog compatibility, read/write/delete support, data location and retention. No exact license or regional SKU is asserted for an unverified version. Spark, Beam and SQL engines address different processing models; choose based on measured needs, not a brand label.
Before releasing a dataset, verify input identity, schema, accepted/rejected counts, total reconciliation, snapshot commit, reader access, reproducible job version, rollback/replay plan and retention. Monitor freshness and costs, including continuous workers, reprocessing, scan bytes and file maintenance. If the job fails, keep the old published snapshot and report missing freshness rather than serving an unmarked incomplete output. Next chapter explores warehouses and streaming query semantics.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Lakehouse governance and quality — knowledge check
Choose the best answer for each offline scenario.
What does a table format add beyond Parquet files?
Which schema change is potentially compatible?
What should a strict gate do when the same ID has a different amount?
Why test direct object access as well as SQL access?
Why coordinate snapshot expiry with file deletion?