Right Sizing Snowflake Warehouses / Compute
Tags: snowflake, bigdata, cloud, compute
Published: 2021-01-07 16:27:44

Snowflake is a cloud based data warehousing platform that can handle huge workloads at scale. But figuring out how much it will cost you can be tricky. 

Storage is pretty straight forward to calculate, it's $40 a month per TB (you can reserve space at a cheaper rate of $23 / TB if you know how much you need up front). 

It's much harder to figure out how many compute credits you'll use in a month. Most companies will pay $2 to $4 per credit, but what does that really mean? 

Credits are used by Snowflake compute warehouses. In order to run queries or ingest data you'll need at least one warehouse running. The size of the warehouse has a direct impact on how many credits an hour it will cost. 

<table>
<thead>
<tr class="row-odd"><th class="head"><p>Warehouse Size</p></th>
<th class="head"><p>Servers&nbsp;/&nbsp;Cluster</p></th>
<th class="head"><p>Credits&nbsp;/&nbsp;Second</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>X-Small</p></td>
<td><p>1</p></td>
<td><p>0.0003</p></td>
</tr>
<tr class="row-odd"><td><p>Small</p></td>
<td><p>2</p></td>
<td><p>0.0006</p></td>
</tr>
<tr class="row-even"><td><p>Medium</p></td>
<td><p>4</p></td>
<td><p>0.0011</p></td>
</tr>
<tr class="row-odd"><td><p>Large</p></td>
<td><p>8</p></td>
<td><p>0.0022</p></td>
</tr>
<tr class="row-even"><td><p>X-Large</p></td>
<td><p>16</p></td>
<td><p>0.0044</p></td>
</tr>
<tr class="row-odd"><td><p>2X-Large</p></td>
<td><p>32</p></td>
<td><p>0.0089</p></td>
</tr>
<tr class="row-even"><td><p>3X-Large</p></td>
<td><p>64</p></td>
<td><p>0.0178</p></td>
</tr>
<tr class="row-odd"><td><p>4X-Large</p></td>
<td><p>128</p></td>
<td><p>0.0356</p></td>
</tr>
</tbody>
</table>
_costs as of 1/7/2021. See [Snowflake Warehouse Documentation] (https://docs.snowflake.com/en/user-guide/warehouses-overview.html) for additional info._

Let's dig into these numbers. To run a Small warehouse it costs 2 credits an hour, at $3 a credit, that's $6 an hour. $144 a day, $52.560 a year.. 


## Right Sizing Warehouses

A couple of quick tips:
- Turn on Auto-suspension and Auto-resumption! This turns your warehouses off when not in use and can save you big bucks. 
- Warehouses don't cost anything if they are off. Don't be afraid to define a bunch of them, just make sure they are off when not needed. 
- Spinning up a warehouse costs a minimum of 1 minute and is billed by the second after the first minute. 
- There is a small lag to spin up a suspended warehouse.

### Oversized Warehouses

Let's say we have a Large warehouse set to auto suspend after 30 seconds and we run a query that only takes a few seconds. We would be billed a full minute for this query. 

In this scenario we might want to look at using an X-Small instead. Even if the query took a few seconds longer on the X-Small we'd save credits if the query still finishes under a minute. 

1 minute on a Large = 0.132 Credits, X-Small = 0.018, Saving 0.114 credits, That's $0.342 at $3 a credit! 

This is where people start to think, we should run X-Small warehouses to save money, but that might actually cost you more!

### Undersized Warehouses

Now let say we have a long running query. In a real world scenario, I built an aggregation that queries tables with 17 billions rows (about 466GB of data). 

On a Large warehouse this query took 1 hour and 44 minutes, which cost 13.9 credits; $41.70 @ $3 a credit per run. 

Moving this query to a 4XL finished in just under 6 minutes! Keep in mind 6 mins on a 4XL still cost $36.60 for 12.2 credits, but running on the bigger warehouse actually saved 1.7 credits; That's $5.10 in savings! 

We run this aggregation every day, in one year we'll save over $1,800 on this one query alone. 

## Conclusion

Picking the right size warehouse can be tricky! Test heavy queries on large warehouses and move fast queries down to smaller warehouses.