$ governance --as-code

Data Governance

Data governance is the set of roles, rules and processes that make sure data is trusted, findable, secure and used legally. In practice it answers questions like: who owns this table, what does “active customer” mean, who may see email addresses, where did this number come from, and what breaks if I change this column? For data engineers, good governance is less about committees and more about automation built into pipelines: tests, metadata, lineage and access policies that run on every change.

The pillars

Ownership

Every dataset has an owner

Data owners decide what data means and who may use it. Stewards keep definitions and quality in shape day to day.

Quality

Measured, not assumed

Freshness, completeness, uniqueness, validity and consistency, checked by tests on every run.

Metadata and lineage

Findable and traceable

A catalog describes each dataset; lineage shows where it came from and what depends on it.

Security and privacy

Least privilege by default

Classification of sensitive data, role- or attribute-based access, masking, retention and deletion.

Lineage in action: impact analysis

Lineage is the map of how data flows between tables, jobs and dashboards. Column-level lineage, collected automatically from SQL and job runs (for example via OpenLineage), turns “what breaks if I change this?” into a lookup.

$ lineage impact orders_db.orders.amount
Catch a breaking change before it ships
orders_db.ordersstg_ordersfct_orders Revenue dashboardChurn modelFinance export source · Postgresdbt modeldbt model BIML feature jobnightly CSV to ERP PR #812 · schema change amount → total_amount not affected CI · contract check failed · 4 downstream assets break · owners notified
  1. The catalog has collected lineage: a source table feeds two dbt models, which feed a dashboard, a model and an export.
  2. A backend engineer opens a PR that renames the source column amount.
  3. Column-level lineage walks downstream: four assets read amount. The churn model only uses other columns, so it is not affected.
  4. A data contract check in CI blocks the merge and notifies the owners. The fix is planned instead of discovered on Monday morning.

Data quality

Quality is defined as testable rules close to the data (completeness, uniqueness, validity, accuracy, consistency, freshness) that run in the pipeline and stop bad data from reaching consumers instead of just sending an email. See Data Quality for the dimensions animated, where to place checks and the tools.

Data contracts

A data contract is an agreement between a data producer and its consumers, written as code: schema, meaning of fields, quality rules, freshness SLO, and how breaking changes are handled. Contracts are checked in CI (like the figure above) and at runtime. They are the practical tool behind “data as a product” in data mesh.

Catalog and metadata

A data catalog is the search engine for your data: descriptions, owners, schemas, tags, popularity, lineage and a business glossary of agreed definitions. Open-source options include DataHub, OpenMetadata and Unity Catalog; commercial ones include Atlan, Collibra and Alation. The catalog is only useful if metadata is collected automatically from warehouses, dbt, orchestrators and BI tools.

Security and privacy

  • Classify data (public, internal, confidential, PII) and tag columns, ideally with automatic detection.
  • Access control: role-based (RBAC) or attribute-based (ABAC, for example “analysts in the EU see EU rows only”), using row filters and column masking in the warehouse or catalog.
  • Least privilege and auditing: no shared superuser accounts; log who queried what.
  • Encryption in transit and at rest.
  • Retention and deletion: keep personal data only as long as needed and be able to delete one person’s data everywhere. See Retention.
  • Regulations: GDPR (EU), CCPA/CPRA (California), HIPAA (US health), and the EU AI Act for data used to train and run AI systems.

Retention

A retention policy says how long each kind of data is kept and what happens after: delete, anonymize, or move to cheaper storage. Laws set the limits in both directions (GDPR says personal data only as long as needed; finance and tax rules often require several years), and storage cost does the rest. Write the policy per dataset in the catalog, then enforce it with the tools that already hold the data:

Where data lives How retention is enforced
Kafka topics retention.ms / retention.bytes per topic, or compaction to keep the latest value per key
Object storage Lifecycle rules: move to an archive tier after 90 days, delete after N years
Partitioned tables Drop partitions older than the limit (DROP PARTITION, partition expiration in BigQuery)
Iceberg / Delta tables Deleting rows is not enough: expire old snapshots (expire_snapshots, VACUUM) so deleted data is really gone
Backups and logs Their own retention, and included in deletion requests

Common mistakes

  • Governance as a document no one reads, instead of checks that run in CI and pipelines.
  • A catalog filled once by hand, then out of date in a month.
  • “Owner: data team” on every table. Owners must be the people who can answer questions about meaning.
  • Granting broad access because fine-grained policies feel slow, then finding PII in a public dashboard.
  • Deleting rows for a GDPR request but leaving them in table snapshots, raw files and backups.

Learning Resources

Books

Docs and tools

Videos