Organization
Reference architecture · open source
Case span
2026
Role
Author, in the architect's role

Leaving Postgres for a managed platform: a reference architecture, measured

A common industry scenario, measured: a B2B SaaS company whose reporting has outgrown its product's Postgres, and a staged architecture with every decision tied to evidence

Stack
Architecture decision records, Open Data Contract Standard, C4 model, Mermaid, PostgreSQL 17, Logical replication, pgbench, Docker, Databricks, Unity Catalog, Snowflake, OpenTofu, dbt, Python, GitHub Actions
Links
Source · Write-up
On this page

ProblemA B2B SaaS company runs every report on its product's Postgres. The product slows down at month end, reports on the replica fail, revenue by plan disagrees with billing, history stops at 90 days, and two enterprise prospects want SOC 2 and provable erasure.

DecisionMeasure the current state on a copy of the company's database before recommending anything; move analytics to a managed platform in stages; and choose between Databricks and Snowflake by a proof of concept on criteria and weights fixed in advance. The proof of concept chose Snowflake, on a tie.

Team
One person
Scale
A company with 6,000 accounts and 350,000 events a day; a lab copy of its Postgres with 31.5 million events; 13 documents and a risk register, 18 decision records, 3 data contracts, a cost model at three points of the company's growth, a proof of concept on Databricks and Snowflake, and a change-data-capture migration rehearsed through cutover and rollback
Links
Source
  • 40 → 525 ms the product's p95 request latency, without and with the BI tool's reports running on the primary a lab copy of the company's database (Postgres 17, 2 vCPU and 4 GB, 31.5 million events); the product's request at 12 a second from pgbench, its weekday peak (each request records one event; 350,000 a day average 4 a second); two analysts running four BI queries in turn; five-minute scenarios after a checkpoint · measured Oct 2026
  • 3 of 35 runs of the long BI reports that finished on a Postgres read replica in five minutes; 32 were cancelled by recovery conflicts the same lab at the product's peak rate; reports on a streaming replica with the default max_standby_streaming_delay (30 s) and hot_standby_feedback off; analysts retried at once · measured Oct 2026
  • 23 s to move one reader from the read replica to the platform, from the decision to its first report answered, with every reconciliation check green; rolling it back took 5.8 s three reports over 90 days answered by the replica and by the platform while the product kept writing; before the switch, rows per table, events per day and invoice totals per month to the cent reconciled up to a fixed time · measured Dec 2026
  • 100 of 100 an erased user's rows still returned by Delta time travel after DELETE, after REORG APPLY (PURGE) and after VACUUM at the default retention Databricks SQL 2026.39 on Free Edition: a Delta table with deletion vectors; DELETE wrote 8 deletion vectors and rewrote 0 files; time travel refused only after the table's deleted-file retention had passed and VACUUM ran · measured Oct 2026
  • 14 of 18 architecture decisions for the company accepted, each citing its evidence, marked direct or indirect; the other four wait on the proof of concept or their stage each decision record cites figures from evidence/evidence.yml, generated into the record by scripts/build.py; figures from the repository's own results are re-derived from the results files in CI, a missing template section or a broken source link fails the build, and evidence that does not test its decision directly is labelled indirect · Oct 2026
Where the company's reports ran and what happened: on the primary the product's p95 latency went from 40 to 525 ms; on the read replica 3 of 35 long report runs finished; with hot_standby_feedback on, 11 of 11, with the primary's cleanup held back; on a replica for reports alone with a 15-minute delay, 7 of 7, up to 4.7 minutes behind Where the company's reports ran and what happened: on the primary the product's p95 latency went from 40 to 525 ms; on the read replica 3 of 35 long report runs finished; with hot_standby_feedback on, 11 of 11, with the primary's cleanup held back; on a replica for reports alone with a 15-minute delay, 7 of 7, up to 4.7 minutes behind
Measured on a lab copy of the company's database before anything was recommended. Read the analysis
A client leaving Postgres for a managed platform: what each stage does, and the decision behind it
  1. Today Postgres · replica Reports slow the product or are cancelled: 3 of 35 finished on the replica; a reports-only replica with a long delay is the stopgap (0001).
  2. Capture CDC · S3 files Every change from the log, 1.1 s at peak and none lost in a crash; one reader cut over in 23 s, rolled back in 5.8 s (0002); files immutable, loads by key (0003).
  3. Record Delta · Iceberg An open format in the client's bucket (0006); restorable for 7 days (0015).
  4. Model dbt · contracts A Type 2 star reconciled to Stripe (0007); contracts in producers' CI (0013).
  5. Govern tags · row filters Masking follows the classification tag, owned by Terraform; an erased row beyond the customer's recovery in 14 days and anyone's in 21, and one e-mail address traced through every copy (0011, 0012).
  6. Choose PoC · cost model Snowflake, on a tie under criteria fixed before the proof of concept, by the lower bill at 36 months (0005).

Context

Architecture work is judged on deliverables: a current state someone measured, a target someone can reach, decisions with the options that lost, a data model, governance an auditor can check, and a migration that does not stop the business. Most public “reference architectures” are a diagram and a list of tools. I had published one of those, and it read as an index of my labs rather than as architecture for anyone in particular.

data-platform-architecture is now a reference architecture for a common industry scenario: a B2B SaaS company with 6,000 accounts, 350,000 product events a day growing about threefold in the first year, and a data team of two. Everything the business knows about itself is read from the product’s Postgres on RDS and its one read replica. The CTO and CFO want a target architecture, a choice between Databricks and Snowflake (both have pitched), a migration that does not touch the product, and a twelve-month roadmap.

Constraints

Data: generated to the scenario’s shape from a fixed seed, the same business data-stack-lab builds, so every figure can be re-run. The company’s current state is measured on a lab copy of its database in Docker on one host, so comparisons between scenarios are the result and absolute latencies are not. The managed platforms are compared from documentation and list prices in the company’s EU region, and the choice between them is made by a proof of concept with criteria fixed in advance; both halves have run, on the smallest warehouse each offers. The migration is rehearsed on the same lab copy, with a capture process reading the same change stream a managed CDC service reads; which service is used follows from the platform choice.

The brief sets the constraints every decision answers to: two data people growing to four, no one on call for a data platform, under $15,000 a month to run, the product’s database not to be changed, a SOC 2 Type II window in month three, and erasure within 30 days everywhere a person’s data is held.

Architecture

  • Brief and current state. Stakeholders, constraints, scale today and in the growth plan. A Postgres 17 primary and streaming replica at the company’s scale (31.5 million events), the product’s own requests at a fixed rate, and two analysts running the BI tool’s queries, in five controlled scenarios at the product’s peak write rate.
  • Requirements. Fifteen quality targets written as testable scenarios, each with today’s value where it could be measured, and a ranking for when they conflict.
  • Options. Scaling Postgres, AWS-native, Databricks, Snowflake and a self-run lakehouse, scored against the requirements, with the vendor bill and the bill plus the people to run each.
  • Target, in stages. Stage 0 moves every report off the primary now; stage 1 is a managed platform fed by change data capture, with a Type 2 star schema and governance; stage 2 serves customers’ usage from a stream-fed store; stage 3 is the assistant. C4 context and container views, zones, deployment, and how each part fails.
  • Data model and contracts. Four domains with owners and data products; a conceptual and logical model with a glossary shared with the assistant’s A semantic layer defines metrics, dimensions and joins once, in governed code, and compiles every query against those definitions into SQL, so each consumer gets the same figure. Related: For text-to-SQL, the definitions mattered more than the model; layers from raw to serving; the marts, bus matrix and a history policy per attribute; physical design per engine (lakehouse marts, a ClickHouse serving store, Citus is a PostgreSQL extension that shards tables across worker nodes by a distribution column. A coordinator node plans each query and runs it on the workers in parallel. Related: Two Postgres servers that ran out of room: an application database and a vector store, moved to Citus as the product database’s growth path); modelling standards; three contracts in the Open Data Contract Standard, with CI failing on an unclassified column or a personal column in a published table.
  • Governance and compliance. An operating model with a responsibility matrix, handling rules per classification, an access lifecycle with time-boxed grants, a retention schedule, data-quality management, policy as code, and the access audit; SOC 2 readiness with a 21-control matrix and the evidence each control produces; every quality attribute with its measured figure, and disaster-recovery targets by component.
  • Security, migration, operations, roadmap. Roles and row filters, erasure; an inventory of every reader with a disposition, migration waves with a parallel run and rollback, the first reader’s cutover rehearsed; runbooks; the first 90 days and the year; a risk register.
  • Eighteen decision records, each with drivers, an options table, consequences, how reversible it is, when to revisit it, and evidence generated from measured results.

Target, in stages

Product's Postgres on RDS
  • Stage 0, the stopgap
    Replica for reports alone 15-minute replay delay
    BI reports
  • Stage 1, the managed platform
    Change data capture every change from the log
    Raw files S3, immutable
    Type 2 star schema with contracts
    Governance masking and erasure
  • Stages 2 and 3
    Stream-fed store customers' usage
    The assistant stage 3
Product's Postgres
Everything the business knows about itself is read from the product's Postgres on RDS and its one read replica.
Measured: 40 → 525 ms: the product's 95th-percentile request latency, without and with two analysts' reports running on the primary, at the product's peak rate of 12 requests a second.
Replica for reports alone
A replica for reports alone, with a 15-minute replay delay: reports need yesterday, not this minute.
Measured: All 7 reports finished and the replica fell up to 4.7 minutes behind, which no report minds.
Decision: 0001
BI reports
Stage 0 moves every report off the primary now.
Change data capture
Every change from the log, delivered to the platform's raw layer.
Measured: 1.1 s at the 95th percentile at the product's peak, against a 15-minute contract, and none of 10,579 changes lost when capture was killed mid-batch. One reader cut over in 23 s and rolled back in 5.8 s.
Decision: 0002
Raw files
Files are immutable and load by key.
Measured: The raw file kept the deleted rows' bytes through delete, checkpoint and vacuum, so the erasure job now ends by rewriting it (4.1 GB in 10 s).
Decision: 0003
Type 2 star schema
A Type 2 star reconciled to Stripe, with contracts in producers' CI.
Measured: A Type 1 dimension misplaces 15.1% of a year's revenue.
Decision: 0007, 0013
Governance
Masking follows the classification tag, owned by Terraform.
Measured: An erased row is beyond the customer's recovery in 14 days and anyone's in 21; the erasure drill on the lab copy left 0 rows holding three erased users' e-mail or name.
Decision: 0011, 0012
Stream-fed store
Stage 2 serves customers' usage from a stream-fed store; the usage page stays on the primary until then.
The assistant
Stage 3 is the assistant. It was priced and decided on Databricks, so three of its decisions are made again on Snowflake before stage 3.
Decision numbers are the architecture decision records the system flow above cites.

In the code

A contract check only means something if it is seen to fail. CI lints every contract, then runs the producer-side check against a copy of the product contract with one column renamed, and requires it to report the change as breaking:

- name: A renamed column is reported as breaking; an unchanged contract is not
  run: |
    original=models/contracts/product-database.odcs.yaml
    renamed=tests/fixtures/product-database-renamed-column.odcs.yaml
    if uvx --from "$DATACONTRACT" datacontract breaking "$original" "$renamed"; then
      echo "::error::removing users.email was not reported as breaking"
      exit 1
    fi
    uvx --from "$DATACONTRACT" datacontract breaking "$original" "$original"

A unit test keeps the fixture honest: it may differ from the real contract by the rename and the version line, and nothing else.

Decisions and trade-offs

Decision Alternative considered Why What it cost
Measure the current state before recommending Take the company’s description of it The replica’s failure was worse than, and different from, how it was described A lab harness and a day of measurement
Now: a replica for reports alone, with a 15-minute replay delay Default settings, or hot_standby_feedback Every report finished in the lab and the primary’s cleanup was not held back; reports need yesterday, not this minute The replica runs minutes behind while a long report is open; nothing the product serves reads it
A managed platform, chosen by a proof of concept Recommend one from experience At this scale the bill does not separate them; ingestion, governance and erasure do, and those can be measured Two weeks before the choice
Criteria and weights fixed before the proof of concept Score after seeing results A result cannot be argued backwards Some criteria will turn out to matter less than weighted
The AWS-native option kept as the control Compare only the two vendors that pitched The cheapest credible option keeps the comparison honest More to price
Usage page stays on the primary until stage 2 Move it in stage 1 No customer-facing path depends on the migration The primary keeps one analytical load for months

Results

Reports on the primary slowed the product. The product’s 95th-percentile request latency, without and with two analysts’ reports running on the primary: 40 → 525 ms, at the product’s peak rate of 12 requests a second. Requests over 100 ms went from 2.2% to 24.0%.

Reports on the replica were cancelled. On the read replica with default settings, 3 of 35 runs of the three long reports finished in five minutes; even the sub-second revenue report was cancelled 4 times in 12. With hot_standby_feedback on, all 11 finished, at the cost of holding back cleanup on the primary. On a replica for reports alone with the replay delay raised to 15 minutes, all 7 finished and the replica fell up to 4.7 minutes behind, which no report minds: that is the stopgap. The full account is in the write-up.

The rest of the case rests on measurements made elsewhere. 14 of 18 decisions cite measured results, among them the 15.1% of revenue a Type 1 dimension misplaces, the 1,638 events Databricks’ COPY INTO never loaded from a corrected file, and a Delta table restored after an overwrite left 1 day of 365. The four waiting on measurement say so in their status.

The Databricks half of the proof of concept is in. The company’s dbt project built on Databricks with 11, 46, 3 models, data tests and unit tests passing after one change (contract types varchar to string), and gave the published revenue figures exactly. One policy on a governed classification tag masked every personal column, including one on a table created after the policy. And an erased user’s rows were still returned by Time travel reads a table as of an earlier snapshot or version, selected by ID or timestamp. It works only while the table format still retains that version's metadata and data files., 100 of 100, after DELETE, after a purge and after VACUUM, until the table’s retention had passed: the subject of the erasure write-up. On Delta Universal Format (UniForm) writes Iceberg metadata for a Delta table alongside the Delta log. Iceberg clients can then read the table from the same Parquet files without a copy, but cannot write to it., the format the design chose, Deletion vectors store the positions of deleted rows in a side file instead of rewriting the Parquet file that holds them. The rows stay in storage until a rewrite (OPTIMIZE or REORG TABLE) produces new files and VACUUM deletes the old ones. Related: We deleted the user from the Delta table. Time travel still returned all 100 rows. are refused, so the delete rewrote all 8 files holding the user’s rows, with the same timeline. The BI reports that take a minute or more on the product’s database ran in 2.82 s at the slowest on the smallest warehouse with eight analysts at once, and nothing queued. Terraform owned 6 of 7 kinds of governance object and planned clean after applying; the mask function the policy calls has no resource and needs a SQL step between two applies. And a day’s build and reports took 38 seconds, while the billing table charged 0.743 DBU for 11 minutes awake, 95% of it waiting for auto-stop: the hours awake set the bill, not the work (the cost write-up).

The Snowflake half is in too. The same dbt project built on Snowflake with 11, 46, 3 models, data tests and unit tests passing and no change at all, and gave the published revenue figures to the cent. Loading the corrected file split Snowflake’s two loaders: COPY INTO loaded it again in full, so nothing was missing but 3,995 rows were duplicates; Snowpipe skipped it, and the 1,638 events were lost as on Databricks. Only COPY INTO followed by a MERGE on the event key was exact. One policy on the classification tag masked 3 of 3 personal string columns, but a tag holds one policy per data type, so dates and numbers need their own. A row filter keyed to a session variable worked, and a restricted role could set the variable itself and read any account: the per-request scope has to come from something the caller cannot write. Time Travel returned an erased user’s rows, 100 of 100, until the retention ran out, and a permanent table then keeps 7 days of Fail-safe that only Snowflake can read. The slowest report took 7.83 s with eight analysts, against 2.8 s on Databricks. Terraform owned 8 of 8 governance objects, the policy’s body included. And the same day’s build and reports kept the warehouse awake 70 seconds for 0.0264 credits, 10 cents: a 60-second auto-suspend against Databricks’ 10-minute auto-stop. Every criterion has now run on both platforms; scoring them against the weights fixed in advance is decision 0005’s next step.

The proof of concept chose Snowflake, narrowly. Under the scoring rule fixed before the last figure was in, Databricks scored 93.4 of 100 and Snowflake 91.8: within the 5 points the rule calls a tie, which goes to the lower bill at 36 months, Snowflake’s ($3,858 a month against $4,001). Databricks was faster (2.8 s against 7.8 s for the slowest report with eight analysts) and put an erased row beyond recovery sooner (15 days against 21); Snowflake cost less for the day’s work and let Terraform own every governance object. The deciding figure, Databricks’ day at a one-minute auto-stop, is estimated at about $0.13 from the measured day, because the free edition will not set that auto-stop; a measured day under $0.109 would reverse the result. The decision on one page states it with the conditions that would change it.

Where the model keeps personal data decides what erasure costs. On the chosen table format a row-level change rewrites every file it touches, so the model keeps e-mail and name in one identity table per source and gives facts keys. Measured: erasing one person rewrote 31,849,449 rows when the e-mail was copied into every event row, and 59,999 when it lived in one table (the write-up). The auditor’s question, who read personal data, is one query over the catalog’s tags and the platform’s lineage: 5 of 5 personal columns found with every read, in 4.7 s.

The migration path is rehearsed. On the lab copy of the company’s database, change data capture delivered each change to the platform’s raw layer in 1.1 s at the 95th percentile at the product’s peak, against a 15-minute contract, and lost none of 10,579 changes when capture was killed mid-batch. The product’s nightly purge reached the platform as 350,000 deletes and was ignored, so history outlives the product’s 90 days. A renamed column stopped that one table in quarantine 0.63 s after the first change under the new name, and the other tables kept loading. Moving one reader from the replica to the platform took 23 s from the decision to its first report, after rows per table, events per day and invoice totals to the cent had reconciled; rolling it back took 5.8 s, with the same answers as before. The reconciliation caught both errors put into it on purpose, one cent on one invoice and one missing event.

Two findings the design now accounts for. Leaving users.last_seen_at out of the change stream kept the column out, not the change: 3,060 of 3,060 updates that touched only that column still carried the user’s e-mail and name into raw. So erasure reaches raw by key, and the lasting fix, moving the column to its own table, is the product team’s to make. And losing the A replication slot records the WAL position that a standby or logical consumer has confirmed, and PostgreSQL retains all WAL after that position. An abandoned or stalled slot therefore grows pg_wal until the disk fills, unless max_slot_wal_keep_size limits it. costs history, not data: recreated, it brought every row’s current state back in 100 s, but none of the 20 versions made and replaced during a 3-minute gap. That is why the log a stopped slot holds back is alerted on long before it is at risk.

One field, followed end to end. A user’s e-mail address is traced from the product database through raw, the identity table and the marts to the assistant’s answer and its traces: for every copy, who reads it, how it is erased, whether that was measured, and who owns the risk left. The erasure drill on the lab copy left 0 rows holding three erased users’ e-mail or name. It also showed two things a row-level proof misses. The raw file kept the deleted rows’ bytes through delete, checkpoint and vacuum, so the erasure job now ends by rewriting it (4.1 GB in 10 s). And every erased address was still in the product database’s write-ahead log, on the primary and the replica, which no platform job reaches; that copy is the product team’s to cover.

The CTO review. A one-page investment recommendation asks for Snowflake Enterprise in the EU region, modelled at $962 a month today, $1,924 at 12 months and $3,858 at 36 at list price, against the $15,000 budget, with no capacity commitment until a month has been billed. It says what the money buys by month, what is already proven, how to back out at each stage, and what changes if the cost, the staffing or the residency does. The choice rests on a 3.7% difference in the 36-month bill, so it is scored again on the vendors’ quotes before anyone signs. The first 90 days after the decision have a go-or-stop point every 30 days, each with its rollback, and the first assessment scopes the consulting version: three weeks, with everything written in the client’s repository and handed over to a named owner. Writing the review turned up a gap between the two architectures: the assistant was priced and decided on Databricks, so three of its decisions are made again on Snowflake before stage 3.

The bill does not decide the platform. In the company’s EU region, at the editions its requirements need, the managed options cost about $710 to $1,000 a month today and $2,900 to $4,000 at 36 months at list price, against a $15,000 budget; a self-run lakehouse is cheap on the bill and the most expensive once the engineer it needs is counted. Per scan or per hour turns on how much an engine-hour scans: 3.1–4.4 TB against Athena at these prices (the cost write-up worked it out on the first version’s US prices).

What went wrong

The first version had no scenario. It was thirteen decisions about a generic platform, each citing a lab. Reviewed against what architecture roles and practitioners actually publish, it read as a list of things I had built. The rework starts from one company’s brief and keeps only the evidence that company’s decisions need; the first version stays in the repository’s v0.1.0 tag.

My first lab copy of the database was unrealistic. I generated events in random time order, so the last week’s rows were spread across all 5 GB and never in memory, and the product looked slow with nothing else running. A real table is appended in time order. Regenerated that way, the product’s median request took 5 ms.

I ran the baseline at 25 times the company’s rate. The first runs drove the product at 100 requests a second, each recording an event: 8.6 million events a day against the brief’s 350,000. A review caught it. At 12 a second, the brief’s peak, the findings held, and the rerun measured the stopgap the first version only described: a replica for reports alone, with a longer delay.

I priced an EU company in a US region. The cost model used AWS US East list prices, and Snowflake Standard, for a company that must stay in one EU region and needs Enterprise features. Re-priced for Ireland at the editions the requirements need, every managed option rose by about a third; the conclusion did not change.

I counted queueing twice. pgbench’s per-request time at a fixed rate already includes the wait to start; I had added the schedule lag on top. The first numbers were double the real ones.

The first runs were noisy for reasons that had nothing to do with reports. A replica restart, a checkpoint inside a scenario and Docker’s virtual disk all moved the slowest requests. Every scenario now starts after a forced checkpoint, with the replica caught up and no checkpoint due; the remaining host effects are written down, and the replica scenarios’ product latency, inflated by a shared disk that RDS does not have, is not used as evidence.

What I’d do differently

Run both halves on the deployment the company would buy. Databricks ran on its free edition and Snowflake on a trial outside the EU, so the speeds compare the two smallest warehouses, and the bills are measured usage priced at EU list, not invoices from the company’s region. The free edition also would not set the one-minute auto-stop the cost criterion needed, so the figure that decided the tie is estimated.

Rehearse on the managed capture service. The cutover and the reconciliation ran against a capture process reading the same change stream; with Snowflake chosen, Openflow or AWS DMS should be held to the same pass criteria, and the revenue-by-plan check, which needs the marts, added to the suite.

Measure the feedback setting’s cost properly. Five minutes with one-to-two-minute reports did not show the bloat hot_standby_feedback causes; an hour with hour-long reports would.

The brief, the measurements, the decisions and the checks are in data-platform-architecture.

Terms in this piece
semantic layer
A semantic layer defines metrics, dimensions and joins once, in governed code, and compiles every query against those definitions into SQL, so each consumer gets the same figure. Related: For text-to-SQL, the definitions mattered more than the model
Citus
Citus is a PostgreSQL extension that shards tables across worker nodes by a distribution column. A coordinator node plans each query and runs it on the workers in parallel. Related: Two Postgres servers that ran out of room: an application database and a vector store, moved to Citus
time travel
Time travel reads a table as of an earlier snapshot or version, selected by ID or timestamp. It works only while the table format still retains that version's metadata and data files.
UniForm
Delta Universal Format (UniForm) writes Iceberg metadata for a Delta table alongside the Delta log. Iceberg clients can then read the table from the same Parquet files without a copy, but cannot write to it.
deletion vectors
Deletion vectors store the positions of deleted rows in a side file instead of rewriting the Parquet file that holds them. The rows stay in storage until a rewrite (OPTIMIZE or REORG TABLE) produces new files and VACUUM deletes the old ones. Related: We deleted the user from the Delta table. Time travel still returned all 100 rows.
replication slot
A replication slot records the WAL position that a standby or logical consumer has confirmed, and PostgreSQL retains all WAL after that position. An abandoned or stalled slot therefore grows pg_wal until the disk fills, unless max_slot_wal_keep_size limits it.

Send a short briefing: what breaks today, or what you need to decide.