🐾DynamoDB: how to choose right capacity🐾
🤓 While working with clients, I noticed that many of them tend to use DynamoDB provisioned capacity. Their motivation is to pay less, because they afraid of spikes and uncontrolled scaling events. It’s sounds fair as provisioned capacity sets a cap on how much capacity units (CU) you will use, and therefore it sets a cap on your bill. But the reality is that for most cases you will spend much more with provisioned mode. Let’s dive deeper into DynamoDB capacity modes and pricing.
Capacity types
DynamoDB has two provisioning modes:
on-demand
provisioned
With on-demand mode, you pay as you go and DynamoDB will serve as many write and read requests as your application send to it. You can optionally configure maximum read or write (or both) throughput for individual on-demand tables. You can learn more about initial throughput in documentation.
With provisioned mode, you pay for the provision of read and write capacity units for your DynamoDB tables. You can configure autoscaling which modifies provisioned throughput when the table load stays increased or decreased for several minutes.
If your application experiences a sudden spike in traffic, DynamoDB's on-demand capacity can become more expensive compared to provisioned one. However, with provisioned capacity, there's a risk of throttling your users. On-demand capacity ensures a smooth user experience without disruptions, but it may lead to unexpected costs.
In the next sections, I will explain more about when to choose which capacity type, but as always I created a cheat-sheet with decision tree😉
When to use on-demand capacity
On-demand capacity mode is a good choice when your traffic is:
Unpredictable or unknown
Periodically idle
Has frequent and extreme spikes
Possible use cases for on-demand mode are:
Your DynamoDB table is provisioned in dev or test environment and therefore has idle periods.
DynamoDB is used as Terraform state lock or any other configuration which is accessed less frequently than every second.
You are running new applications in production and cannot estimate potential load.
Your application usage is rapidly increasing over time.
Your application has frequent and swift or rare but swift spike in usage.
You prefer to pay as you go and don’t want to estimate patterns.
When to use provisioned capacity
Provisioned capacity mode is a good choice when your traffic:
Has predictable pattern
Spikes are small and rare
Ramps are incremental
Possible use cases for provisioned mode are:
Your application is equally accessed over the day, and has low traffic over night.
Load on your application is increasing and decreasing gradually without sudden spikes.
Your traffic is stable with small and rare spikes or cyclical.
You tolerate throttling and application has retry mechanism implemented.
💝Do not forget about reserved capacity
If you are using provisioned capacity and has stable load, you can reserve certain amount of capacity to lower your cost. Reserved capacity can only be used with DynamoDB Standard table class and can save you up to 77% depending on you region.
Thank you for reading, let’s chat 💬
💬 Which one do you use: on-demand or provisioned mode?
💬 Why did you choose the mode you currently use?
💬 Do you consider to switch after reading this post?
I love hearing from readers 🫶🏻 Please feel free to drop comments, questions, and opinions below👇🏻