3. Snowflake Architecture & Virtual Warehouses
Snowflake's Multi-Layered Architecture
Snowflake is architected as a unique multi-cluster shared-data platform that separates storage from compute. The storage layer uses Amazon S3, Google Cloud Storage, or Azure Blob Storage to maintain data in a proprietary, compressed, columnar format. This decoupling ensures that storage costs are decoupled from compute, allowing you to scale up or down based on activity.
The Cloud Services layer acts as the brain of the platform. It handles authentication, security, metadata management, query parsing, and optimization. This layer is entirely managed by Snowflake and ensures that ACID compliance is maintained across all operations. The Query Processing layer consists of Virtual Warehouses, which are individual compute clusters that execute DML and DDL commands, operating independently to prevent resource contention.
-- Check virtual warehouse status SELECT warehouse_name, state, size, auto_suspend FROM SNOWFLAKE.ACCOUNT_USAGE.WAREHOUSES;
Virtual Warehouses: Compute and Scaling
Virtual Warehouses are the compute engines of Snowflake. They provide the resources needed for querying and loading data. You can scale these vertically (increasing the size like X-Small to 4X-Large) to decrease execution time for complex, compute-intensive queries. This follows the $Time = rac{Workload}{Resources}$ principle where doubling the resources can theoretically halve the execution time for large data scans.
Horizontal scaling is achieved via multi-cluster warehouses, which automatically add clusters to handle increasing concurrency. With the Auto-suspend and Auto-resume features, you can minimize costs by ensuring warehouses shut down during periods of inactivity and wake up instantly when a new query arrives.
-- Creating a multi-cluster warehouse with auto-scaling CREATE WAREHOUSE COMPUTE_WH WITH WAREHOUSE_SIZE = 'SMALL' AUTO_SUSPEND = 60 AUTO_RESUME = TRUE MIN_CLUSTER_COUNT = 1 MAX_CLUSTER_COUNT = 3 SCALING_POLICY = 'ECONOMY';
Advanced Storage Features: Cloning and Data Protection
Snowflake's metadata-based storage allows for Zero-Copy Cloning. When you clone a database or table, Snowflake simply creates new metadata pointers to the existing micro-partitions without duplicating the actual data. This makes cloning instantaneous and cost-effective, ideal for creating dev/test environments from production snapshots.
Time Travel and Fail-safe ensure robust data protection. Time Travel allows users to query data as it existed at any point within a defined retention period (up to 90 days for Enterprise editions). Fail-safe is a non-configurable, seven-day period that follows Time Travel, specifically for disaster recovery and data restoration managed by Snowflake support.
-- Create a clone of a production table for experimentation CREATE TABLE SALES_DEV CLONE SALES_PROD; -- Query data as it was 1 hour ago SELECT * FROM SALES_PROD AT(OFFSET => -3600);
Knowledge Check
Ready to test your understanding of 3. Snowflake Architecture & Virtual Warehouses?