There are two broad ways to fill a test environment with data that behaves like the real thing. One is to take a copy of production and scrub it. The other is to generate data from nothing. Teams argue about this, and I will take a side at the end: generate by default, mask only for the cases that force you to.

The case for copying production

Real data is messy in ways nobody would invent. Customer names with trailing spaces, a phone number stored with a country code in half the rows and without in the rest, orders from 2016 that use a status value the code no longer produces. A copy contains all of it for free, and it has realistic volume and distribution, which matters for performance tests and for queries whose speed depends on how values are spread.

The price is risk. Test environments typically have weaker access control than production, more people with login, vendors and contractors with access, logs shipped to places nobody audits, and databases left running on a laptop. A raw copy of customer records in such a place is a data breach waiting for a trigger. In India the Digital Personal Data Protection Act, 2023 puts obligations on organisations that process digital personal data, including safeguards and breach consequences. I would not try to give a legal opinion on whether a particular test copy is permitted, and your compliance team should decide that, but the practical position is plain: the fewer places real personal data lives, the better. Sector rules, such as those that apply to banks and insurers under their regulators, can be stricter again.

Masking is harder than it sounds

Masking means replacing sensitive values while keeping the data usable. Common techniques:

  • Substitution: replace real names with plausible fake ones from a list.
  • Shuffling: keep the real values but reassign them to different rows, so the column’s distribution survives while the link to a person breaks.
  • Tokenisation or format-preserving replacement: turn a PAN or card number into another value of the same shape, so validation code still accepts it.
  • Nulling or redaction: drop the value entirely where the test does not need it.

The trouble is consistency. If customer “Meera Iyer” appears in the orders table, the support tickets table, a CSV in a file store and a search index, she must become the same fake person in all of them, or joins and lookups break. And masking is rarely complete. Free-text fields such as notes and complaint descriptions contain names, addresses and phone numbers that a column-by-column rule will never find. A date of birth, a PIN code and a gender can together re-identify a person even when the name is gone, so removing the obvious columns is not the same as anonymising.

Subsetting: the in-between step

Full production copies are huge. Subsetting extracts a slice, for example every record connected to 5,000 chosen customers, following foreign keys so the slice is self-consistent. It cuts storage and refresh time and reduces exposure, but it needs an accurate map of how tables relate, including the relationships that exist only in application code. A subset that leaves out the parent row of a child record produces failures that look like product bugs and are not.

The case for synthetic data

Synthetic data is created by code or tools: factories that build a customer, an address, an account and an order with the properties a test needs. No personal data exists to leak. You also get control. Want a customer with a failed KYC, two addresses and a refund pending? Ask for exactly that, instead of searching a copied database for a lucky row and hoping nobody changes it before your test runs.

It has weaknesses. Invented data is too clean unless you add noise deliberately; it often lacks the rare, ugly cases that break software; and statistically faithful synthetic data, for performance work, takes real effort. If you generate data that look like PANs, make them match the structure (five letters, four digits, one letter, and the fourth letter indicating the holder category, such as P for an individual) so format checks behave, but use obviously fake values wherever the system does not verify them against an external source.

Where I land

My opinion: generate for functional testing, and keep a small, curated set of nasty real-shaped records, written by hand, from every production incident you have had. For performance and migration rehearsals, where volume and skew truly matter, use a masked subset, and treat the masking job as production code with tests: after each run, scan the output for patterns such as email addresses and 10-digit numbers, and fail the build if any survive in places they should not.

The one position I would reject is “it is only the QA environment”. Environment names do not reduce the harm if the data leaks. Decide who owns the test data process, write down what is allowed, and review it when the system changes.

Figures and names in the examples are illustrative.

Leave a Reply

Trending