connectionsnowflake-cloud-data-platformcloud-storagecost-management

Do Idle Snowflake Connections Use Cloud Services Credits?


Motivation | Suppose one wanted to execute two SQL queries against a Snowflake DB, ~20 minutes apart.

Optimization Problem | Which would cost fewer cloud services credits:

  1. Re-using one connection, and allowing that connection to idle in the interim.
  2. Connecting once per query.

The documentation indicates that authentication incurs cloud services credit usage, but does not indicate whether idle connections incur credit usage.

Question | Does anyone know whether idle connections incur cloud services credit usage?


Solution

  • Snowflake connections are stateless. They do not occupy a resource, and they do not need to keep the TCP/IP connection alive like other database connections.

    Therefore idle connections do not consume any the Cloud Services Layer credits unless you enable "CLIENT_SESSION_KEEP_ALIVE".

    https://docs.snowflake.com/en/sql-reference/parameters.html#client-session-keep-alive

    When you set CLIENT_SESSION_KEEP_ALIVE, the client will update the token for the session (default value is 1 hour).

    https://docs.snowflake.com/en/sql-reference/parameters.html#client-session-keep-alive-heartbeat-frequency

    As Peter mentioned, the CSL usage up to 10% of daily warehouse usage is free, so refreshing the tokens will not cost you anything in practice.

    About your approaches: I do not know how many queries you are planning to run daily, but creating a new connection for each query can be a performance killer. For costs perspective, idle connection will do max 24 authorization requests on a day, so if you are planning to run more than 24 queries on a day, I suggest you to pick the first approach.