A reference data architecture for a B2B SaaS company that has outgrown running its analytics on the product's Postgres, a scenario common across the industry: the brief, the current state measured, the options, a staged target architecture, the data model and contracts, security and governance, the migration, and the decisions, each backed by measured results.
The company. 6,000 customer accounts, 350,000 product events a day growing about threefold in the first year and then roughly 2.2 times a year, a data team of two, and everything the business knows about itself read from the product's Postgres on RDS and its one read replica (the brief).
What is wrong, measured on a lab copy of its database (current state):
- At the brief's peak rate, with the BI tool's reports on the primary, the product's 95th-percentile request went from 40 ms to 525 ms.
- On the replica, 3 of 35 runs of the long reports finished in five minutes; the rest
were cancelled by recovery conflicts. Turning on
hot_standby_feedbacklets them finish by holding back the product database's cleanup; a replica for reports alone with a 15-minute replay delay let all of them finish, and fell up to 4.7 minutes behind instead. - Revenue by plan is read from each account's current plan; on this business's shape of data that puts 15.1% of a year's revenue on the wrong plan.
- Events are deleted after 90 days, nobody can say who read personal data, and there is no way to erase a person from every copy, which two enterprise prospects require.
The recommendation.
- Now: every report on the replica, never the primary, and the replica the reports' alone, with a 15-minute replay delay: minutes of lag cost nothing a report needs (0001).
- Within six months: a managed analytical platform fed by change data capture, with a Type 2 star schema reconciled to Stripe, governance by classification tags, and erasure that can be proven (stage 1). Personal data lives in one identity table per source, because where the model keeps it decides what an erasure costs: measured, 31,849,449 event rows rewritten to erase one person when the e-mail was in every row, 59,999 when it was not (0017). The platform sits inside the SOC 2 scope from the day it holds customer data (12).
- Databricks or Snowflake is decided by a two-week proof of concept on criteria and weights fixed in advance (0005); every criterion has run on both (11). At this scale the list-price bill does not separate them: in the company's EU region, at the editions the requirements need, about $710 to $1,000 a month today and $2,900 to $4,000 at 36 months, against a $15,000 budget; the people to run a self-built lakehouse would cost more than either (options). The proof of concept scored them 93.4 (Databricks) to 91.8, a tie that the rule fixed in advance gives to Snowflake (14. The platform decision).
- Months 6–10: customers' usage under a minute old from a store fed by a stream (stage 2). Months 10–13: the assistant, on the same governed tables (AI architecture).
flowchart LR
today[Today] --> stage1["Stage 1: the platform"] --> stage2["Stage 2: customer usage"] --> stage3["Stage 3: the assistant"]
Detail, timing and exit criteria for each stage are in 5. Target architecture.
| Document | What it answers | |
|---|---|---|
| 1 | Brief | who the company is, why now, stakeholders, constraints, scale |
| 2 | Current state | what running analytics on the product's database costs, measured |
| 3 | Requirements | each consumer's needs; 15 quality targets as testable scenarios |
| 4 | Options | five options against the requirements; cost with and without people |
| 5 | Target architecture | the stages, C4 context and containers, zones, deployment, failure modes |
| 6 | Data model | domains, the logical model and glossary, layers, the star schema, physical design per engine, modelling standards; contracts |
| 7 | Security and governance | the operating model, classification, access lifecycle, retention, data quality, the access audit, erasure |
| 8 | Migration | inventory, waves, running both, cutover and rollback |
| 9 | Operations | what is watched, runbooks, change and release |
| 10 | Roadmap | week by week to the platform live, then the year, with costs and team |
| 11 | Proof of concept | Databricks and Snowflake: the dbt project, masking by tag, row filters, erasure through time travel, speed, the day's bill, Terraform |
| 12 | SOC 2 readiness | scope, the control matrix, and what an auditor asks |
| 13 | Quality attributes | every quality attribute, where it is designed and what was measured; disaster recovery |
| 14 | The platform decision | Databricks or Snowflake on one page: parity, where they differ, the recommendation and when to choose differently |
| 15 | One field, end to end | A user's e-mail address from the product database to the assistant's answer: every copy, who reads it, how it is erased, what was measured, and the risk left |
| 16 | The investment recommendation | one page for the CTO: the ask, what it buys, what is proven, how to back out, and the answer if the cost, the staffing or the residency changes |
| 17 | The first 90 days | from the decision: work, people, dependencies, run cost, rollback and a go-or-stop point every 30 days |
| 18 | The first assessment | the consulting version: a three-week assessment, what it takes in and hands over, how it is accepted, what it leaves out |
| Decisions | 18 decision records with options, drivers and evidence | |
| Risks, principles | the register; the rules across decisions |
| # | Decision | Status | Backed by |
|---|---|---|---|
| 0001 | Analytics moves off the product's database onto a separate platform | Accepted | 40 → 525 ms product p95 request latency, without and with the BI tool's reports on the primary; 3 of 35 runs of the three long reports that finished on the read replica in five minutes; 32 were cancelled by recovery conflicts |
| 0002 | The product's tables reach the platform by change data capture, not extracts | Accepted | 533 of 570 account changes in a year seen by monthly snapshots; 15.1% of a year's revenue on the wrong plan with a Type 1 account dimension |
| 0003 | Files that land are immutable, and every load writes by key | Accepted | 1,638 events never loaded by COPY INTO and Auto Loader after a truncated file was corrected under the same name; 0 of 3,198 bad rows promoted when any failing data-quality check held the day |
| 0004 | A managed platform, not a self-run lakehouse | Accepted | 909,968 rows recovered by snapshot rollback; 20 → 1 files merged per partition by optimize |
| 0005 | Databricks or Snowflake: decided by a two-week proof of concept on fixed criteria | Accepted | 11, 46, 3 models, data tests and unit tests that passed when the dbt project was built on Databricks after one change, with revenue figures identical to DuckDB's; 3 of 3 personal columns masked by one policy on the classification tag, including a column on a table created after the policy |
| 0006 | Tables are kept in an open format, in storage the company owns | Accepted | 909,968 rows recovered by snapshot rollback; 88 ms one-month predicate over 1.5M Iceberg rows |
| 0007 | A Kimball star, with Type 2 history for every attribute a fact is reported by | Accepted | 15.1% of a year's revenue on the wrong plan with a Type 1 account dimension; 5,048 of 5,048 invoices on the plan they billed, Type 2 dimension from dbt snapshots |
| 0008 | Incremental models load their run's window and replace it by key | Accepted | 96.56% of a month's events lost by high-water-mark loads backfilled newest day first, every run green; 0 of 89,508 events loaded by a data-interval incremental model on Airflow 3's default @daily, in 30 successful runs |
| 0009 | Pipelines are scheduled by the platform's own jobs, not a separate orchestrator | Accepted | 0 of 89,508 events loaded by a data-interval incremental model on Airflow 3's default @daily, in 30 successful runs |
| 0010 | Stage 2: customers' usage is served from a store fed by a stream, not from the platform | Proposed | 6.1 s p99 from event time to queryable in ClickHouse at 1,000 events/s; 9 of 9 failure runs with every event layer exact |
| 0011 | Classification tags drive masking and row filters; every table carries the account | Accepted | 3 of 3 personal columns masked by one policy on the classification tag, including a column on a table created after the policy; 1 of 5 accounts visible through a row filter keyed to the caller's identity |
| 0012 | Erasure: delete by key, then let every copy of the old version expire inside 30 days | Accepted | 100 of 100 rows of an erased user still returned by time travel after DELETE and after REORG … APPLY (PURGE); refused time travel to the version before the delete, once the table's deleted-file retention had passed and VACUUM had run |
| 0013 | Every source has a contract, checked in the producer's CI | Accepted | reported as breaking what datacontract breaking says for the product contract with users.email renamed; an unchanged copy is not reported as breaking; 0 breaking schema changes passed as safe, in any mode |
| 0014 | Quality gates: tests on rows, checks on the day, reconciliation to billing | Accepted | 0 of 3,198 bad rows promoted when any failing data-quality check held the day; 4 of 4 deliberate model breaks that failed the build |
| 0015 | Every analytical table can be restored to any point in the last 7 days | Accepted | 365 of 365 days back after RESTORE TABLE, following an INSERT OVERWRITE of one day that left 1; 909,968 rows recovered by snapshot rollback |
| 0016 | Kimball marts over a raw change history, without a Data Vault layer | Accepted | 5,048 of 5,048 invoices on the plan they billed, Type 2 dimension from dbt snapshots; 15.1% of a year's revenue on the wrong plan with a Type 1 account dimension |
| 0017 | Personal data lives in one place: facts carry keys, not identities | Accepted | 31,849,449 rows rewritten to erase one person (551 events) when the model copies e-mail and name into every event row; 59,999 when they live only in a 60,000-row user table; 8 files rewritten by deleting one user's rows from a UniForm table, which refuses deletion vectors; time travel still returned all 100 rows until the retention passed |
| 0018 | SOC 2: the platform inside the system description, vendors carved out, three criteria | Accepted | 5 of 5 columns tagged personal whose every read in 90 days one query found, by reader, column and time, from the catalog's tags and the platform's column lineage; 6 of 7 kinds of governance object Terraform owned on Databricks, with a clean plan after applying; the seventh, the mask function, needs SQL |
Every figure, with its method and source file, is in EVIDENCE.md.
| Status | |
|---|---|
| The current state | measured: baseline/ runs the company's database and workload in Docker, four scenarios (results/baseline.json) |
| Loading, history, backfills, quality gates, overwrite and restore on Delta | measured in data-stack-lab, on the same generated business data, partly on Databricks |
| Contracts | linted in CI; a breaking change is shown to fail the producer-side check |
| Platform cost | modelled from list prices with stated assumptions (cost/); the proof of concept measures it |
| Databricks against Snowflake | both halves measured (11). Databricks: the dbt project built with one change and gave identical figures; one policy masked every personal column; erasure is final only after VACUUM past the table's retention. Snowflake: the dbt project built with no change and gave identical figures; only COPY INTO and a MERGE loaded the corrected file exactly (Snowpipe skipped it, losing 1,638 events); masking follows the tag with one policy per data type; a per-request row filter works but the caller can set it; erasure is final 7 days after the retention, in Fail-safe; the slowest report took 7.8 s at eight analysts against 2.8 s; Terraform owned every object |
| Stage 2 and the assistant | designed; decided when each stage starts |
Data: generated to the scenario's shape from a fixed seed, so every figure can be re-run.
python scripts/build.py --check keeps every decision's evidence, the decision
tables and the cost tables identical to their sources, and CI checks every link. For a
figure measured in this repo's own results/, --check also re-derives it from the JSON
and fails if it drifts; a figure from a sibling repo is verified there, not here; a figure
still being re-measured is marked check: pending, with why. What is checked, how, is in
EVIDENCE.md.
uv sync --lockedCI's checks: pytest (cost arithmetic, generated sections, relative links),
scripts/build.py --check, cost/model.py --check, and the contracts job's
datacontract lint on every contract plus datacontract breaking against the
renamed-column fixture.
The baseline (2. Current state): Docker, two Postgres
containers, 2 vCPU and 4 GB each; load as baseline/README.md says,
then uv sync --group baseline && uv run python baseline/run.py --rate 12 --out results/baseline-brief-rate.json (about 30 minutes; --rate 100 is the stress run in
results/baseline.json).
The proof of concept (11. Proof of concept):
uv sync --group poc; DATABRICKS_HOST, DATABRICKS_TOKEN and DATABRICKS_HTTP_PATH for
a warehouse, with rights to create schemas in the workspace catalog and tag policies;
commands in the docstrings of poc/databricks/run.py (governance
and erasure), poc/databricks/workload.py (speed and cost:
load speed day, then bill a few hours later, once the billing table has the hour) and
poc/databricks/terraform.py (operability; needs OpenTofu or
Terraform).
Apache-2.0. See LICENSE.