field note 017 · 2026-05-21 · bigquery, cost
a parity check cost $14k a month, and most of it went to looking up one number
a blockchain data-indexing company we run infrastructure for had a warehouse bill that went "through the roof" overnight. the culprit was a small hourly sanity check, and the expensive part of it asked for a single max.
the setup
the client was loading decoded on-chain events into bigquery for a large cloud provider's evaluation: polygon and ethereum, tens of terabytes, partitioned by block timestamp. a parity job on a single eval box compared our counts with the evaluator's own tables every hour, so both sides could see how far apart they were. it shipped and it worked.
early on may 15, daily bigquery spend for the project went from about $50 to about $470. nobody noticed until may 21.
the bill stepped up overnight and stayed there
daily bigquery spend for the eval project, in us dollars
we grouped the project's query jobs by the account that ran them. the top spender was the service account the parity cron runs as, and each hourly run scanned 2.83 TB on polygon plus 0.36 TB on ethereum. 24 runs a day for 30 days comes to about $14k a month for a check.
the biggest thing in the project, a 128.8 TB public dataset, cost us $0 to store: it's a subscription to someone else's data, and it had no readers. it turned up during the dig and had nothing to do with the bill.
where the bytes went
the cron did two things. one was a log query that wrote an agreement summary, and that part was cheap and fine. the other worked out how many new events had landed since the last run, and it started with max(block_number) over a time window.
that query ran against our deduplication view rather than the table underneath. the view keeps the newest copy of each event with a window function (row_number() over block, transaction, and log index, keep row 1). bigquery has to compute that window over the whole table before it can apply any partition filter, so partition pruning (skipping every day of data the query doesn't need) never happens. we dry-ran the same lookup both ways on polygon:
almost the whole run was one lookup through the view
gigabytes scanned; the two max() rows are polygon dry runs, the other two are live runs across both chains
what doesn't fix it
the textbook answer is "add a partition filter." through the view, a max with a literal timestamp filter still scanned about 2.8 TB. the filter was there, and the window function ran first anyway.
the tidy one-query version doesn't work either: find the max in a common table expression, then filter the view on block_number between it and the start. the planner prunes partitions at plan time, and it can't prune on a value the query hasn't computed yet.
the fix
we split it into two separate queries, so every filter bigquery sees is a literal.
- step one asks the raw table (no view) for
max(block_number)with a literal timestamp filter. deduplication drops copies, so it can't move the max, and this reads about 100 MB. - step two counts through the view, with both the literal timestamp filter and a literal
block_number betweenrange taken from step one. with both literals in place, pruning engages through the window function, and on polygon it reads about 1.5 GB.
then we moved the cron from every hour to once a day. it went live early on may 22, and the next live run scanned about 2 GB where it used to scan about 3,200 (about 1,500× less).
| line item | before | after |
|---|---|---|
| parity cron | ~$14k / month | ~$0.50 / month |
| eval storage, ~55 TB | ~$1,100 / month | unchanged |
| project total | ~$15-18k / month | ~$1.1k / month |
what we'd do instead
- dry-run every scheduled query against the real tables before it goes on a timer, and multiply the bytes by the schedule. 2.83 TB times 720 runs a month is a number you'd notice on a whiteboard.
- put "latest" lookups (max, min, newest block) on the raw table by default. dedup views are for counting and reading rows, and they need both literal filters when you do.
- when the bill jumps, rank query jobs by the account that ran them before ranking datasets by size. the automation was the suspect here, and the biggest dataset was free.
- alert on a day-over-day step in spend. spend went from ~$50 to ~$470 a day and sat there for six days, because it only showed up when someone opened the bill.
we'll find the query before you cut the dataset.
talk to the agent →