Where do we use DynamoDB in real-world applications, and what kind of problems does it solve compared to a traditional relational database like MySQL or PostgreSQL? Please explain with practical use cases such as user sessions, shopping carts, IoT data, gaming leaderboards, metadata storage, and high-scale applications.
The use case is quite different than traditional relational databases. DynamoDB’s premise is that it’s a) a fully managed service, no need to maintain it, manage upgrades, backups, etc. and b) you’ll get practically infinite scaling IF you know your access patterns and can index the tables accordingly. This comes with the cost of not being able to query as freely as you can in other databases (you can make fast queries on the indexed fields, otherwise you scan them all).
It also has the advantage of being fully compatible with other AWS services, so you can get your code to run with IAM permissions for just a specific primary key (great for tenant isolation for example), as well as Dynamo Stream, which lets you trigger events when there are changes / inserts in the table.
It definitely has use cases, I’ve developed a few things with it that run in production to this day quite well. I would not pick it as the primary database for a new large project though in most cases. I think even in Alex Debrie’s book on Dynamo (he’s one of the known DynamoDB “gurus”) he says that if you’re a young startup, DynamoDB is probably not the DB for you (Pretty sure he said that, not 100% sure, not going to look for the exact quote, but the message is true IMO )
It’s cheap fast and easy when it fits. So at the start of most projects I consider it. I mostly end up using Postgres.
Most of the time the fit is if you have data that has a very rigid access pattern, and doesn’t benefit from being relational. Most data doesn’t fall into either of those categories let alone both. But doing it as a thought exercise fleshes out access patterns, some of which may have been a problem if overlooked.
Most of the uses I’ve had are materialized analyitics with few if any pivots. Like a spark job or flink aggregating things then stuffing the output in a table for fast retrieval.
Then there’s random goofy shit like deduplication tables that fit nicely. Say you want exactly once semantics on an sqs queue. Use a conditional write of an idempotent value from an event on the condition that it doesn’t already exist. sqs is at least once delivery, the deduplication makes it at most once, and using dynamo is really friggin fast. And supports ttls. (There are better ways to do something similar, but sometimes it’s easier to deal with decisions of the past than to forklift them out.)
One real-world application for Dynamodb is for messaging.
Imagine you are making a CRM or a marketing platform system which handles millions of message exchange per day and you want to store the message for X days. Dynamodb makes its very easy with practically infinite scale with in built TTL settings.
Scale to zero. Use zero pay zero. This is very important for prototyping and startups. Less of a differentiator since Aurora DSQL was released last year and that effectively gives you the same benefit with a relational database.
Scale to infinity. You trade higher upfront design and a frugal interface for extremely flexible scaling. This is very important for high throughput or spiky application traffic. The original use case was basically “i know my access pattern, i dont need the flexibility, i just want to make sure that i can always write to this database and my changes are always eventually persisted”
You may be thinking “scale to infinity? Thats overkill, who actually needs that?”.
Amazon does. Thats why they made it. If you are not Amazon, Microsoft, Google, Netflix scale, then a relational database will likely serve your needs just fine with a lot less hacks and application-level implementations of joins / complex query logic (don’t get me started on single table design — again if you’re not Amazon scale then you do not single table designs, even if you choose to go with DynamoDB).
I worked at Amazon so I’m very comfortable with DynamoDB. Only because I used it for years. Anyone else should probably start with PostgreSQL. If you dont want to manage instances at all and need scale to zero, try Aurora DSQL.
Very true! I always think about Just Use Postgres with questions like these. If you’re not sure which data store to use, Postgres is the right answer.
Even if you’re pretty sure you can live with all the limitations DynamoDB imposes on your architecture right now, it’s not like Postgres where its flexibility means there’s always at least some room to refactor or optimise.
Also elasticity. We abuse the shit out of that to get some incredibly cheap burst capacity. MongoDB were trying to sell us a move to atlas and they couldn’t come anywhere near it price wise.
I’ve built whole systems using dynamodb + lambda. Eg an operational checklist system saas used by enterprises. You have to think and architect a little differently with dynamodb, eg using lambda triggers on a table change stream to update a related table, rather than using relations. It has nice features too that are more cloud - it’s easy to run lambas which send to websockets when a given table is updated (and therefore updates data live in a web app) or makes requests to another api for integrations. I’ve pretty much moved away from relational databases because (1) cost - especially for having multiple stacks for testing etc (2) single point of failure - though I’ve never actually been caught by that with rds and many people I’m sure run with no downtime (3) no administration needed (sql versions/upgrades/instance sizing etc) (4) when you get used to it it feels more ‘cloud’ and you can build whatever you want, the scalability in both directions opens up possibilities, the lambda integration is useful and the admin overhead of relational becomes more apparent
Same experience here. I’ve used it to persist state for fully event driven architectures. Works really well, and I would encourage the use of single table design. You will need to consider your access patterns up front as others have noted ~ but it’s NOT that crazy, just different for many new to the concept.
Minor perk, not saying this is THE reason to go DDB, just nice: I like to build ephemeral environments for apps and services, so DDB is amazing for this. RDS usually takes 10-15 minutes to provision, which is forever in ephemeral deployment speak. With my EDA serverless apps, the whole app or service is up in about 1-2 minutes and I’m running full E2E tests
We use it for basically everything, inside a serverless application.
The app is written as a modular monolith, with business functionality split into packages - which expose storage abstractions which are invariably implemented on top of DynamoDB and/or S3.
This has scaled very well: this isolation means that any complexity involved in implementing a feature in DynamoDB (e.g. complex key structures) does not leak outside the package, and it’s very rare for new features to require table modification.
As coding agents came along, we found it’s also a rich source of examples: we can point Claude at a few representative packages and get something that works straight out of the box and follows all the existing conventions and style - again leveraging the self-contained nature of the packages.
By contrast, with a relational database, you are invariably designing a model and table structure that must work for many possible use-cases - present and future/ This means multiple overlapping consumers of each part of the model - each with different needs - and migrations and refactors as you correct design errors which will then affect all those consumers. Of course you can do table-per-package or table-per-microservice but then you’re giving up a lot of the advantages of the relational model in the first place, IMHO.
I’ve built systems both ways for many years at this point, and they both have strengths and weaknesses, but since the vast majority of storage is just simple CRUD, I find DynamoDB is a good fit for most use cases as long as you design for it from the outset.
It does a bounded amount of work per request. This restriction is actually a blessing if you anticipate scaling.
Better to say where it struggles and how you adapt. Don’t use it for data tables with multiple filters and sorts. Don’t try to do many-to-many mappings. Denormalise your data, use adjacency list pattern. You can write a 200 line lambda and use CDC to send data into ElasticSearch. That will give you more search capabilities.
It Depends. (Like everything in IT.) It’s great if what you need is a simple flat-file with one, or few, indexes (items you’d need to retrieve based on their contents.) If you need to filter or retrieve based on any value, it’s not for you. If you need to setup complicated relationships between tables (and query on them), it’s not for you.
If you find your workflow involves scanning every line of a DDB looking for something, or building reports about every line in the DB, it’s going to be very expensive, very quickly.
In the end, as always, it comes down to business needs, and then making the trade-offs to meet those business needs. A single project might have parts that are suitable for one, and other parts best put in the other. (e.g. a supply-chain management system for a retailer will probably be relational. The shopping cart for that same retailer will probably be best-suited for NoSQL.)