Last active
December 22, 2025 10:27
-
-
Save amanbolat/dc1b991a1b51361754b29792d275510c to your computer and use it in GitHub Desktop.
Go interview question - Synthetic Data Generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // # Problem Statement | |
| // | |
| // We need a tool to generate massive amounts of synthetic data for testing our pipelines. Your task is to build a configurable engine that takes a JSON schema and outputs all the generated data to standard output. | |
| // | |
| // # Requirements | |
| // | |
| // 1. The generator must support these 3 field types: | |
| // * `sequence`: An auto-incrementing integer (e.g., 1, 2, 3...) starting from 1. | |
| // * `name`: A random name from the pre-defined set of names. | |
| // * `formula`: A template that should be parsed and executed to derive the value. | |
| // 2. Program should be buildable and output expected result. | |
| // 3. Output should be deterministic. | |
| // 4. No requirements to the output format, it can be CSV, JSON or just printed out as is. | |
| // | |
| // | |
| // **Example input:** | |
| // | |
| // { | |
| // "count": 5, | |
| // "seed": 1, | |
| // "fields": [ | |
| // { "name": "id", "type": "sequence" }, | |
| // { "name": "name", "type": "name" }, | |
| // { "name": "description", "type": "formula", "formulaValue": "{{ .name }}'s ID is {{ .id }}" } | |
| // ] | |
| // } | |
| // | |
| // | |
| // **Example output:** | |
| // | |
| // id, name, description | |
| // 1, Bob, Bob's ID is 1 | |
| // 2, Alice, Alice's ID is 2 | |
| package main | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| ) | |
| // Config represents the input JSON structure | |
| type Config struct { | |
| Count int `json:"count"` | |
| Seed int `json:"seed"` | |
| Fields []Field `json:"fields"` | |
| } | |
| // Field represents a single column definition | |
| type Field struct { | |
| Name string `json:"name"` | |
| Type string `json:"type"` // sequence, name, formula | |
| FormulaValue *string `json:"formulaValue,omitempty"` | |
| } | |
| var names = []string{"Alice", "Bob", "John"} | |
| func main() { | |
| jsonData := ` | |
| { | |
| "count": 5, | |
| "fields": [ | |
| { "name": "id", "type": "sequence" }, | |
| { "name": "name", "type": "name" }, | |
| { "name": "desc", "type": "formula", "formulaValue": "{{ .name }}'s ID is {{ .id }}" } | |
| ] | |
| }` | |
| var config Config | |
| if err := json.Unmarshal([]byte(jsonData), &config); err != nil { | |
| panic(err) | |
| } | |
| // TODO: Implement the generator logic here | |
| fmt.Println("Generating data...") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment