# Data Lab: prompt for your AI agent

Copy everything below the line into ChatGPT, Claude, Copilot or your company agent. Replace {{CONTEXT}} with a short description of your business and systems (no secrets). Then paste the JSON it returns into Data Lab (Generate with AI > Paste).

---

You are a senior data engineer. Design or document my data architecture and answer in the "data-lab/v1" JSON format, which I will import into Data Lab (a visual studio that simulates data flow). Schema: https://data-lab.co/schema/v1.json

## My context
{{CONTEXT}}

## How to answer
1. Ask at most 3 short questions, only about what my context lacks: (a) sources with PEAK volumes (events/s or rows/day, record size), (b) platform and tools, (c) each consumer and its freshness need (SLA). If I say "assume" or the context is enough, ask nothing.
2. Then reply with a short "Assumptions" list (max 6 bullets: volumes, freshness, delivery), then ONE ```json block with a single JSON object: valid JSON only (no comments, trailing commas or placeholders). 
3. Never include secrets, keys, hostnames, IP addresses, connection strings or personal data. Use generic ids and names.

## Format
Top level: { "format": "data-lab/v1", "name": string, "description"?: string, "components": [...], "flows": [...] }. No positions; the layout is automatic.

### components (each needs "id" and "type")
- id: unique, short, [A-Za-z0-9_.:-], max 64 chars (e.g. "orders_db"). type: one of the list below.
- vendor: the concrete product when known (e.g. "PostgreSQL", "Redis", "Iceberg"); keep type generic: Redshift is type "snowflake" with vendor "Redshift", Dagster is type "airflow" with vendor "Dagster", a managed service is its engine (MSK = kafka, MWAA = airflow, EMR = spark, ElastiCache = cache).
- label (max 80 chars), description (max 500), layer (one of source, ingest, process, store, serve; defaults to the type's layer).
- numbers: capacityPerSec (max events/s it sustains; set it for logs and stream processors), capacityRecordsPerRun (batch engines), partitions, retentionHours, slaFreshnessSec (max acceptable data age in seconds, on the component that consumers read).
- runsOn (optional; only when the hosting is known or reasonably assumed; it sets hard throughput limits and a monthly cost estimate): { "kind": "managed", "provider": aws | gcp | azure | snowflake | databricks | confluent, "service": "MSK Express", "size": "express.m7g.large", "count": 3 } or { "kind": "self-hosted", "vcpu", "memGiB", "disk": nvme | ssd | hdd | object, "diskGiB", "netGbps", "instances" }. Add "activeHoursPerDay" (0-24) for compute that stops between runs (nightly cluster, auto-suspending warehouse); omit if always on. Use exact vendor names; unknown ones are dropped. costUsdPerHour: your measured compute USD/hour.
- format: parquet | delta | iceberg | hudi | avro | protobuf | json | csv. transform: { "kind": map | filter | aggregate | join | explode, "selectivity": output/input ratio, e.g. 0.05 for an aggregation, 1 for a join/enrich }.

Allowed types (default layer):
- api (source): application, service, webhook, IoT device or other event producer
- database (source): operational/OLTP database (Postgres, MySQL, MongoDB...); set vendor
- kafka (ingest): durable, replayable event log/broker (Kafka, Pub/Sub, Event Hubs, Pulsar)
- kinesis (ingest): managed stream (Kinesis Data Streams / Firehose)
- airflow (process): orchestrator that schedules jobs (Airflow, Dagster, Prefect); use control flows
- spark (process): distributed batch/stream compute (Spark, EMR, Databricks jobs)
- flink (process): low-latency stream processor (Flink, Kafka Streams, Beam, ksqlDB)
- dbt (process): SQL transformation models run inside a warehouse/lakehouse (dbt, Dataform, SQLMesh)
- s3 (store): object store / data lake files (S3, GCS, ADLS)
- lakehouse (store): open-table lakehouse (Delta, Iceberg, Hudi; Databricks)
- snowflake (store): cloud data warehouse / OLAP store (Snowflake, Redshift, Synapse, ClickHouse)
- bigquery (store): BigQuery warehouse
- dlq (process): quarantine for records that failed processing
- bi (serve): dashboards and reports (Looker, Tableau, Power BI, Superset); consumers only
- ml (serve): model training or serving endpoint
- schema_registry (ingest): schema/contract registry for events
- cdc_connector (ingest): log-based change capture (Debezium, Datastream, DMS)
- feature_store (serve): online/offline ML features (Feast, Tecton)
- vector_db (store): embedding store for semantic search / RAG (pgvector, Pinecone, Qdrant)
- reverse_etl (serve): syncs warehouse data back to SaaS tools (Hightouch, Census)
- data_quality (process): validation/observability checks (Great Expectations, Soda, Monte Carlo)
- catalog (store): metadata catalog / lineage (DataHub, Unity Catalog, Collibra)
- cache (serve): low-latency key-value cache (Redis, Memcached)

### flows (each needs "from" and "to", both component ids)
- mode: stream | batch | cdc. stream = continuous events; cdc = database change capture; batch = scheduled runs. Inferred from the endpoints if omitted.
- Rates: eventsPerSec for stream/cdc (peak sustained, realistic: Kafka thousands to hundreds of thousands/s, CDC sub-second lag); recordsPerRun plus schedule (cron) for batch. Always give numbers for flows on a log or stream processor; defaults are placeholders.
- latencyMs = time this hop adds, including commit interval, micro-batch or run duration (e.g. 60000 for a 60 s lake commit).
- errorRate (fraction 0..1), dlqTarget (id of a "dlq" component), ordering (none | per-key | global), delivery (at-most-once | at-least-once | exactly-once), schema (e.g. "orders.v1"), bytesPerRecord.
- kind "control" = orchestrator trigger (e.g. Airflow -> Spark job); carries no data. Orchestrators only have control flows.
- kind "metadata" = governance link, always FROM the pipeline component TO the schema_registry, catalog or data_quality component (CDC connector -> registry, consumer -> registry, lake table -> catalog, table -> its quality check). No rate, mode or schedule; "schema" optional.

## Conventions (Data Lab reads these literally)
- Direction follows the data: sources -> ingest -> process -> store -> serve. bi, ml and dlq are sinks.
- Read path: an application that reads from a cache, database, warehouse or feature store (e.g. a product API) is type "api" with layer "serve" (the only case where an api is a flow target). Model the read as a flow store -> api, mode "stream", eventsPerSec = peak read requests/s (may exceed the write rate: reads do not consume data), latencyMs = read latency. No errorRate or DLQ on reads.
- DLQ: put errorRate and dlqTarget on the flow INTO the failing stage, and add exactly one flow from that stage to the dlq with eventsPerSec = input rate x errorRate. Never send DLQ output back into the main log.
- schema_registry, catalog and data_quality carry no records: no data flows to a registry or catalog; link each with at least one metadata flow. Airflow may also trigger data_quality (control).

## Before you answer, check
1. Volume: each branch out of a stage <= its input x selectivity x (1 - errorRate); fan-out sends the full rate to every branch; aggregations carry transform.selectivity.
2. Batch: recordsPerRun = upstream events/s x schedule interval in seconds (2,000/s hourly = 7,200,000) and fits capacityRecordsPerRun; every batch flow has a schedule.
3. Partitions >= peak MB/s / ~10 and >= the largest consumer's parallelism (round up: 12, 24, 48). Keep capacityPerSec at least 1.25x peak inflow.
4. Delivery end to end: exactly-once only from a log into a processor with checkpoints and onto a transactional or idempotent sink (Kafka transactions, Iceberg/Delta commits); idempotent upserts and everything else: at-least-once.
5. CDC and keyed streams: ordering "per-key" from capture through the log (key = primary key); "global" only on a single partition.
6. retentionHours >= longest replay or outage you must survive (CDC logs: 72-168 h) and >= any batch consumer's interval.
7. Freshness: on each path, sum of latencyMs plus the schedule interval of each batch hop (back-to-back hops with the same cron count once) must be <= the consumer's slaFreshnessSec. Shorten hops or relax the SLA.
8. Orchestrators only trigger jobs (control flows); every scheduled job has one. Sinks emit nothing. No data cycles (lint warns): replay from the log. ADF only orchestrates: model copies as cdc_connector/spark.
9. Keep raw (immutable) and curated (cleaned, modelled) stores separate; consumers read curated.
10. Every stage with errorRate > 0 has the DLQ policy and flow above. Avro/Protobuf/CDC topics get a schema_registry with metadata flows from the producer and each consumer, and a schema name on the data flow. Every catalog and data_quality has metadata flows from the tables it covers or checks.
11. Every id is unique, every flow endpoint exists, ids in dlqTarget exist, an api that is read from has layer "serve".

## Example
```json
{
  "format":"data-lab/v1","name":"Orders: CDC to product API and analytics","description":"Postgres changes stream to a cache that serves the product API (seconds-fresh) and to a raw lake that an hourly Spark job curates for BI.",
  "components": [
    {"id":"orders_db","type":"database","vendor":"PostgreSQL","label":"Orders DB"},
    {"id":"cdc","type":"cdc_connector","vendor":"Debezium","capacityPerSec":20000},
    {"id":"registry","type":"schema_registry","description":"Avro schemas, BACKWARD compatibility"},
    {"id":"events","type":"kafka","label":"Order change log","partitions":24,"retentionHours":168,"capacityPerSec":100000,"format":"avro","runsOn":{"kind":"managed","provider":"aws","service":"MSK Express","size":"express.m7g.large","count":3}},
    {"id":"enrich","type":"flink","label":"Enrich and validate","capacityPerSec":10000,"transform":{"kind":"join","selectivity":1}},
    {"id":"dlq","type":"dlq","description":"Records that fail validation; replay after a fix"},
    {"id":"serving_cache","type":"cache","vendor":"Redis","label":"Order state cache","capacityPerSec":100000,"slaFreshnessSec":5},
    {"id":"product_api","type":"api","layer":"serve","label":"Product API","description":"Reads order state; peak 5,000 requests/s"},
    {"id":"lake_raw","type":"lakehouse","vendor":"Iceberg","label":"Raw orders (as received)","format":"iceberg"},
    {"id":"orchestrator","type":"airflow","vendor":"Airflow"},
    {"id":"curate","type":"spark","label":"Hourly curation","capacityRecordsPerRun":20000000,"transform":{"kind":"aggregate","selectivity":0.05},"runsOn":{"kind":"managed","provider":"aws","service":"EMR","size":"m5.xlarge","count":4,"activeHoursPerDay":2}},
    {"id":"lake_curated","type":"lakehouse","vendor":"Iceberg","label":"Curated order metrics","format":"iceberg","slaFreshnessSec":10800},
    {"id":"dashboards","type":"bi","vendor":"Looker"}
  ],
  "flows": [
    {"from":"orders_db","to":"cdc","eventsPerSec":2000,"latencyMs":500,"ordering":"per-key"},
    {"from":"cdc","to":"events","eventsPerSec":2000,"latencyMs":100,"ordering":"per-key","delivery":"at-least-once","schema":"orders.v1"},
    {"from":"events","to":"enrich","eventsPerSec":2000,"latencyMs":200,"errorRate":0.001,"dlqTarget":"dlq","ordering":"per-key","delivery":"exactly-once"},
    {"from":"enrich","to":"dlq","eventsPerSec":2,"latencyMs":50},
    {"from":"enrich","to":"serving_cache","eventsPerSec":1998,"latencyMs":100,"delivery":"at-least-once"},
    {"from":"enrich","to":"lake_raw","eventsPerSec":1998,"latencyMs":60000,"delivery":"exactly-once"},
    {"from":"cdc","to":"registry","kind":"metadata","schema":"orders.v1"},
    {"from":"enrich","to":"registry","kind":"metadata"},
    {"from":"serving_cache","to":"product_api","mode":"stream","eventsPerSec":5000,"latencyMs":5},
    {"from":"orchestrator","to":"curate","kind":"control","schedule":"0 * * * *"},
    {"from":"lake_raw","to":"curate","mode":"batch","recordsPerRun":7192800,"schedule":"0 * * * *","latencyMs":600000},
    {"from":"curate","to":"lake_curated","mode":"batch","recordsPerRun":359640,"schedule":"0 * * * *","latencyMs":120000},
    {"from":"lake_curated","to":"dashboards","mode":"batch","recordsPerRun":50000,"schedule":"0 * * * *","latencyMs":2000}
  ]
}
```

Now produce the JSON for my architecture.
