Optimize Costs By Using Shorter Attribute Names
Uriel Bitton
AWS Cloud Consultant | The DynamoDB guy | AWS Certified | I help you supercharge your DynamoDB database ????
Welcome to the 13th edition of Excelling With DynamoDB!
In this week’s issue I’ll discuss a lesser known yet effective way to optimize your data on DynamoDB for speed and cost.
Why Optimize Attribute Names
An optimization beneficial for large databases using DynamoDB is to shorten attribute names in your tables.
The most obvious question is what effect does shortening the attribute names have on speed and costs?
DynamoDB offers a pay-per-use pricing plan which effectively means you pay only for the data you use/provision.
You don’t pay a minimum monthly amount nor a per reads/writes capacity.
With DynamoDB, you are charged for the RCUs and WCUs you provision per month.
An RCU or read capacity unit is roughly 4Kbs worth of data, while a WCU or write capacity unit is around 1Kb of data; RCUs measure reads while WCUs measure writes.
So instead of being charged for the number of reads and writes from and to your database, you are charged per 4Kb and 1Kb slices respectively.
If you provision 1 RCU per month - which essentially means you allow only 4Kbs of data to be read per month, you will pay about $0.00013 and $0.00065 for 1 WCU.
Ultimately, the less data you read and write, the less your bill will be at the end of the month.
This leads us to design smaller items in our database tables.
How To Optimize Attribute Names
Optimizing your database table attribute names is a simple process. The idea is to simply use shorter names and rebuild them later in your application.
Consider the following example.
const user = User;
response = client.putItem(
TableName = ‘Users’,
Item = {
“u”: {“S”: user.username },
“e”: {“S”: user.email },
“fn”: {“S”: user.firstName },
“ln”: {“S”: user.lastName },
}
)
The putItem method inserts into the Users table an item with four attributes and values.
We have “u” for username, “e” for email, “fn” for first name and “ln” for last name.
To write user items to our table we can save on write units by using this abbreviation process. Then when our application reads the items we can convert the attribute names to more meaningful names.
The result is an optimized read and write operation which saves on costs and latency as well.
领英推荐
When To Optimize Attribute Names
Naturally, this is a slightly extreme optimization and will not favour every type of application.
The recommended usage of shortening attribute names is for applications that have databases with massive amounts of data, where these optimizations will yield large savings of costs and latency.
For your average application however, this optimization is usually unnecessary. The difference in costs with smaller to medium sized databases will be insignificant.
Conclusion
Optimizing attribute names in DynamoDB can lead to significant cost savings and improved performance for applications with large datasets.
By using shorter attribute names, you can reduce the amount of data read and written, thereby decreasing your monthly charges.
This optimization is particularly beneficial for applications with substantial data volumes. Applications that don’t need to store millions or billions of items will usually not see any significant cost savings from this optimization.
If you enjoyed this post, please consider subscribing and sharing the newsletter with your network: https://www.dhirubhai.net/newsletters/7181386750357893121/
?? My name is Uriel Bitton and I hope you learned something in this edition of Excelling With DynamoDB.
?? You can share the article with your network to help others learn as well.
?? If you enjoyed this you can subscribe to my newsletter on Medium to get my latest articles on DynamoDB and serverless by email.
?? my blog website is coming soon, so stay tuned for that.
?? I hope to see you in the next week's edition!
Uriel
References