DEV Community

Cover image for My take on dynamodb
Kyle Parisi
Kyle Parisi

Posted on

My take on dynamodb

Why Dynamodb

Every time I look at the Dynamodb SDK docs, I think 'man this is an over engineered hot mess'. The obvious reasons to use dynamodb are that it is managed, has autoscaling built in, and it's cheap. The technical idea is that compute (i.e. mysql) is much more expensive than mapped storage (i.e. dynamodb).

Why might I use it

Using it as a key value store, 1:1, or a time series data source, 1:N, are clear and easy to implement. I'm of the opinion that this is probably all you should consider using it for. If you need N:M, you need to add a "Global Secondary Key" which is like a higher order clone of your main table's items which doesn't require uniqueness on the partition key. If you need N:M:O, just use a relational database.

Take-aways on reading data


scan abilities

Use scans when you don't know the partition key. You probably want to reserve this operation for "data-science" reasons. Scan will go through all of the data. If you don't have a lot of data (< 10GB), do whatever you want.


query abilities

Use queries when you know the partition key and want to sort on the sort key.


filter abilities

Filters can be applied to either scans or queries. They happen after the scan or query completes. A query and filters can be a powerful combination, such as filtering a product list by brand or price.

Get Item

Interestingly the AWS console does not have a get item option. This is probably because a query can solve this operation. Using this method is obviously going to return 1 record and be most efficient on all fronts.

Create, update, delete

These are pretty generic operations on an atomic level. If you need to batch an operation, there are methods in the SDK for those.

A use case I like

User sessions I think are an interesting candidate for the 1:1 or 1:N use case. Data will be automatically encrypted at rest. Dynamodb tables can also be configured to have TTL on items. In the 1:N scenario, if a logout action happens and you set the sort key to contain a user id, you can remove all sessions at once.

Top comments (5)

kevinlbatchelor profile image
Hello Dave

Dynamodb can really be helpful for some use cases, the API scares off a lot of devs and it isn't a good substation for an rds. It scales well with no maintenance. But if you need to write complex queries of relational data I prefer postgress or msql on rds. For config, state or otherwise effemirel data it is perfect.

kyleparisi profile image
Kyle Parisi

I agree about the API/SDK. I made a really quick prototype around reads: that I may add as a follow up article. This other library is neat:

tusharborole profile image
Tushar Borole

worst part of dynamo db is you cant sort by key, seriously, what kind of database it is, which does not even provide the sorting feature and specified key

okbrown profile image
Orlando Brown

Here you go.
ScanIndexForward: <false|true>
Put that in your query to order by sort key ASC or DESC

Some comments may only be visible to logged-in visitors. Sign in to view all comments.