FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Guides

Copying production to staging is the first mistake at a client site

When a client has one database full of personal data, mask it before it leaves production and build all three environments from a single definition in code.

ShareLinkedInFacebookX

In brief

  • Do not copy production data straight into staging: personally identifiable information (PII) goes with it.
  • Mask data before it leaves production, then create staging and dev from the masked copy.
  • Describe all three environments in code and promote them through Git, so they stay identical except for parameters.
Comparison of two ways to mask data. Before: real PII is copied from production to a non-prod environment and only then masked, so a single wrong access permission exposes the data. After: data is masked inside production, non-prod receives only the masked copy, and PII never leaves production.
Where the masking step sits decides whether PII leaves production. Source: Database Lab Engine (Postgres.ai) and Neon documentation, as cited in the article.

In the first week at a client site, you ask where staging is. The answer: there is only one database, and it is production, holding the name, phone number and address of every customer. The pipeline you are about to write has to run on that data, yet you cannot experiment on it.

The first instinct is usually “copy production to another database to be safe”, and that instinct is wrong. Neon, the serverless Postgres provider, warns plainly that production data cannot be safely copied to staging or test environments, because personal information travels with the copy.

This guide walks through five steps to build three environments from scratch. All three are described in code, data is masked before it leaves production, and deployment goes through Git. The code here is a simplified illustration of the structure, not configuration you can run as is.

What you will build, and what you need

The running example is a hypothetical delivery company with an orders table. The table has the columns id, customer_name, phone, address, order_value and created_at. The end result is three environments, dev, staging and prod, sharing one definition, with dev and staging seeing only masked data.

You need read access to the production schema, an infrastructure-as-code tool and a Git repository. On tools: OpenTofu works for both cloud and on-premises. AWS CDK lets you write infrastructure in a programming language and deploy it through CloudFormation. On GCP, Infrastructure Manager runs Terraform configurations as a managed service. If the client runs Kubernetes, add Argo CD.

Step 1: Flag the PII columns first

Before writing a single line of infrastructure, sit down with someone who understands the client’s data and classify every column. In the example, customer_name, phone and address are PII. order_value and created_at must stay intact, because your pipeline computes on exactly those columns.

Do not skip this step. Neon states clearly that it does not detect PII automatically and masks nothing unless the user declares the rules. So rather than relying on automatic detection, treat your classification file as the primary input for every masking rule.

Check: you have a classification file in which every column falls into one of two groups, keep or mask. The client has reviewed it and agreed.

Step 2: One definition, three sets of parameters

Environment as Code means describing the whole environment in code, including services, configuration and dependencies. According to Bunnyshell, this makes each environment a replica of production, which cuts down on “it works on my machine”. For that to hold, the definition must be written only once.

# Illustrative repo layout, not tied to any specific tool
pipeline-infra/
  modules/pipeline/     # the single definition: DB, jobs, scheduler
  envs/
    dev.yaml            # parameters only
    staging.yaml
    prod.yaml

With CDK, you get the parameters, conditionals and loops of a real programming language. The snippet below is a sketch in plain Python, not the CDK API:

# Sketch: same function, different parameters
ENVS = {
    "dev":     {"data_source": "masked", "size": "small"},
    "staging": {"data_source": "masked", "size": "medium"},
    "prod":    {"data_source": "live",   "size": "large"},
}
for name, params in ENVS.items():
    build_pipeline(name, **params)   # a function you write yourself

Check: comparing the parameter files is pointless, since by design they contain only parameters. Compare what they produce instead: the resource list after rendering the full configuration for staging and prod, or the list of resources actually deployed. If they differ in anything other than size and data source, such as a service that exists only in prod, staging is no longer a faithful replica.

Step 3: Where to mask is the question that matters most

There are two places to put the masking step, and their risks are far apart. The documentation for Database Lab Engine (Postgres.ai) describes both.

Mask before leaving production

  • PII stays only in production
  • Non-prod environments receive only the masked copy
  • Masking rules run on the client's infrastructure

Mask in the non-prod environment

  • PII is physically copied out of production
  • Real data sits on non-prod infrastructure
  • A single wrong permission exposes the data

At a client site, choose the left column. A simple approach is to create a masked view inside production and grant the export process read access to that view alone:

-- Illustration, Postgres with the pgcrypto extension;
-- the secret key stays in production and never travels with the export
CREATE VIEW orders_masked AS
SELECT id,
       'customer_' || id AS customer_name,
       encode(hmac(phone, current_setting('app.mask_key'), 'sha256'), 'hex') AS phone,
       'redacted'        AS address,
       order_value,
       created_at
FROM orders;

Pay attention to the choice of masking function. Phone numbers have a small value space, so if you hash with md5(phone) and no key, anyone holding the export can hash every possible phone number and match them back.

A keyed hash (HMAC) preserves uniqueness, so the pipeline can still join or count returning customers, but without the key it cannot be reversed. order_value stays untouched so that results computed in staging match reality.

Check: run a query on the export that searches for strings shaped like phone numbers. The result must be zero. Keep the query and run it every time the data is refreshed.

Step 4: Staging and dev both come from the masked copy

Once the masked copy exists, every non-prod environment draws its data from it. Neon describes a branching approach: child branches inherit the masked data, and refreshing staging is simply a matter of recreating the branch. If the client does not use Neon, the same principle applies with snapshots of the masked copy.

The practical gain is that each engineer’s dev environment can be deleted and recreated at any time without anyone touching production. A bug that only appears with real data can now be reproduced on data of the same shape, just without the real names.

Check: delete your dev branch or database and recreate it. If it takes more than a few minutes, or needs someone to grant you production access, the process still has a gap.

Step 5: Promote environments through Git, not by hand

The final step stops the three environments drifting apart over time. Argo CD is a GitOps-style continuous delivery tool for Kubernetes. Its principle is that application definitions, configuration and environments must all be declarative and under version control. Argo CD can also manage multiple clusters.

# Illustration: each environment points to a directory in the repo
deploy/
  dev/       -> dev cluster
  staging/   -> staging cluster
  prod/      -> prod cluster

To move a change from staging to prod, you open a pull request that edits the prod/ directory rather than running commands by hand on your own machine. For non-Kubernetes infrastructure, OpenTofu aims at the same thing: a single workflow for managing infrastructure throughout its lifecycle.

Check: pick any change running in prod and trace it back to the commit it came from. If you cannot find one, someone is editing by hand.

Three common mistakes at client sites

The first mistake is masking with a script run on an engineer’s laptop. The real data has already landed on the laptop, which puts it squarely in the right-hand column of the comparison, only on a machine even harder to control than a non-prod server.

The second is forgetting new columns. Say the client adds an email column next month and the masking rules are not updated. With a tool such as Neon that masks only according to manually declared rules, that column flows straight into staging.

The phone-number scan from step 3 will not catch this, because it does not look at the schema.

The fix is a separate check, call it a schema check: read the current column list of the production table, compare it with the classification file from step 1, and fail when it finds a column that has not been classified.

Run it alongside the scan every time the data is refreshed.

The third mistake is letting staging drift from prod through “just a quick fix”. After a few weeks, staging no longer proves anything about prod.

How this skill shows up in FDE interviews

When reading FDE job descriptions, watch for phrases such as “deploy in customer environments”, “regulated data” or “on-prem”. When you see them, have an answer ready for how you handle real data, because the job is likely to put you in exactly the situation described here.

On your CV, do not just write “used Terraform, Argo CD”. Write in terms of outcomes, for example: built three environments from a single definition, masked PII inside production, with automated checks running on every data refresh. Those three points show you understand the risk a client holding real data has to carry.

In your first session with a client, do not open by asking for production admin access. Ask to sit down and classify columns with the person who owns their data. It is the cheapest step, and a good way to start building trust.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
7 sources
Read next on the roadmap · Stage 5: DeploymentSQS promises delivery at least once. Build for the duplicatesA Free Tier fanout exercise with SNS, three queues and Lambda rehearses the duplicate and lost-message failures before you meet them on a client site.