DynamoDB is an excellent database service that supports varied business-critical workloads. Being purpose-built to support modern applications that can run at any scale, many businesses including, Netflix, Dropbox, Zoom, Disney+ and more are using this service.
But it is fully managed by Amazon and that comes at a price. While DynamoDB should be designed with the best practices that keep cost in check and optimizes its performance, there are strategies to reduce the costs of existing workloads that we will be talking about today. But before we start with the strategies, we want to understand the two capacity modes that change the pricing model.
Amazon DynamoDB charges you for the number of reads/write operations in your tables and storage plus any additional optional features you may be using, such as backup and restore, data transfer, Streams, etc. So, Amazon offers two billing options, on-demand and provisioned.
DynamoDB On-Demand mode
A pay-as-you-go billing model is dependent on the read and writes your application performs. Your workload is automatically accommodated for increases or decreases in traffic and there is no need to pre-plan for the capacity. This prevents throttling, and under or over-provisioning.
If you have unpredictable traffic and you have created new tables with unknown workloads, on-demand is the best option for you.
DynamoDB Provisioned mode
If you have predictable traffic and can forecast the capacity requirements, the provisioned mode can save you a lot. You are required to separately specify the number of reads and writes per second and use auto-scaling if you require minor flexibility.
Optimizing DynamoDB usage and costs
1. Use on-demand, learn, then switch to provisioned
Although it is recommended to first start with on-demand billing, do not make the mistake of staying in this mode for a long time. Understand your traffic, peaks and demands as soon as possible and move to provisioned to optimize costs. You can use Amazon CloudWatch metrics to help you make this decision.
On-demand is a great starter and remains a great choice if your loads are very unpredictable. Suppose it’s a new project or an experimental run, you do not understand the traffic and cannot activate provisioned mode. But if that’s not the case, switching to provisioned would be one of the best ways to optimize DynamoDB costs.
2. Apply Auto Scaling to provisioned tables
Once you have made the switch to provisioned tables, you would be able to see the difference between costs. But business and demands are can have a sudden unforeseen spike above your provisioned limits. To add a little flexibility to your database, apply AWS Auto Scaling. It avoids manual capacity management as your workload changes and any unnecessary costs in case of overprovisioned tables. Pair Auto Scaling with Amazon CloudWatch, and create alarms and loops to automatically make this system flexible.
3. Tag your Tables
AWS Cost Explorer does not show the individual table costs. You have to tag them and give names to enable table-level cost analysis. For Example, if you have separate tables for teams, organizations, services or applications, tag them under suitable names to get a detailed table-level analysis.
4. Compress or use S3 for large items
Avoid storing large values or images that can increase your DynamoDB costs. The first way to resolve this issue is by compressing the files. Making them smaller will save you money. The second solution is to store the object in Amazon S3 and store its identifier in the DynamoDB table.
5. Choosing the right table for your workload
AWS offers two kinds of table classes for DynamoDB, the Standard class and the Standard-Infrequent Access class. The standard class is the default option and it is designed to balance storage and read/write costs. If you have normal usage for these tables and require them on a regular basis, then the default option is the best for you. If you want a table that is mostly going to act as an archive and will not be accessed frequently, then Standard-Infrequent Access is the best option. It offers up to 60% lower storage costs but makes up for it with 25% higher read/write costs. You should follow this guide by AWS to make the decision.
Leave A Comment