Snowpipe & Snowpipe Streaming: Automated Data Ingestion in Snowflake
Learn how to automate continuous data ingestion into Snowflake using Snowpipe and Snowpipe Streaming.
20+ years shipping high-throughput database systems. Notes here come from systems that actually shipped.
- ✓Basic knowledge of SQL and Snowflake
- ✓Access to a Snowflake account with ACCOUNTADMIN privileges
- ✓Cloud storage bucket (AWS S3, Azure Blob, GCS) with appropriate permissions
- Snowpipe automates loading of data from cloud storage (S3, Azure, GCS) as soon as new files arrive.
- Snowpipe Streaming enables near-real-time ingestion via REST API without intermediate files.
- Both use Snowflake's COPY command internally but are triggered automatically.
- Key benefits: no manual loading, reduced latency, and automatic error handling.
- Setup involves creating external stage, pipe object, and optional auto-ingest via event notifications.
Imagine you have a mailbox (cloud storage) where letters (data files) arrive. Snowpipe is like a mail sorter that automatically picks up each letter and files it into the correct folder (table) as soon as it arrives. Snowpipe Streaming is like a direct phone line where you can call in data instantly without writing a letter first.
In modern data pipelines, waiting for batch loads is a bottleneck. Snowflake's Snowpipe and Snowpipe Streaming solve this by automating continuous data ingestion. Snowpipe automatically loads new files from cloud storage (AWS S3, Azure Blob, GCS) as soon as they appear, using event notifications. Snowpipe Streaming goes further, allowing you to stream rows directly via a REST API, achieving sub-second latency. This tutorial covers both approaches, from setup to production debugging, with real-world examples. You'll learn how to create external stages, define pipes, monitor ingestion, and handle common pitfalls. By the end, you'll be able to build a robust, near-real-time data ingestion pipeline into Snowflake.
What is Snowpipe?
Snowpipe is a fully managed service that automates the loading of data from cloud storage into Snowflake tables. It uses the COPY command internally but is triggered automatically when new files arrive. Snowpipe supports AWS S3, Azure Blob Storage, and Google Cloud Storage. It can be configured with event notifications (SQS, Event Grid, Pub/Sub) to detect new files, or you can call the REST API to trigger a load. Snowpipe is ideal for near-real-time ingestion with latencies typically under a minute.
Setting Up Auto-Ingest with S3 Event Notifications
To enable auto-ingest, you need to configure an S3 bucket to send event notifications to an SQS queue, and then grant Snowflake access to that queue. Steps: 1) Create an SQS queue in AWS. 2) Configure S3 bucket to send events (s3:ObjectCreated:*) to the queue. 3) Create an IAM role that Snowflake can assume to read from the queue and the bucket. 4) In Snowflake, create a storage integration and pipe with AUTO_INGEST = TRUE. The pipe will automatically start loading files as they arrive. Below is a simplified example of the SQL to create the storage integration and pipe.
Snowpipe Streaming: Real-Time Row Ingestion
Snowpipe Streaming is a newer feature that allows you to insert rows into Snowflake tables with sub-second latency using a REST API. Instead of waiting for files, you send rows directly via HTTP requests. This is ideal for streaming data from applications, IoT devices, or change data capture (CDC) systems. Snowpipe Streaming uses channels (similar to Kafka partitions) to ensure ordering and deduplication. Each channel is a sequence of rows that are committed in order. You can create multiple channels for parallelism. The client SDK (Java, Python) handles batching and retries. Below is an example using the Python SDK.
Monitoring and Managing Snowpipe
Snowflake provides several views and functions to monitor Snowpipe activity. Key views: INFORMATION_SCHEMA.COPY_HISTORY shows load history per table; SNOWPIPE_STATUS function gives current pipe state; LOAD_HISTORY shows file-level load details. You can also use ACCOUNT_USAGE views for historical data. To manage pipes, you can pause, resume, drop, or refresh them. Refreshing a pipe re-ingests files from the stage that have not been loaded yet. This is useful for recovery. Below are common monitoring queries.
Error Handling and Data Validation
Snowpipe can encounter errors like malformed files, schema mismatches, or permission issues. By default, Snowpipe skips files with errors and continues. You can configure error handling using the ON_ERROR option in the COPY command within the pipe definition. Options: CONTINUE (default), SKIP_FILE, SKIP_FILE_% (skip a percentage), ABORT_STATEMENT. For Snowpipe Streaming, errors are returned in the API response; you should implement retry logic. Use VALIDATE function to test files before loading. Below is an example of a pipe with error handling.
Performance Optimization and Best Practices
To optimize Snowpipe performance: 1) Use compressed files (gzip, snappy) to reduce transfer time. 2) Partition files by date or other keys to avoid large scans. 3) Set appropriate file sizes (100-250 MB compressed) to balance parallelism. 4) Use multiple pipes for different tables or partitions. 5) For Snowpipe Streaming, batch rows in the client (e.g., 1000 rows per request) and use multiple channels. 6) Monitor the Snowpipe ingestion queue length; if it grows, increase the number of pipes or reduce file size. Below is an example of a pipe with optimized settings.
The Midnight Ingestion Stall: When Snowpipe Missed Files
- Always monitor Snowpipe's status using SYSTEM$PIPE_STATUS.
- Set up alerts for pipes that have been idle longer than expected.
- Use file naming conventions consistently to avoid filter mismatches.
- Test event notifications end-to-end before production.
- Have a manual refresh plan for recovery.
SELECT SYSTEM$PIPE_STATUS('mydb.myschema.mypipe');SELECT * FROM TABLE(INFORMATION_SCHEMA.COPY_HISTORY(TABLE_NAME=>'mytable', START_TIME=>DATEADD(hours, -1, CURRENT_TIMESTAMP())));| File | Command / Code | Purpose |
|---|---|---|
| create_pipe.sql | CREATE OR REPLACE STAGE my_s3_stage | What is Snowpipe? |
| auto_ingest_setup.sql | CREATE OR REPLACE STORAGE INTEGRATION my_s3_int | Setting Up Auto-Ingest with S3 Event Notifications |
| streaming_insert.py | from snowflake.ingest import SimpleIngestManager | Snowpipe Streaming |
| monitor_pipes.sql | SELECT SYSTEM$PIPE_STATUS('mydb.myschema.mypipe'); | Monitoring and Managing Snowpipe |
| error_handling.sql | CREATE OR REPLACE PIPE my_pipe | Error Handling and Data Validation |
| optimized_pipe.sql | CREATE OR REPLACE PIPE my_optimized_pipe | Performance Optimization and Best Practices |
Key takeaways
Common mistakes to avoid
4 patternsForgetting to grant Snowflake access to the SQS queue
Using AUTO_INGEST without setting up event notifications
Not monitoring pipe status and copy history
Assuming Snowpipe Streaming is exactly like file-based Snowpipe
Interview Questions on This Topic
What is Snowpipe and how does it differ from manual COPY commands?
Frequently Asked Questions
20+ years shipping high-throughput database systems. Notes here come from systems that actually shipped.
That's Snowflake. Mark it forged?
3 min read · try the examples if you haven't