Snowflake Architecture: A Deep Dive for Developers
Learn Snowflake's unique architecture: storage, compute, cloud services.
20+ years shipping high-throughput database systems. Drawn from code that ran under real load.
- ✓Basic understanding of SQL (SELECT, INSERT, CREATE TABLE).
- ✓Familiarity with cloud concepts (AWS, Azure, GCP).
- ✓No prior Snowflake experience required.
Snowflake separates storage and compute, allowing independent scaling. It uses a columnar, compressed format and offers features like cloning, time travel, and zero-copy cloning. Virtual warehouses handle compute, and cloud services manage metadata and queries.
Think of Snowflake like a library with separate reading rooms. The books (data) are stored in a central archive (cloud storage). You can have multiple reading rooms (virtual warehouses) where people read books without disturbing each other. You can also make instant copies of any book (zero-copy cloning) without using extra paper.
Snowflake is a cloud-native data warehouse that revolutionized how organizations store, process, and analyze data. Unlike traditional databases, Snowflake's architecture is built for the cloud from the ground up, separating storage and compute to enable elastic scaling, concurrency, and near-zero maintenance. For developers coming from traditional SQL databases, understanding Snowflake's architecture is crucial to leveraging its full potential. In this tutorial, we'll explore the three layers of Snowflake: storage, compute, and cloud services. We'll dive into virtual warehouses, data sharing, cloning, time travel, and best practices. By the end, you'll be able to design efficient Snowflake solutions and avoid common pitfalls.
1. Overview of Snowflake Architecture
Snowflake's architecture is a hybrid of shared-disk and shared-nothing models, but it's best described as a multi-cluster shared-data architecture. It consists of three layers: Database Storage, Compute (Virtual Warehouses), and Cloud Services. The storage layer stores all data in a compressed, columnar format in cloud blob storage (AWS S3, Azure Blob, GCP Cloud Storage). The compute layer consists of virtual warehouses that process queries. The cloud services layer handles authentication, metadata, query optimization, and security. This separation allows independent scaling: you can scale storage without affecting compute and vice versa. Data is automatically partitioned into micro-partitions, which are small, immutable files that enable efficient pruning and parallel processing.
2. Database Storage Layer
The storage layer is where Snowflake stores all table data and query results. Data is automatically compressed, columnar, and partitioned into micro-partitions. Each micro-partition contains between 50 MB and 500 MB of uncompressed data. Snowflake automatically manages clustering, but you can define clustering keys to improve pruning for large tables. Data is encrypted at rest and in transit. The storage layer also handles time travel and fail-safe, which allow you to query historical data and recover dropped objects. Time travel retains data for 1 day by default (up to 90 days with Enterprise edition). Fail-safe provides an additional 7 days of recovery by Snowflake support.
3. Compute Layer: Virtual Warehouses
Virtual warehouses are the compute resources that execute queries. They are essentially clusters of compute nodes (servers) that can be scaled up (larger size) or scaled out (more clusters). Each warehouse can be set to auto-suspend and auto-resume to save credits. You can create multiple warehouses for different workloads (e.g., ETL, BI, data science). Warehouses can be set to 'Standard' (single cluster) or 'Multi-cluster' (up to 10 clusters) for high concurrency. When you execute a query, Snowflake assigns it to a warehouse. The warehouse caches data in memory and SSD to speed up subsequent queries. You can also set resource monitors to limit credit consumption.
4. Cloud Services Layer
The cloud services layer is the brain of Snowflake. It handles authentication, session management, metadata storage, query parsing and optimization, and security. This layer is stateless and scales automatically. It also manages the data sharing and cloning features. When you run a query, the cloud services layer parses it, optimizes it, and generates an execution plan. It then coordinates the virtual warehouse to execute the plan. Metadata about tables, views, and schemas is stored here. The cloud services layer also manages the information schema and account usage views that provide insights into query history, warehouse usage, and more.
5. Zero-Copy Cloning and Data Sharing
Zero-copy cloning allows you to create a copy of a database, schema, or table instantly without duplicating the underlying data. The clone initially shares the same storage as the source, and only new changes are stored separately. This is incredibly useful for creating development environments, running tests, or taking snapshots. Data sharing allows you to share data with other Snowflake accounts without copying it. You create a share and add objects to it, then the consumer can access the data using their own compute. This is a powerful feature for data collaboration.
6. Best Practices and Performance Optimization
To get the most out of Snowflake, follow these best practices: 1) Choose the right warehouse size and scaling policy. Start with X-Small for development and scale up as needed. 2) Use clustering keys for large tables (over 1 TB) to improve prune efficiency. 3) Leverage materialized views for pre-aggregated data. 4) Use result caching: Snowflake caches query results for 24 hours if the underlying data hasn't changed. 5) Optimize joins by ensuring join keys are of the same data type. 6) Avoid using SELECT * in production; only select needed columns. 7) Use automatic clustering for tables that are frequently queried. 8) Set up resource monitors to control costs. 9) Use time travel wisely; longer retention costs more storage. 10) Monitor query performance using the QUERY_HISTORY view and set up alerts for long-running queries.
7. Security and Access Control
Snowflake provides robust security features including role-based access control (RBAC), network policies, encryption at rest and in transit, and multi-factor authentication (MFA). You can create roles and grant privileges to databases, schemas, tables, and warehouses. Use the ACCOUNTADMIN role for administrative tasks, and create custom roles for different teams. Network policies allow you to restrict access to specific IP ranges. Snowflake also supports OAuth and SAML for single sign-on. Data masking and row-level security can be implemented using secure views and dynamic data masking.
The Midnight Query Storm: When Virtual Warehouses Collide
- Always test scaling policies under realistic load.
- Use multi-cluster warehouses for unpredictable workloads.
- Set resource monitors to avoid runaway costs.
- Monitor query history and warehouse load using Snowflake's information schema.
- Consider using separate warehouses for different workloads (e.g., ETL vs. BI).
SHOW WAREHOUSES;SELECT * FROM INFORMATION_SCHEMA.QUERY_HISTORY WHERE WAREHOUSE_NAME = 'MY_WH' ORDER BY START_TIME DESC LIMIT 10;| File | Command / Code | Purpose |
|---|---|---|
| architecture_overview.sql | SHOW WAREHOUSES; | 1. Overview of Snowflake Architecture |
| storage_example.sql | CREATE OR REPLACE TABLE orders ( | 2. Database Storage Layer |
| warehouse_management.sql | CREATE WAREHOUSE my_wh WITH | 3. Compute Layer |
| cloud_services_queries.sql | SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'PUBLIC'; | 4. Cloud Services Layer |
| cloning_and_sharing.sql | CREATE OR REPLACE TABLE orders_clone CLONE orders; | 5. Zero-Copy Cloning and Data Sharing |
| optimization_examples.sql | CREATE OR REPLACE TABLE large_orders ( | 6. Best Practices and Performance Optimization |
| security_examples.sql | CREATE ROLE analyst; | 7. Security and Access Control |
Key takeaways
Common mistakes to avoid
3 patternsUsing SELECT * in production queries
Not setting auto-suspend on warehouses
Ignoring clustering for large tables
Interview Questions on This Topic
Explain the three layers of Snowflake architecture.
Frequently Asked Questions
20+ years shipping high-throughput database systems. Drawn from code that ran under real load.
That's NoSQL. Mark it forged?
3 min read · try the examples if you haven't