Skip to content

← All work

CS-08 · 2026 · ongoing

An atomic nightly warehouse for my finance app

A nightly ELT warehouse behind Mizan: atomic runs that finish or never happened, dbt models in DuckDB shaped around domains, and a data contract.

My role
Product owner and architect; built with Claude Code
When
2026 · ongoing
Status
Runs nightly · being extended
242Measured
dbt steps on every build
62 models, 172 data tests, 6 unit tests and 2 seeds, all passing
154Measured
Python tests
Including those that compare the warehouse with the app figure for figure
7Measured
Published versions kept
Rolling back is one pointer swap
How the warehouse is put together
  1. Nightly snapshotThe ledger and Mizan’s own files, contract columns only, as dated Parquet
  2. StagingRenamed, typed, deleted rows dropped
  3. CoreConformed dimensions and facts: date, month, account, category
  4. DomainsSpending, income, budget, wealth, ledger
  5. Dashboards and assistantNext: Grafana, and a local LLM that answers only from the domains

Each night the ledger and Mizan's own files are copied, contract columns only, into a dated snapshot that is never edited. dbt shapes the newest night into staging views, a shared core of dimensions and facts, and one schema per domain. Dashboards and a local assistant are next, and will read only the domains.

Proof: a real nightly run in Airflow 3
Airflow 3 graph view of the nightly run. take_snapshot, check_snapshot, fresh_build, the dbt task group (shown with 58 more tasks inside) and publish each show success. record_failure, which runs only if a step fails, shows skipped.

A screenshot from the Airflow UI, not a mock-up, on invented data. Left to right: copy the ledger, verify the copy, start from an empty build, build every dbt model as its own task with its tests (the group holds 58 more), then check and swap in. record_failure runs only if a step fails, so here it was skipped.

Scope note. A personal system built to a professional standard. Everything shown here uses an invented household; my real ledger never leaves my home server.

The problem

Mizan, my finance app, works everything out fresh each time. It can’t answer history questions: what changed since last night, or how this month compares with last year once rules have changed. Those need a warehouse. I also wanted one clean enough that an AI assistant could answer from it without making anything up.

What it is

A pipeline that runs every morning after the bank import:

  1. Copy. The ledger is copied into a dated folder of Parquet files. A night is written whole or not at all, and never edited, so comparing two nights shows exactly what changed.
  2. Model. dbt on DuckDB cleans the data, pairs transfers between my own accounts, and builds a shared core (dates, accounts, categories) with one schema per question area: spending, income, budget, wealth and ledger.
  3. Publish. The new version goes live only if it checks out.

Only what’s allowed gets copied

A written contract lists every column the warehouse may copy. Notes, tags and bank account numbers are never on it. It’s enforced three times: by the database login (it can only read those columns), by a view, and by a check before any file is written. A CI test runs a real PostgreSQL 16 database with notes and account numbers in it, and passes only if the export can’t reach them.1

All or nothing, like a bank

A transfer either completes or never happened. Each night works the same way:

  • A night that doesn’t add up (wrong time zone, balances that don’t match the ledger) is refused whole, never loaded in part.
  • Each build starts from empty, is checked against the ledger before going live, and goes live with one atomic swap.
  • The last 7 versions are kept, so rolling back is one more swap.

Checked against the app, figure for figure

Tests only catch the mistakes you thought of. So a parity check runs Mizan’s own code on the same data and compares every figure. A one-cent change fails it, and CI proves that by planting such changes.2

It found a real bug the warehouse’s own tests had passed: the two systems paired transfers differently, and on 4,000 invented test ledgers they disagreed 2,192 times.3 The warehouse now uses Mizan’s exact rule. The same check made a big refactor safe: old and new layouts matched row for row.4

There’s also a reference household: an invented year, every month worked out by hand. Every build has to reproduce that table to the cent, cell by cell.5

Running it

Airflow 3 runs the nightly job, with each dbt model as its own task, so a failure names the model that broke (the screenshot above is a real run).6 CI runs on every push: the unit tests, the full dbt build on fresh invented data,7 and the database permission test.

It can also read a bank statement’s text into its period, its opening and closing balances, and its lines.8

My role

I was the product owner and architect. I decided what the warehouse is for, what it may copy and when it must refuse, and I reviewed and tested what was built. The code was written with Claude Code, under those rules.

What’s not done

  • Dashboards reading the published data.
  • Access by domain, so a dashboard or assistant can use only approved tables.
  • An assistant that answers only through the semantic layer’s 29 vetted metrics. That’s now Mizan AI.

What this shows

All-or-nothing pipeline design, dbt modeling, data contracts enforced in the database rather than in a document, testing against a second source of truth, and least-privilege access to sensitive data.

Footnotes

  1. Test · tests/test_export.py in the warehouse repository starts a real PostgreSQL 16 in CI with notes, account numbers and an IBAN column, then checks the read-only role is refused all three. CI sets REQUIRE_DOCKER=1, so the test fails rather than skips if the database can’t start. ↩

  2. CI run · make mutation (commits 820998c and 2c5c43c): each mutation changes one value by a cent or drops a row, in the raw nights or the built marts, and the run fails if any goes unnoticed. 23 of 23 caught. Unmutated controls run first, so a catch can’t come from a check that always fails. ↩

  3. Commit · f48672d, “Match Mizan figure for figure”: on 4,000 random ledgers, invented to stress transfer matching, the old rule disagreed with Mizan’s 2,192 times. Since then the port is checked against Mizan’s own code on those ledgers. ↩

  4. Commit · 785f77a, “Domain marts on conformed dimensions”: old and new layouts built from the same invented nights compared table by table, for histories starting on the 1st and mid-month. ↩

  5. Test · tests/test_reference_household.py (warehouse v1.5.0, commit 919d43e, run by make test on 2026-11-24): the warehouse is built from the hand-worked ledger and every cell of its table must match. The table’s checksum is pinned in both repositories, so neither copy can change alone. ↩

  6. Screenshot · the Airflow 3 graph view at the top of this page: a full nightly run on invented data, every step successful, record_failure skipped. ↩

  7. Test run · dbt build on the invented household (warehouse v1.5.0, commit 919d43e): 242 steps (62 models, 172 data tests, 6 unit tests and 2 seeds), all passing; make test runs 154 Python tests. The repository is private for now, so these receipts name the commit and file to check. Warehouse figures measured on 2026-11-24. ↩

  8. Test · tests/test_statement.py (warehouse v1.5.0, commit 919d43e): invented statements read into period, balances and lines; all read right by make test on 2026-11-24. ↩