Worked design: cut a runaway warehouse bill
This is a "design" question about an existing system. Interviewers want a method, not a list of tips.
Cut a runaway warehouse bill
The company's cloud warehouse bill went from $40k to $150k a month in a year. Leadership wants it back under $80k within a quarter, without breaking the dashboards and models people rely on. You have read access to the warehouse's query history and billing views.
How do you find where the money goes, what do you change first, and how do you keep it from creeping back?
Hint 1
Don't optimize anything until you can attribute cost to teams, warehouses, models and queries.
Hint 2
The biggest wins are usually things that shouldn't run at all, or run far more often than anyone needs.
Show solution
Measure first: attribute spend by compute cluster or warehouse, user/role, tool, dbt model and query pattern, using the warehouse's metering and query-history views. Tag queries (query tags, labels) so cost maps to an owner. Usually a short list of things explains most of the bill.
Then fix in order of return: stop what nobody uses (dead dashboards and models, duplicate pipelines); reduce frequency to what consumers need (hourly → daily); right-size compute (auto-suspend, smaller warehouses, separate workloads, concurrency settings); make the expensive queries cheaper (incremental models instead of full rebuilds, partition/cluster pruning, no SELECT *, pre-aggregations for dashboards); and set storage retention (time travel, staging tables).
Keep it down: budgets and alerts per team, cost dashboards with owners, guardrails (statement timeouts, maximum bytes billed, resource monitors), cost checks in code review for new models, and a monthly review of the top 20 queries.
The full walkthrough is in the worked design.
What a strong answer covers
- Builds cost attribution (by warehouse, team, model, query) before changing anything (weight 3)
- Removes unused or over-frequent workloads first (biggest, cheapest wins) (weight 2)
- Right-sizes compute: auto-suspend, sizing, workload isolation (weight 2)
- Makes expensive queries cheaper: incremental models, pruning, pre-aggregation (weight 2)
- Adds guardrails and ownership so cost does not creep back (weight 2)
- Protects consumers: changes validated, stakeholders told, rollback possible (weight 1)
Follow-ups
- The finance team wants per-customer cost for your multi-tenant product. How would you allocate shared compute?
Tag queries with the tenant (query tags or labels, or per-tenant warehouses or projects), then allocate compute by each tenant's share of measured usage: credits, bytes scanned or slot time. Allocate shared jobs proportionally to rows or data per tenant, and document the method so finance trusts it.
- One team says their model "must" refresh every 5 minutes. How do you decide?
Ask what decision changes within 5 minutes and what it's worth, then show the cost of each refresh frequency. Offer alternatives such as an incremental model, a streaming table for just the few fields that need freshness, or 15–30 minutes. Agree on an SLA and a budget, and let the owner choose knowing the cost.
1. Requirements
- Goal: about −45% in one quarter ($150k → under $80k a month).
- Constraint: no broken dashboards or models. Changes must be safe and reversible.
- Unknowns to ask about: pricing model (on-demand per bytes, credits per warehouse-hour, or reserved capacity), the biggest consumers, any commitments already bought.
2. Data contracts
Consumers implicitly rely on freshness and availability. Write them down before you change anything: "Finance dashboard by 07:00 daily" is a contract; "refreshes every 5 minutes because nobody changed the default" is not.
3. Ingestion: get the cost data
Every major warehouse exposes metering and query history (for example Snowflake's account usage views, BigQuery's INFORMATION_SCHEMA.JOBS, Databricks system tables). Build a small cost model:
cost_by_query = query → warehouse/slots used × duration (or bytes billed) → $
cost_by_owner = join query tags / users / service accounts → team, dbt model, dashboard
Tag everything: dbt can set a query tag per model, BI tools use dedicated service accounts, and orchestrators label jobs. Untagged spend is the first thing to fix.
4. Storage and format: find the waste
Typical findings, roughly in order of size:
- Things nobody uses: dashboards with no viewers in 90 days, models with no downstream readers, duplicate pipelines from two teams.
- Frequency nobody needs: hourly or 5-minute refreshes for data looked at once a day.
- Idle or oversized compute: warehouses that never suspend, one big warehouse for every workload, BI tools keeping clusters warm.
- Expensive patterns: full-table rebuilds of large models,
SELECT *on wide tables, filters that defeat pruning, dashboards querying raw events. - Storage: long time-travel retention on churny tables, forgotten staging and backup copies.
5. Transform: fix in order of return
| Fix | Typical effort | Risk |
|---|---|---|
| Delete unused models and dashboards (after notifying owners) | Low | Low, with a deprecation period |
| Reduce refresh frequency to the real need | Low | Low, if the freshness contract is agreed |
| Auto-suspend, right-size, separate warehouses per workload | Low | Low |
| Incremental models instead of full rebuilds | Medium | Medium: validate against a full rebuild |
| Pruning: partition/cluster keys, fix non-sargable filters | Medium | Low |
| Pre-aggregated tables for dashboards | Medium | Low |
| Commitments / reserved capacity once usage is stable | Low | Financial, not technical |
6. Serving
Point dashboards at pre-aggregated, partitioned tables instead of raw facts, and use the BI tool's caching. Separate interactive BI compute from batch transformation, so neither slows the other down and each can be sized correctly.
7. Quality
Every optimization is a change to production logic. For incremental conversions and refactors, compare results with the old version (row counts, key metrics) before switching. Announce frequency changes to the consumers.
8. Orchestration and backfill
Schedule by consumer need: group models into "hourly", "daily" and "weekly" tiers. Only rebuild what changed (dbt's state-based selection). Avoid backfills on the expensive interactive warehouse.
9. Failure modes
| Failure | Mitigation |
|---|---|
| Removing a "dead" model breaks a hidden consumer | Deprecation period, query-log check for readers, quick restore |
| Smaller warehouse makes a critical job miss its SLA | Change one workload at a time, watch runtimes |
| Savings creep back in 3 months | Budgets, alerts, ownership, monthly review |
10. Cost: keep it down
- Guardrails: statement timeouts, maximum bytes billed per query, resource monitors or quotas per team.
- Visibility: a cost dashboard per team and per model, sent to the owners.
- Process: cost impact noted in PRs for new models; a monthly "top 20 most expensive queries" review.
11. What changes at 10×
At 10× usage, per-query optimization doesn't scale with people. The answer becomes platform-level: chargeback per team, default incremental patterns, automated detection of unused assets, and capacity commitments negotiated from real usage data.