Production-grade guide to synthetic data generation covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.
Synthetic data generation creates realistic, artificial datasets using models, rules, or code to simulate real-world data. It matters when real data is scarce, expensive, or hard to collect—such as in training machine learning models with limited labeled examples, testing systems under edge cases, or generating test data for continuous integration pipelines.
The first step is defining the structure of synthetic data: what fields exist, their types, and their relationships. A synthetic dataset is not just a table; it is a model of a domain, with constraints and correlations. The schema governs how values are generated, and its design determines downstream performance.
Define the schema as a JSON document, where field types, constraints, and inter-field dependencies are explicitly declared. Use type, required, default, and format keys to describe each field. For nested structures, use object and array types recursively.
{
"name": "Customer",
"properties": {
"id": {
"type": "integer",
"format": "uuid",
"required": true
},
"name": {
"type": "string",
"minLength": 3,
"maxLength": 100
},
"email": {
"type": "string",
"format": "email",
"pattern": "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$"
},
"preferences": {
"type": "array",
"items": {
"type": "string",
"enum": ["newsletter", "sms", "push", "email"]
},
"minItems": 1,
"uniqueItems": true
},
"address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" },
"state": { "type": "string", "pattern": "^[A-Z]{2}$" },
"zip": { "type": "string", "pattern": "^\\d{5}(-\\d{4})?$" }
},
"required": ["street", "city", "state"]
},
"created_at": {
"type": "string",
"format": "date-time",
"default": "now"
}
},
"required": ["id", "name", "email"]
}
When the schema is defined, apply it using a data generation pipeline. The pipeline reads the schema and instantiates data rows based on the rules. A common failure is misreading minLength and minItems—a minLength of 3 on a string does not enforce minItems on an array unless explicitly linked.
Once the schema is fixed, add rules that govern how values are populated. These rules define the logic behind synthetic data: if a customer is from California, their preferences should include push and sms.
Use a declarative rule language in the schema. Each rule consists of a condition and an action. Conditions are expressed using a simple, flat JSON object with field comparisons, and actions modify fields or add new ones.
{
"rules": [
{
"condition": {
"field": "address.state",
"operator": "equals",
"value": "CA"
},
"action": {
"type": "add",
"field": "preferences",
"value": "push"
}
},
{
"condition": {
"field": "created_at",
"operator": "after",
"value": "2023-01-01T00:00:00Z"
},
"action": {
"type": "set",
"field": "is_active",
"value": true
}
},
{
"condition": {
"field": "name",
"operator": "contains",
"value": "John"
},
"action": {
"type": "set",
"field": "segment",
"value": "premium"
}
}
]
}
Rules are applied sequentially. The order matters: a rule adding newsletter to preferences can be overwritten by a later rule that adds push. If the condition fails, the rule is skipped—no error, just silence. A common failure mode is the missing condition key: field is misnamed as field_name, or operator is misspelled as op, causing the rule to be ignored entirely.
Real data has variation. Synthetic data must reflect this. Use statistical distributions to model field values. For example, order_value should follow a log-normal distribution, and age should be normally distributed around 35.
Define distribution parameters in the schema’s properties section:
"order_value": {
"type": "number",
"distribution": {
"type": "lognormal",
"mu": 3.5,
"sigma": 1.2
}
}
The generator reads mu and sigma, draws random numbers from a log-normal distribution, and assigns them to order_value. If mu is missing, the generator defaults to mu = 0, producing values skewed toward 1, often too low.
For strings, use templates. Define a template field with placeholders:
"email": {
"type": "string",
"template": "{{name}}.{{last_name}}@company.com",
"distribution": {
"type": "choice",
"options": [
{ "value": "gmail.com", "weight": 0.6 },
{ "value": "outlook.com", "weight": 0.3 },
{ "value": "company.com", "weight": 0.1 }
]
}
}
The template engine substitutes {{name}} and {{last_name}} from the name field. If name is "Alice Smith", last_name is "Smith", and company.com is chosen, the resulting email is [email protected].
When using template, the generator expects name and last_name to exist. If last_name is missing, the template fails silently—no error, no fallback. The system may produce [email protected] or [email protected], depending on the implementation.
Generate large datasets in parallel using a batch processing framework. A common setup uses a generate command with configurable concurrency and output format.
generate --schema customer.schema.json \
--output-dir ./data \
--count 100000 \
--concurrency 32 \
--format parquet \
--output-partition-by created_at
The command reads the schema, creates 100,000 records, divides the work among 32 worker processes, and writes the output as partitioned Parquet files. Each partition corresponds to a month of created_at.
The --output-partition-by flag expects a list of field names. If created_at is misspelled as created_at (with an extra underscore), the partitioning fails silently, producing a created_at column but no partitioning. The output directory structure becomes flat, and queries on created_at perform poorly.
When --concurrency 32 is used, the generator spawns 32 threads or processes. Each process reads the schema, generates data independently, and writes to a shared output directory. A common failure is race conditions: two processes write to the same file, overwriting each other. The solution is to use --output-suffix to append a unique ID per worker:
generate --schema customer.schema.json \
--output-dir ./data \
--count 100000 \
--concurrency 32 \
--output-suffix "worker-{{worker_id}}" \
--format parquet
Now each worker writes to ./data/customer-0001.parquet, ./data/customer-0002.parquet, etc., avoiding contention.
After generation, validate the output against the schema and rules. Validation is not optional—it is how you catch silent failures.
Run a validate command with a configuration file:
{
"input": "./data/*.parquet",
"schema": "customer.schema.json",
"rules": "customer.rules.json",
"output": "./reports/validation-report.json",
"fail-on": [
"missing-field",
"type-mismatch",
"constraint-violation"
],
"thresholds": {
"total-rows": 95000,
"min-rows": 90000,
"max-rows": 110000
}
}
The validate command checks each row for schema compliance, rule satisfaction, and statistical properties. It reports:
missing-field: a required field is absent.type-mismatch: a value has the wrong type (e.g., string where integer expected).constraint-violation: a minLength, pattern, or enum constraint fails.rule-failure: a rule condition was not met, but its action was not applied.The output is a JSON report with errors, warnings, and summary. The fail-on list determines which failures cause the command to exit with non-zero status.
A subtle failure: the thresholds key is misnamed threshold (singular). The system reads thresholds but ignores threshold, leading to missing validation checks. Another: fail-on expects a list of strings, but if fail-on is a single string instead of an array, only the first error type triggers a failure.
As models evolve, so do data schemas. A new feature, loyalty_points, is added to Customer. The generator must handle old data while producing new records.
Use a schema-version field in the output:
{
"version": "1.2",
"generated-by": "synthgen v0.8.3",
"generated-at": "2024-05-14T12:00:00Z"
}
The generator adds this metadata to every output file. When validating, the validate command checks version against a min-version and max-version in its configuration.
{
"schema": "customer.schema.json",
"min-version": "1.0",
"max-version": "1.5",
"fail-on": ["version-mismatch"]
}
If the generated data has version: "1.2", the validation passes. If version: "0.9", it fails with version-mismatch. The system does not warn—only fail.
A common mistake is assuming that schema evolution is automatic. But if loyalty_points is added to the schema but not to the rules file, the field is generated but not validated. The validate command reads schema but ignores rules—the rules are not applied to the generated data.
created_at is defined as string with format: date-time, but the generator outputs date-time as YYYY-MM-DD. The format key is ignored, and created_at is parsed as ISO 8601 but not validated. The data is valid but not conformant.address.zip but the field is address.postal_code. The rule is never applied, and the error is discovered only in production.distribution block is defined but type is missing. The generator defaults to type: "uniform", but the expectation was type: "normal".--output-partition-by created_at fails silently because created_at is date instead of date-time. The partitioning is applied to a column that does not exist.part-00000.parquet file. The final file is corrupted—overwritten, truncated, or missing rows.thresholds is a single object, but total-rows is misspelled as total_rows. The system reads total_rows but ignores total-rows, leading to an undetected data drift.Synthetic data generation is not about producing data—it is about producing reliable, consistent, validated data that reflects the real world. Its success lies in the details: the schema, the rules, the distributions, and the validation. And every detail can fail silently, leaving engineers to discover what they thought was working.
This page was rewritten on 14 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy