Tutorial: Get started with Elastic Channels (SDK)¶
This tutorial walks through setting up and running a producer application using the Snowpipe Streaming SDK with an Elastic Channel. Elastic Channels are the recommended starting point for most new applications because Snowflake manages the channel lifecycle and scaling.
Use a Named Channel instead when your application requires ordered ingestion or exactly-once recovery. Exactly-once recovery requires records retained in the source or durable application-managed storage for replay.
Prerequisites¶
- Snowflake account with access to a user with sufficient privileges to create roles, databases, and tables.
- Outbound network access from your producer host to Snowflake and to the Snowflake-provided cloud storage endpoints used for SDK file uploads (AWS S3, Google Cloud Storage, or Azure Blob Storage, depending on your deployment).
- Java 11+, Python 3.9+, or Node.js 20+ depending on your chosen SDK.
- glibc version 2.26 or later on Linux.
Elastic Channels require SDK version 1.8.0 or later:
- Java: Maven Central (https://central.sonatype.com/artifact/com.snowflake/snowpipe-streaming)
- Python: PyPI (https://pypi.org/project/snowpipe-streaming/)
- Node.js: npm (https://www.npmjs.com/package/snowpipe-streaming)
Step 1: Configure Snowflake objects¶
Generate a key pair for authentication¶
Generate a private-public key pair using OpenSSL. For more information, see Key-pair authentication and key-pair rotation.
Important
Save rsa_key.p8 (private key) and rsa_key.pub (public key) securely. You will use the private key in subsequent steps.
Create database, schema, table, and configure user authentication¶
Run the following SQL commands in your Snowflake account using Snowsight or the Snowflake CLI. Replace placeholders with your own values. For required privileges, see Access control.
Note
The data column is a VARIANT type. Pass semi-structured data as a native object (Java Map, Python dict, or JavaScript object). Passing a raw JSON string stores the data as a string literal.
Step 2: Configure an authentication profile¶
Create a profile.json file in the root directory of your project.
Replace the placeholders:
MY_USER: Your Snowflake username from Step 1.your_account_identifier: Your Snowflake account identifier (for example,xy12345).rsa_key.p8: The private key file generated in Step 1.MY_ROLE: The role you created in Step 1.
Step 3: Add the SDK dependency¶
Download: Sample Java code (https://github.com/snowflakedb/snowpipe-streaming-sdk-examples/tree/main/java-example)
Add version 1.8.0 or later of the SDK to your Maven pom.xml. Check Maven Central (https://central.sonatype.com/artifact/com.snowflake/snowpipe-streaming) for the latest version.
Download: Sample Python code (https://github.com/snowflakedb/snowpipe-streaming-sdk-examples/tree/main/python-example)
The SDK requires Python 3.9 or later.
Download: Sample Node.js code (https://github.com/snowflakedb/snowpipe-streaming-sdk-examples/tree/main/nodejs-example)
The SDK requires Node.js 20 or later.
Step 4: Append rows and wait for acknowledgement¶
The following examples create a table-mode client, get the implicit Elastic Channel, and append rows using an API that returns a Future or Promise. The returned CompletableFuture (Java), Future (Python), or Promise (Node.js) completes successfully when Snowflake durably acknowledges the append. An append token is required but can be null or None. It is an identifier returned in callbacks so you can match the result to your messages; it does not prevent duplicates.
Append events as they arrive; the SDK buffers and combines appends internally using time and size thresholds. The single-row example waits immediately to demonstrate acknowledgement. In production, retain a bounded set of Futures or Promises and periodically wait for all pending appends to be durably acknowledged rather than waiting after every row or collecting rows into another batch before submitting them. See Bound outstanding acknowledgements.
The successfully completed Future or Promise indicates durable acknowledgement, not immediate table visibility. Synchronous validation, serialization, closed-client, and immediate backpressure failures are raised directly by the append call. Handle these at the call site.
Keep each event available until its acknowledgement succeeds, according to your delivery requirements. A caller wait timeout doesn’t mean the append failed; retain the original pending acknowledgement instead of immediately resubmitting. The SDK’s buffer isn’t persistent across process failure. For pausing intake, source replay, and producer-local retention options, see Protect unacknowledged data.
Step 5: Track acknowledgements with callbacks (optional)¶
As an alternative to tracking Futures or Promises, use appendRow or appendRows with registered success and error handlers. Both ways of tracking appends use the SDK’s automatic batching. Register handlers before the first append and use non-null append tokens so you can track outcomes. Limit how many appends are awaiting acknowledgement before submitting more.
Important
Keep callback bodies short. Callbacks run on the channel’s internal acknowledgement task. Delegate blocking I/O, retries, and reconciliation to your own queue or executor. A callback exception is caught and logged but does not replace checking Futures or Promises for appends that return them.
See the Java (https://github.com/snowflakedb/snowpipe-streaming-sdk-examples/tree/main/java-example), Python (https://github.com/snowflakedb/snowpipe-streaming-sdk-examples/tree/main/python-example), and Node.js (https://github.com/snowflakedb/snowpipe-streaming-sdk-examples/tree/main/nodejs-example) sample folders for producer examples. Use the checkpoint guidance and error-handling guidance when adapting them to your source and delivery requirements.
Step 6: Run the application¶
Step 7: Verify the data¶
After the application runs, allow time for Snowflake to process and materialize the data, then query the target table.
If rows are missing from the target table after a durable acknowledgement, check the error table:
For more information on error tables, see Error logging in Snowpipe Streaming with high-performance architecture.
Next steps¶
- Best practices: Automatic SDK batching, bounded acknowledgements, producer-side retention, and graceful shutdown.
- Error handling: Synchronous and asynchronous failures, retries, and duplicate handling.
- Limitations: Request size, delivery guarantees, and SDK version requirements.
- Costs: Ingestion credit usage.