Data Engineering for AnalyticsVol. 21 · Analytics
0 / 0

Shelves / Data Engineering for Analytics

DE·09

Governance, Privacy and Cost

Running an analytics platform people can trust and afford: who may see what (roles, row-level security, column masking, catalog policies), classifying and protecting personal data (pseudonymisation versus anonymisation, purpose limitation, retention and deletion that actually removes data from a lakehouse), auditing access, ownership and discovery, and the economics of storage, compute and bytes scanned, with pruning, materialisation choices, cost attribution and budgets; with a lab that cuts bytes scanned to 2% with partitioning and column selection, builds a masked view for kitchen staff, and reverses an unsalted hashed customer ID in 40 milliseconds.

16 topics · ~8 min read · 16-question quiz
Updated Suggest a correction

Start here: the platform holds everyone's data

An analytics platform gathers the most sensitive combination of data in the company: every order, every customer's address and habits, payments, riders' locations, support conversations. It also tends to grow costs quietly: each new dashboard scans terabytes, each team copies tables "just to be safe". Governance is how you keep it lawful, safe and affordable without making it useless.

Three questions organise this chapter:

Question Practices
who may see what? roles, row-level security, column masking, catalog policies, audits
is personal data handled lawfully? classification, minimisation, pseudonymisation, purpose limits, retention, deletion
what does it cost, and who pays? storage vs compute, bytes scanned, pruning, materialisation, attribution, budgets

Measured

Query on 5 M orders (one year) Bytes read
all columns, all data 33.7 MB (100%)
all columns, one month, table not partitioned 33.7 MB (100%)
all columns, one month, partitioned by month 4.4 MB (13%)
3 columns, one month, partitioned 0.67 MB (2%)

On a warehouse that bills by bytes scanned, those four queries differ in cost by 50×. And a "pseudonymous" customer reference made by hashing the customer ID with MD5 was reversed in 40 ms by hashing all 100,000 possible IDs: hashing a small ID space hides nothing.

How deep to go

Volume 17 defines six mastery levels. For governance, privacy and cost:

Level What you can do
L1 Explain access control, personal-data handling and warehouse cost drivers
L2 Configure roles, masked views and partitioned tables
L3 Explain pseudonymisation vs anonymisation, deletion in lakehouses, billing models
L4 Find over-broad access, leaked personal data and expensive queries, and fix them
L5 Design governance and cost controls for a data platform
L6 Run them: audits, regulatory requests, budgets, chargeback across teams

Access control

  • Roles mapped to groups from your identity provider (analyst, finance, kitchen-ops, data-engineer), never to individuals; least privilege by default; production write access only for pipelines.
  • Row-level security: policies that filter rows by user attributes (kitchen_id IN (kitchens of the user)), implemented as row access policies in the warehouse or secure views (the lab).
  • Column masking: dynamic masking policies or views that hide or transform sensitive columns (phone, address, free-text notes) for roles that don't need them.
  • Catalog-level policies (Unity Catalog, AWS Lake Formation, Iceberg REST catalogs with access control) apply the same rules across engines reading the same tables.
  • Audit: log who queried what (warehouse query history, catalog audit logs), retain it, and review access to sensitive tables.

Personal data

Analytics needs less personal data than people assume. In order of preference:

  1. Don't collect or copy it (minimisation): most analysis needs a stable customer key, area and segment, not names, phones or addresses.
  2. Pseudonymise at ingestion: replace identifiers with a keyed HMAC (secret key held outside the platform) or a token from a vault; keep the mapping restricted. The lab shows why an unkeyed hash fails.
  3. Restrict the rest with masking and row-level security, and tag sensitive columns in the catalog so policies follow them.
  4. Aggregate for broad sharing (counts with minimum group sizes, no rows for groups smaller than, say, 10).

Remember the legal frame: privacy laws such as India's Digital Personal Data Protection Act, 2023, and the EU's GDPR require a lawful basis or consent, purpose limitation, security safeguards, retention limits, and honouring rights such as correction and erasure. Pseudonymised data is still personal data under them. Ask your legal team; design so their answers are implementable.

Retention and deletion

  • Write a retention policy per dataset (raw events 90 days, pseudonymised facts 7 years, location trails 30 days) and implement it as scheduled jobs.
  • Erasure requests must reach every copy: raw, staging, marts, extracts, ML features, caches, and lakehouse history. In Iceberg or Delta: delete rows, then compact (so rewritten files no longer contain them), then expire snapshots older than the deletion and remove orphan files. Until then, time travel still returns the data.
  • Prefer designs where personal attributes live in few tables keyed by the pseudonym, so erasure touches a handful of places.

Ownership and discovery

  • Every dataset has an owner (a team), a description, a sensitivity tag, freshness expectations and contacts, in a data catalog (DataHub, OpenMetadata, Unity Catalog, the warehouse's own).
  • Certified datasets (tested, documented, owned) are what dashboards should use; everything else is clearly "experimental".
  • Lineage from chapter 08 links datasets to the jobs and dashboards that use them.

Cost

Warehouses bill in two main ways:

Model You pay for Levers
bytes scanned (on-demand) data read by each query partitioning, clustering, column selection, avoiding SELECT *, preview tools instead of full scans
compute time (warehouses, slots, clusters) the time clusters run right-sizing, auto-suspend, separating workloads, scheduling heavy jobs off-peak, query efficiency
storage data kept (including history and copies) retention, snapshot expiry, compression, avoiding duplicate copies

Practices:

  • Prune (the lab: 50× fewer bytes with partitioning and three columns instead of all).
  • Materialise expensive, frequently read results (dbt tables or incremental models) instead of recomputing them in every dashboard query; but don't materialise what's rarely read.
  • Separate compute for pipelines, BI and ad-hoc work so one can't starve the others, and each can be sized and suspended independently.
  • Attribute costs with tags or labels per team, pipeline and dashboard; publish a monthly cost report; set budgets and alerts on spend and on single expensive queries.
  • Review the top 10 most expensive queries every month: one fix there often saves more than any platform change.

Common traps

  • Everyone is an admin "for now".
  • Hashing identifiers and calling it anonymisation.
  • Deletion that forgets history, backups or derived copies.
  • SELECT * dashboards on unpartitioned tables.
  • Nobody sees the bill until finance asks.

Lab: bytes scanned, masked views and a reversible pseudonym

Setup. DuckDB and PyArrow on the lab machine; chapter 01's 5 million orders (one year), as one unpartitioned zstd Parquet file and as a copy partitioned by month (12 files). Bytes read are computed from Parquet metadata: the compressed size of the column chunks a query needs in the files it can't skip, the quantity on-demand warehouses bill for.

Experiment 1: what a query reads

Query Files Bytes read Share of table
SELECT *, all data 1 33.69 MB 100.0%
SELECT * WHERE month = '2026-10', unpartitioned (data not sorted by time) 1 33.69 MB 100.0%
SELECT * WHERE month = '2026-10', partitioned by month 1 of 12 4.43 MB 13.2%
SELECT kitchen_id, amount_paise, status WHERE month = '2026-10', partitioned 1 of 12 0.67 MB 2.0%

October held 424,641 rows (8.5% of rows), but its file was 13% of the bytes: split files compressed less well than the single file of regularly generated data.

Experiment 2: a masked, row-filtered view for kitchen staff

A view joining a staff_kitchens(role, kitchen_id) mapping, filtered by the session's role, exposing customer_ref instead of customer_id and dropping the free-text note:

Querying as kitchen_12_staff Result
rows visible 25,000 (kitchens 12 and 13 only)
distinct kitchens 2
customer reference e.g. cust_00063cb5 (first 8 hex characters of MD5 of the customer ID)

Experiment 3: reversing the "pseudonym"

Hashing every possible customer ID (1 to 100,000) with MD5 and comparing with 00063cb5 found customer 83110 in 40 ms.

What it shows

  • Partitioning plus column selection cut the bytes read 50×; filtering on an unpartitioned, unsorted table cut nothing. On bytes-billed warehouses, layout is cost.
  • Views can implement row-level security and masking in any engine; warehouses' native row access and masking policies do the same with less room for mistakes and apply to every query path.
  • An unkeyed hash of a small ID space is not a pseudonym, it's an obfuscated ID. Use an HMAC with a secret key held outside the analytics platform (or a tokenisation service), rotate keys with care, and still treat the result as personal data.

Try it yourself

  1. Replace MD5 with HMAC-SHA256 using a secret key and confirm the brute force no longer works without the key.
  2. Sort the unpartitioned file by placed_at and recompute Experiment 1's second row using row-group statistics.
  3. Implement the kitchen-staff rule as a PostgreSQL row-level security policy and compare with the view.
  4. Delete one customer's rows from chapter 07's Iceberg table, then find them again with time travel; then expire snapshots and confirm they're gone.

Revision sheet: governance, privacy and cost

Key ideas

  • Roles from identity groups; least privilege; row-level security; column masking; catalog policies across engines; audited access.
  • Personal data: minimise, pseudonymise with keyed HMAC or tokens, restrict, aggregate; pseudonymised is still personal.
  • Retention per dataset; erasure across every copy, including lakehouse history (delete, compact, expire snapshots).
  • Owners, descriptions, sensitivity tags and certification in a catalog.
  • Cost: bytes scanned, compute time, storage; prune, materialise wisely, separate compute, attribute, budget, review top queries.

Numbers to remember

  • Lab: bytes read 100% → 13% (partitioned month) → 2% (+3 columns); MD5 pseudonym reversed in 40 ms.

Glossary

  • Row-level security: per-user row filtering.
  • Dynamic masking: role-dependent transformation of column values.
  • Pseudonymisation: replacing identifiers with keyed or tokenised references.
  • Anonymisation: making re-identification impossible (rarely achieved).
  • Chargeback / showback: assigning or showing platform costs to teams.