- The Cloud Economist
- Posts
- 5 Strategies I Use To Save Big On DynamoDB Costs
5 Strategies I Use To Save Big On DynamoDB Costs
5 proven strategies that have help me and will help you potentially save thousands of dollars a month.
Have you stopped using DynamoDB or heard of someone doing so because of its high costs?
This is a story I’ve heard more than once or twice.
Just last week, I was chatting with a LinkedIn connection who was telling me about his company’s decision to migrate some of its database off of DynamoDB.
The sole reason?
High costs.
But he admitted to me that the company (or the database developers ) wasn’t well acquainted with how to optimize for costs nor how to design tables with costs in mind.
This led me to believe many companies out there as well are building databases unaware of how to optimize them for costs.
In an effort to help those struggling with costs in DynamoDB, I layout 5 strategies you can use right now to save big on your monthly database costs.
1. Well-Designed Queries & Data models
In DynamoDB, everything balances on how well designed your data model is.
It will break or make your entire table, its performance, scalability and especially costs.
Avoiding Scans contribute enormously to cost savings.
Avoiding Filter Expressions also reduces costs when filtering. But how do you filter without them?
Use hierarchical structured sort keys. You can do everything you need with the begins_with() and BETWEEN query methods.
Just stop using Scans, they will drive up your costs really high.
Learn the single table design and how to overload sort keys - that’s a great way to reduce costs as well.
2. Setting TTLs on temporary data
Oftentimes you will have to store temporary data in your DynamoDB tables.
These can be any of the following:
temporary access codes
log data
user session data
expirable tokens
old notifications
Any data that is not needed after x amount of years
Storing this data in DynamoDB can quickly become costly, especially at scale.
The problem is, that identifying and deleting this data will ironically end up costing you as well (to query/scan for it).
However, by using DynamoDB’s TTL feature — time to live — the data will automatically be deleted by DynamoDB without incurring any costs at all.
TTLs are simple to set up on your table items. I wrote an extensive article about this here.
3. Keep attribute names short
Some time ago, I wrote an article about how shortening attribute names could help you save costs in DynamoDB.
While this remains a more drastic measure to squeeze out charges, it can be quite effective at larger scales.
The idea behind this is that DynamoDB charges you for the size of the data returned from your queries.
If your queries return smaller data you are charged less for the same query.
One way of optimizing this is by shortening your attribute names.
For example, “lastDateSubmittedByUser” could become a gluttonous attribute name when used on every item in a table.
A good strategy would be renaming the attribute name to “LDSU” and then renaming it back to the original name on the front end.
4. Use Infrequent Access Tables
DynamoDB offers two table classes to help you optimize your table’s costs.
These are:
Standard table class
Standard-Infrequent Access table class
The standard table class is the default table that is designed to balance storage and throughput costs.
On the other hand, the standard-infrequent access table class offers up to 60% lower storage costs and 25% higher read/write costs than the standard table.
The takeaway here is to choose the infrequent table class for infrequently accessed data when you can to save on costs.
5. Don’t store large objects
DynamoDB was never designed to store large objects.
Large objects can consist of blob files, long text, or objects with many attributes.
DynamoDB promises single-digit latency queries and for that reason, data queried is always limited to 1MB.
Furthermore, a single item’s maximum size cannot surpass 400 KBs.
Instead, large objects should be stored in Amazon S3 or compressed if they absolutely need to be stored in your DynamoDB table.
One Tip To Save Costs
Use on-demand throughput capacity when you can’t anticipate the traffic you will get on your tables.
Use provisioned capacity mode when you understand your traffic patterns and can ancticipate usage better.
Switch between modes to test them out and find the most efficient configuration.
Want to learn more about optimizing your cloud costs? Subscribe to our newsletter for weekly cloud computing cost-savings tips and insights.
Curated Article
“How To Reduce DynamoDB Latency & Costs With The Single Table Design”. Uriel Bitton. Ovt 14, 2024. https://medium.com/aws-in-plain-english/how-to-reduce-dynamodb-latency-costs-with-the-single-table-design-88c178d78c7b
Enjoying the newsletter?
🚀 Follow me on LinkedIn for daily posts on AWS and DynamoDB.
🔥 Invite your colleagues to subscribe to help them save on their AWS costs.
✍️ Check out my blog on AWS here.