How do you optimize a data warehouse for billions of rows?
Tests physical design in columnar warehouses at scale. Strong answers cover partition and cluster pruning, materialized views or rollups to reduce joins, caching and search indexes for hot paths, and reserved slots or autoscaling.
What's really being asked
Whether you understand that cloud data warehouses bill for scanned bytes and compute time, not just storage, and that query performance at the billion-row tier is driven by physical layout rather than SQL tuning alone. Interviewers want to see you reason about partition pruning, clustering, pre-aggregation, caching layers, and workload management as a coordinated system instead of isolated knobs.
The full answer
Four distinct layers in order. First, schema optimization: partition tables by date or event time so dashboards only scan relevant shards, and cluster by high-cardinality filter columns like user_id or event_type to co-locate similar rows and reduce bytes read. Second, pre-aggregation: build materialized views or scheduled rollups that collapse billions of raw events into daily or hourly aggregates, eliminating joins and window functions at query time. Third, acceleration: leverage result caching for repeated dashboard queries, use BI Engine or an in-memory acceleration layer for sub-second slices, and add search indexes on text-heavy filter fields if the platform supports it. Fourth, cost governance: move from on-demand to reserved capacity or slot-based billing when query volume is steady, use autoscaling for bursty BI workloads, and enforce query timeout limits or maximum bytes billed to prevent runaway scans.
The mistakes people make
Proposing to add more warehouse nodes or increase instance size without changing table design, which linearly increases cost. Suggesting indexes in the traditional OLTP sense, which most columnar warehouses do not use for raw event tables. Recommending caching alone as the primary fix, which ignores data layout and still incurs full scan costs on cache misses. Proposing to shard into hundreds of tiny tables manually, which breaks partition pruning and complicates querying.
What usually comes next
How would you choose between partitioning by ingestion time versus event time when backfills are common? When would a materialized view hurt performance or freshness? How do you handle a dashboard that needs both real-time and historical data in the same chart? What monitoring signals tell you whether to cluster a column or leave it unclustered?
A concrete example
A BigQuery events table with twelve billion rows per month and a dashboard filtering on event_type and date. Partition by _PARTITIONDATE and cluster on event_type and user_id. Create a materialized view grouped by date and event_type that refreshes every hour. The dashboard queries the materialized view instead of the raw table, scanning under fifty megabytes instead of multiple terabytes. Enable BI Engine cache for the top ten dashboard tiles. Switch the project to flat-rate reservations with baseline slots and autoscaling max to cap spend during traffic spikes.
Interview question
A BigQuery table holds 12 billion monthly rows. Dashboards filtering by date and event_type scan terabytes. Which strategy most effectively reduces bytes scanned while keeping hourly freshness?
- a.Shard the table into hundreds of daily tables and enable BI Engine acceleration for all dashboard tiles.
- b.Switch to flat-rate slot reservations and enforce maximum bytes billed per query.
- c.Increase the warehouse instance size and enable query result caching for all dashboard queries.
- d.Partition by date, cluster by event_type and user_id, and route dashboards to an hourly materialized view.Correct
Why? this is the answer
Partitioning and clustering prune the data to relevant shards, while an hourly materialized view collapses billions of rows into megabytes, directly reducing bytes read. Option C is tempting because caching speeds up repeated queries, but cache misses still incur full terabyte scans and larger instances do not reduce bytes billed.
Just read this? Test yourself on what you have been reading.
Read the original → docs.cloud.google.com
- #data-warehouse
- #bigquery
- #snowflake
- #query-optimization
- #cost-control
Put your scrolling time to good use
Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Every open role lists the topics its interview covers, so you can prepare for the real thing rather than guessing.
See open roles