Environment Management

Concepts covered: Environment Management

Each environment exists to catch 1 class of failure, and only the failures its data can produce will show up there. A fixture of 12 hand-written rows catches a wrong join condition in seconds and can never show that 1 customer key holds 40% of the rows. A full copy of prod shows that skew and costs as much as prod to run. Choose each environment's data from the failure it is there to catch.

EnvironmentData shapeCatchesMisses
DevA 1% key sample of prod, last 30 days, PII maskedLogic errors and wrong joins on realistic valuesSkew, rare values, full-volume runtime
CIRepo fixtures; slim CI builds only changed models, on small inputsRegressions, contract breaks, edge cases someone wrote downAny case nobody wrote a fixture for
StagingSnapshot clone of prod at full volumeRuntime, memory, skew, migration behaviourData that lands after the snapshot
ProdLive dataEverything, after consumers are exposedNothing

Sampling dev data by key

Sampling each table at random breaks joins. Take 1% of orders and, separately, 1% of customers: only 1% of the sampled orders find their customer, so every dev join comes back nearly empty and looks like a bug. Sample by a shared key instead. Keep every row for customers in a fixed bucket, in every table that carries customer_id, and the same customers exist everywhere.

CREATE TABLE dev.orders AS
SELECT
  o.order_id,
  o.customer_id,
  o.order_date,
  o.amount,
  to_hex(hmac_sha256(to_utf8(o.email), k.secret)) AS email_hash
FROM prod.orders AS o
CROSS JOIN prod_secrets.masking_key AS k
WHERE mod(o.customer_id, 100) = 7
  AND o.order_date >= current_date - INTERVAL '30' DAY

Bucket 7 is arbitrary. What matters is that dev.customers, dev.payments and every other table keyed on customer_id filter on mod(customer_id, 100) = 7. The email goes through hmac_sha256 with a key only prod can read. The same address always yields the same hash, so the column stays unique and joinable, and without the key nobody can hash a list of known emails to match it. A plain sha256 would let them.

A team builds dev by keeping 1% of rows from each table with an independent random filter. Their dev join of orders to customers returns around 1% of the sampled orders. What fixes it?

Staging at full volume

Staging runs at prod volume because performance failures only appear there. A join on a key where 1 value holds 40% of rows finishes on a 1% slice and spills to disk on the full table. A snapshot clone gives full volume for the price of metadata: the staging table points at prod's immutable files as of 1 snapshot, and staging writes create new files without touching prod. Staging pays for the compute it runs and the storage of what it changes.

Dev and CI data
  • Runs in seconds to minutes
  • Shaped by fixtures or key sampling
  • Answers: is the logic right?
  • Cheap to rebuild nightly
Staging data
  • Same volume and distribution as prod
  • Cloned from a prod snapshot
  • Answers: will it run at scale?
  • Pays a full run each release

A change adds a join on merchant_id. In prod, 1 merchant accounts for 35% of transactions, and the new join runs out of memory on that key. Which environment is set up to catch this before release?

About this lesson

This section is part of the Pipeline Operations: Advanced lesson on DataDriven, the home of data engineering. Lessons cover SQL, Python, Spark, data modeling and pipeline architecture, and each section pairs its explanation with worked examples and practice you run as you go.