Amazon DynamoDB Cost — Cutting Tips

Hardik Shah
6 min readNov 11, 2022

The cost of using DynamoDB can vary depending on how you use the service and what your usage patterns are. You can optimize your costs by making sure that you’re optimizing for performance, availability, and consistency in each of these areas:

#1. Use on-demand capacity for flexibility

The most expensive option in terms of capacity is “on-demand,” which gives you full control over your costs. This is ideal for testing and prototyping if you need faster execution times but are not sure how often data will be written to your DB table.

On-Demand Capacity

If you have plans to scale up or down frequently, then the on-demand option may be a good choice for your needs. In this scenario, it’s more cost effective than using reserved capacity because there are no upfront commitments required from either side — DynamoDB keeps track of how much storage space you’re using and charges per write or read operation accordingly (e.g., $0.10/GB).

#2. Analyze your workloads and use the right capacity mode

The second tip is to analyze your workloads and use the right capacity mode. The two most popular capacity modes are on-demand, which means that your instance will only be charged when it is running, and reserved, where you pay upfront for a certain amount of capacity. Each of these modes has advantages and disadvantages; if you want flexibility, use on-demand; if you want predictability, reserve your instances.

On-demand instances are cheaper than reserved ones but have an hourly minimum charge — so even if you don’t need to run your app for an hour or more in one go (a common situation), it may cost more than necessary because there’s no way around this minimum charge!

#3. Use an Auto Scaling policy

Auto Scaling can help you save money on DynamoDB. Auto Scaling is a feature of AWS that allows you to automatically increase the capacity of services based on demand. If you’re using Auto Scaling, then your application will automatically add more read and write capacity as needed.

Auto Scaling can do many things, but we’ll focus on two use cases: increasing and decreasing capacity based on load and cost considerations respectively. For example, if you have an archive table that only gets used once every month (or even less), then it would be wasteful for DynamoDB to keep that table available all year long. With an Auto Scaling policy in place, your table will be deleted until needed again next month or year — saving money in the process!

Similarly with billing changes — if new pricing information becomes available from Amazon about how much more expensive their service will get next quarter compared with last quarter, then this could change how much capacity should be provisioned now.

#4. Enable DAX

This is a service that can accelerate your queries and significantly reduce costs. If you have a lot of reads in your application, then DAX is an excellent way to save money.

To enable this feature, go to the Amazon DynamoDB console and click on “vertical bar” icon at bottom-right corner. This will open up a drop-down menu with two options: “Disabled” and “Enabled” as shown below:

By default it should be enabled for all tables. However, if you want to check whether it is disabled or not, check the status on each table by clicking on them one by one and making sure that Status column shows 1 (Enabled). You can also enable/disable it using AWS CLI command line tool as shown below:

#5. Enable Batch Get & Put Operations

Batch reads and writes allow you to run multiple requests in a single API call. This can be useful for high throughput applications, as it greatly reduces the number of network round trips required. It also improves write performance by allowing DynamoDB to process multiple item updates in parallel, reducing latency caused by serialization and deserialization.

Batch operations are enabled by default on a table, but you can opt out of them by setting enableBatchOperations to false in your table’s configuration:

dynamodb = dynamodb_table(“my-table”, config={‘enableBatchOperations’: False}).put_item({“UserId”: uuid4().hex})

#6. Choose the Right DynamoDB Partition Key Distribution

You can control how DynamoDB partitions the data by choosing the right partition key distribution. The table’s size will be divided into multiple partitions, and all these partitions have a similar number of items. This way, you can easily distribute your data according to the number of reads and writes needed for each partition.

For example: If you want to read all your customers’ orders from a single table, you should set up this table so that it doesn’t contain too many customers in one region (partition). You also need to make sure that every customer has their own region in order to improve performance significantly! You can do that by using a hash function as part of your hash key; this will guarantee uniform distribution across multiple regions for each unique combination of values in that portion of your hash key.

#7. Configure CloudWatch Alarms to Monitor Provisioned Throughput Throttling

Monitor your provisioned throughput. You can configure alarms to notify you when you are approaching or exceeding your provisioned throughput capacity. You will be charged more if you exceed your provisioned throughput, so it is important to ensure that you do not reach this limit by monitoring the number of read and write operations performed against tables in DynamoDB using CloudWatch Alarms. If necessary, increase the capacity on your table (this does not increase the size of data stored in DynamoDB).

#8. Create secondary indexes for your tables to optimize queries and reduce reads, writes, and storage costs.

Secondary indexes are used to reduce the number of reads and writes to your tables. For example, if you have a table named User with columns name and age, then you can create a secondary index (auto-generated by default) like this:

User(name, age)

You can use this secondary index as follows to filter data on Name or Age:

SELECT * FROM user WHERE first_name = ‘Joe’;

#9. Choose the right partition key data type

Hash and range partition keys are the two most common partition key data types. They’re both used to create multiple partitions within a table, but they accomplish this task in different ways.

Hash partition keys:

  • Create a hash of the partition key to determine which shard the record should go in (i.e., you can’t reliably predict where your records will end up).
  • Can only be used with string or binary data types as the hash function doesn’t work with numbers or dates or other non-string values. If you try to use anything else for your hash key, DynamoDB will return an error message saying that it isn’t supported and won’t allow you to create a table using this kind of distribution method.

Range partition keys:

  • Divide up items based on ranges instead of hashing them into arbitrary groupings based on their contents — making sure everything gets split evenly across all available nodes ensures greater availability when compared against other types but sacrifices some performance due to additional latency caused by transferring large amounts of information between nodes every time something needs updating or deleting.

Cutting down costs can be done by making sure all of your bases are covered when you configure your dynamodb

  • On-demand capacity mode: This is the default of DynamoDB, and it’s suitable for most workloads. However, if your workload is variable or has peaks, you might want to use this mode as well.
  • Provisioned Throughput mode: If you have a consistent throughput requirement, then this is the right choice for you. You can either choose between two options here — high performance or high capacity — depending on what fits best with your application’s needs.
  • Read capacity units (RCUs): RCUs are good for applications that read data frequently but don’t write any data back into the database like NoSQL databases do; instead they just read from them and keep those reads in cache so that they don’t need to query again later on when someone else wants access too!

Conclusion

As you can see, there are many different ways to cut down on your DynamoDB costs. The key is to make sure that you have an understanding of how your workloads will impact the database and its performance so that you can plan accordingly.

--

--