← Questions
Design a cache for query views that depend on each other
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in Snowflake's system design round, last asked Sep 2025. It tests caching, dags and invalidation.
An analytics system keeps materialized query views, and each view is defined on base tables and on other views, so the views form a DAG. Design a caching strategy that cuts query latency over these views while keeping results correct when base data changes.
Requirements
- Functional: serve queries over views from cache when possible; when a base table changes, refresh or invalidate every dependent view; support backfills of historical data.
- Non-functional: low query latency, explicit freshness SLAs per view, bounded memory and storage, correctness under concurrent refreshes and reads.
Clarifying questions
- How often do base tables change, and in what form (appends, updates, full reloads)?
- How deep and wide is the DAG, and are some views read far more than others?
- What freshness does each consumer need: always current, or within minutes?
- Are aggregates incrementally maintainable (sums, counts) or not (distinct counts, medians)?
- Is the system on one cluster or many nodes with a shared cache?
What a strong answer covers
- What to cache and at which granularity: whole view results, partial aggregates per partition, or base-table scans; and where: in memory, local disk, a distributed cache.
- Cache keys built from the view definition plus the versions of its inputs (a version vector or snapshot id), so a stale entry can never be served by mistake.
- Update propagation in topological order along the DAG, incremental refresh versus full recomputation and when each is chosen, and coalescing many base changes into one refresh.
- Consistency: readers see one snapshot across views that share inputs; refreshes publish new versions atomically.
- Eviction weighted by recompute cost, size and access frequency, not plain LRU; hot views pinned.
- Partial failures (a refresh dies halfway), backfills that touch old partitions, and monitoring of freshness lag, hit rate and correctness (sampled recomputation).
Follow-ups
- A base table near the root of the DAG changes every minute. How do you avoid recomputing everything?
- Two views refresh concurrently and a query joins both: how does it get a consistent pair?
- A backfill rewrites a year of data. What happens to the cache?
Where it's asked
- Snowflake · System design · Last asked Sep 202560 min · Design discussion
What it tests
caching · dags · invalidation · databases
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing
