Snowflake Internals
Why does one filter make a query 50× faster? Why is there no VACUUM? What happens when an availability zone goes down? You can answer all of these once you understand micro-partitions, the three caches and how Snowflake keeps old versions of data.
Architecture: shared-disk storage with shared-nothing compute
Classic databases are either shared-disk (all nodes read one storage system, which is simple but hits contention) or shared-nothing (each node owns a slice of data, which is fast but makes resizing a data-reshuffling project). Snowflake combines them:
One central copy of every table in object storage. Any warehouse can read any table, and resizing compute never moves data.
Inside a warehouse, each node works on its own set of micro-partitions in parallel and caches them on local SSD, like an MPP database.
Storage is a library that never closes. Warehouses are study groups. Any number of groups can borrow the same books at once, a bigger group reads faster, and when a group goes home the books stay on the shelf.
Micro-partitions: how a table is really stored
Facts to memorise
- Each micro-partition holds 50–500 MB of uncompressed data, which is much smaller once compressed.
- Columnar inside: each column is stored and compressed separately, so
SELECT a, breads only columns a and b. - Immutable: an
UPDATEorDELETEwrites new micro-partitions and marks the old ones as no longer current. - Created automatically in the order data arrives. You never declare partitions.
- Cloud Services keeps metadata per micro-partition and column: min/max values, distinct value count, null count and more.
What "pruning" means
Before any warehouse starts work, the optimizer compares your WHERE predicates against each micro-partition's min/max metadata. Any partition that cannot contain a match is skipped entirely and never read.
The Query Profile shows this as Partitions scanned vs Partitions total. Good pruning is the single biggest performance lever in Snowflake.
Pruning breaks when you wrap the filter column in a function the optimizer can't reason about, compare against a sub-query result, or when values are scattered across all partitions.
ORDERS table holds one year of data. Change how it was loaded and the date range you query. Highlighted partitions are the ones Snowflake must read. Faded ones were pruned using min/max metadata.SELECT SUM(amount) FROM orders WHERE order_date BETWEEN '2026-03-01' AND '2026-03-30';
See it in a real account
-- How well is this table organised for a date filter?
SELECT SYSTEM$CLUSTERING_INFORMATION('sales.public.orders', '(order_date)');
-- Returns JSON: total_partition_count, average_overlaps, average_depth,
-- and a histogram of partition depth. Depth near 1 = excellent pruning.
-- After running a query, check pruning in the profile or via SQL:
SELECT query_id, partitions_scanned, partitions_total, bytes_scanned
FROM TABLE(information_schema.query_history())
ORDER BY start_time DESC LIMIT 5;
How CPU and memory are used
Snowflake doesn't publish exact node hardware, and it changes over time. The model you need: each warehouse size up doubles the compute resources (CPU, memory and local SSD) and the credit rate. Inside a warehouse:
- Work is split by micro-partitionsThe partitions left after pruning are spread across the nodes and their CPU threads. More nodes means more partitions are scanned in parallel, which is why big scans speed up almost linearly with size.
- Columnar, vectorised executionOperators process batches of column values at once, which uses CPU caches efficiently. Reading fewer columns means less CPU and I/O.
- Memory holds the hard partsHash tables for joins and
GROUP BY, sort buffers forORDER BYand window functions, and data redistributed between nodes during joins. - When memory runs out, it spillsFirst to the node's local SSD (bytes spilled to local storage), then to remote object storage (bytes spilled to remote storage). Remote spilling is very slow. It is the clearest sign a query needs a bigger warehouse or a rewrite.
- Concurrent queries share the clusterQueries running at the same time on one cluster split its CPU and memory. Too many heavy ones lead to queuing or spilling, which is the signal to scale out.
The three caches
| Cache | Lives in | What it stores | Lifetime | Warehouse needed? |
|---|---|---|---|---|
| Result cache | Cloud Services | Final result sets of queries | 24 h, extended each time it's reused, up to 31 days. Invalidated if the underlying data changes. | No |
| Metadata cache | Cloud Services | Row counts, min/max, partition statistics | Always current | No (for COUNT(*), MIN, MAX) |
| Warehouse (local disk) cache | Each warehouse's SSD and memory | Raw micro-partition column data read from storage | Until the warehouse suspends or is resized | Yes |
The result cache is only reused if the query text is the same, the data hasn't changed, the query has no functions evaluated at run time such as RANDOM(), UUID_STRING() or CURRENT_TIMESTAMP() (CURRENT_DATE() is the documented exception), and the role has access. To test real performance, turn it off for your session:
ALTER SESSION SET USE_CACHED_RESULT = FALSE;
-- Find queries that spilled (ACCOUNT_USAGE, last 7 days)
SELECT query_id, warehouse_name, warehouse_size,
bytes_spilled_to_local_storage / POWER(1024,3) AS gb_local_spill,
bytes_spilled_to_remote_storage / POWER(1024,3) AS gb_remote_spill,
total_elapsed_time / 1000 AS seconds
FROM snowflake.account_usage.query_history
WHERE start_time >= DATEADD(day, -7, CURRENT_TIMESTAMP())
AND bytes_spilled_to_remote_storage > 0
ORDER BY bytes_spilled_to_remote_storage DESC
LIMIT 20;
"How do I VACUUM in Snowflake?" You don't.
In Postgres, an UPDATE leaves dead row versions inside the table file, and VACUUM reclaims them. Redshift needs VACUUM to re-sort and remove deleted rows. Snowflake never edits a micro-partition in place, so there is nothing to compact. Old versions move through a storage lifecycle and are purged automatically.
| Maintenance task elsewhere | Snowflake equivalent |
|---|---|
Postgres VACUUM / Redshift VACUUM DELETE | Automatic. Replaced micro-partitions age out through Time Travel and Fail-safe. |
Redshift VACUUM SORT / index rebuild | Automatic Clustering re-organises tables that have a clustering key, as a serverless background service. |
ANALYZE / gather statistics | Automatic. Metadata is maintained on every write. |
| Shrinking a bloated table | Lower DATA_RETENTION_TIME_IN_DAYS, use transient tables for staging, or avoid tiny frequent DML. |
A table updated every 5 minutes with MERGE rewrites micro-partitions constantly. With 90-day Time Travel, you may store far more historical bytes than active bytes. Check with:
SELECT table_catalog, table_schema, table_name,
active_bytes / POWER(1024,3) AS active_gb,
time_travel_bytes / POWER(1024,3) AS time_travel_gb,
failsafe_bytes / POWER(1024,3) AS failsafe_gb,
retained_for_clone_bytes / POWER(1024,3) AS clone_gb
FROM snowflake.account_usage.table_storage_metrics
WHERE deleted = FALSE
ORDER BY time_travel_bytes + failsafe_bytes DESC
LIMIT 20;
Backup and recovery
Snowflake has no RMAN or pg_dump. Instead you get layers of protection, each with different reach.| Layer | Protects against | Who restores | How far back |
|---|---|---|---|
| Time Travel | Bad UPDATE/DELETE, dropped table, schema or database | You, with SQL | 0–90 days (edition and table type dependent) |
| Zero-copy clone | Need for a point-in-time snapshot you keep beyond Time Travel | You | As long as you keep the clone |
| Fail-safe | Disaster after Time Travel expired | Snowflake Support only, best effort | 7 days after Time Travel (permanent tables only) |
| Replication / failover groups | Region or cloud outage | You (promote secondary) | Up to the last refresh |
| Snapshots / backup sets (newer feature) | Ransomware, accidental purge, compliance (WORM-style retention locks) | You | Per backup policy |
| Unload to your own bucket | Regulatory need for an independent copy outside Snowflake | You (re-load) | As long as you keep files |
Snapshot/backup-set features are newer than the rest of this table, and availability depends on your account and region. Confirm in the current docs before you design around them.
The recovery playbook
-- A. Someone ran DELETE without WHERE 20 minutes ago
CREATE OR REPLACE TABLE orders_restored CLONE orders AT (OFFSET => -60*25) COPY GRANTS;
-- verify, then swap atomically:
ALTER TABLE orders SWAP WITH orders_restored;
-- B. Find the exact bad statement and restore to just before it
SELECT query_id, query_text, start_time
FROM TABLE(information_schema.query_history())
WHERE query_text ILIKE 'delete from orders%' ORDER BY start_time DESC;
CREATE OR REPLACE TABLE orders_restored CLONE orders
BEFORE (STATEMENT => '01b2c3d4-0000-1234-0000-0001a2b3c4d5');
-- C. A table (or schema / database) was dropped
UNDROP TABLE orders;
UNDROP SCHEMA staging;
UNDROP DATABASE sales;
-- D. Nightly "backup" clone created by a task
-- (add a second step that drops clones older than your retention)
CREATE OR REPLACE TASK nightly_clone
WAREHOUSE = admin_wh
SCHEDULE = 'USING CRON 0 2 * * * UTC'
AS
EXECUTE IMMEDIATE $$
BEGIN
LET stmt STRING := 'CREATE DATABASE SALES_BKP_' ||
TO_CHAR(CURRENT_DATE, 'YYYYMMDD') || ' CLONE sales';
EXECUTE IMMEDIATE :stmt;
END;
$$;
ALTER TASK nightly_clone RESUME; -- tasks are created suspended
Why clone + SWAP instead of INSERT … SELECT? A clone is a metadata operation, so it is instant at any size. SWAP WITH exchanges the two tables in one atomic step, so readers never see a half-restored table. Swap moves privilege grants along with the table contents, so clone with COPY GRANTS to keep the restored table's privileges identical.
High availability and failover
- Storage: the cloud provider replicates objects across multiple availability zones.
- Cloud Services: run across several availability zones.
- Warehouses: if a node fails while a query runs, Snowflake replaces it and retries the failed work, so you usually see a slower query rather than an error.
- You configure nothing. This covers hardware and zone failures, not a whole-region outage.
- Replication group: copies databases and account objects to another account (read-only replicas). Available on all editions.
- Failover group: a replication group whose secondary can be promoted to primary. Business Critical.
- Client Redirect: one connection URL that you re-point to the new primary, so apps don't change config. Business Critical.
- RPO is set by
REPLICATION_SCHEDULE. RTO is how fast you run the promote and redirect.
-- On the PRIMARY account CREATE FAILOVER GROUP prod_fg OBJECT_TYPES = USERS, ROLES, WAREHOUSES, RESOURCE MONITORS, DATABASES, INTEGRATIONS ALLOWED_DATABASES = sales, finance ALLOWED_INTEGRATION_TYPES = STORAGE INTEGRATIONS ALLOWED_ACCOUNTS = myorg.dr_account REPLICATION_SCHEDULE = '10 MINUTE'; CREATE CONNECTION prod_conn; ALTER CONNECTION prod_conn ENABLE FAILOVER TO ACCOUNTS myorg.dr_account; -- On the SECONDARY account CREATE FAILOVER GROUP prod_fg AS REPLICA OF myorg.prod_account.prod_fg; CREATE CONNECTION prod_conn AS REPLICA OF myorg.prod_account.prod_conn; -- Disaster! On the SECONDARY account: ALTER FAILOVER GROUP prod_fg PRIMARY; -- databases become writable here ALTER CONNECTION prod_conn PRIMARY; -- apps using the connection URL follow
Remember for interviews: replication copies data and objects, but warehouses on the secondary start suspended and are billed only when used. Replication itself uses serverless compute plus data transfer, so frequent refreshes of big, churny databases cost real money. Pick the RPO the business actually needs.