I only have experience with relational databases but am interested in DynamoDB and doing a single table design if appropriate.
(This is example is analogous to my actual existing product.)
I have a bunch of recipes. Each recipes has a set of ingredients, and a list of cooking steps. Each cooking step consists of a list of texts, images and videos that are used by the app to construct an attractive presentation of the recipe.
Videos may be used in multiple recipes (e.g., a video showing how to dice onions efficiently.)
My access cases would be give me the list of recipes (name of recipe, author, date created); give me the ingredients for a particular recipe; give me the list of cooking steps for a particular recipe which entails returning a list of the steps and each step is itself a list of the components.
Is this an appropriate scenario for single table DynamoDB?
If you know all the access / queries beforehand (sounds like you do) and can design good indexes around them, then it can work.
I don’t love single table design, but that’s mostly from trauma due to working with a poorly designed single dynamo table with data that was super relational and should have just been in postgres or something
While dynamo looks cool and interesting, it has massive drawbacks that need to be carefully considered.
The design gets clunky, because it’s not optimized for development productivity, but for raw performance. What would have looked elegant in SQL, is complicated in dynamo
It’s a proprietary tool - if this was a work project for you, think about staffing your team with people proficient in dynamo. With RDBMS it’s simple, everyone knows some SQL dialect and most of the knowledge is transferable. It’s not the same here, if somebody went from SQL to dynamo for the first time, there’s a learning curve
Pricing can be tricky to understand and if your design is poor, your wallet will compensate for your lack of expertise with dynamo. Of course, this is only a concern when you have big datasets, it sounds like it’s not a problem for you
Using Dynamo is essentially a performance optimization. I have used it and will use it again, but unless it’s something very simple that I never want to have to worry about scaling on, I’d rather use Postgres. I have a batch service that I wrote using DDB because it kind of needed to be slapped together quickly, and five years later I still regret it every time I have to mess with it.
Yep! And it will be much cheaper than storing and retrieving it from DynamoDB. At least, that’s the common complaint from DynamoDB users who ask the DBA team how to migrate their data out of DynamoDB to a relational database.
Yes you can use DDB for that. Just consider what the (minimal) amount of data is for each page you want to render. Then you try to load all that data in a single ddb call using an optimized index.
Just don’t think relational. You usually need to duplicate data which some people really don’t like leading to relational data structures and inefficient query patterns.
I would suggest you have more to do to figure out your access patterns. The hard parts are in the smaller details (e.g. “allow recipe title to be updated. don’t allow duplicated recipe names on create. don’t allow duplicate recipe names on update. list recipes by date created. list recipes by title. list recipes by average review. search for recipe by ingredient. update all recipes with specific ingredient.” etc,. etc)
What you listed alone it would be doable in dynamodb pretty easily (deciding how to model your shared videos, as an example, would require a fair amount of thinking), but if you’re goal is to learn DynamoDB on a small / hobby project, go for it I say, what you listed out alone could be a great wya to get some practice.
That said, you would almost certainly (in my opinion of course) be better off, by far, with a relational database for this type of use case. The relationship between videos for common ingredients and stuff would be a natural fit for a relational database (e.g. have a tagging system that relates video resources to ingredients, ingredients associated to recipes, and an easy way to go between these things, manage them easily, etc).
Sidenote: I am a human, btw, though I wonder as I’m typing all of this what the point of me typing all of this anymore is.
Your access patterns, as stated, are well-defined, key-based, and hierarchical which means that DynamoDB would likely be a good fit. DynamoDB obviously has some benefits over a typical RDBMS such as the ability to send stateless API-based queries (vs. persistent connections), built-in backups and point-in-time recovery, low to zero operational cost when not in use, etc.
But, I would think ahead to how your users might eventually want to query your database. Let’s say you have above 100 recipes. At that point, simply presenting a list of recipes to the user wouldn’t be ideal. The user would likely want to fuzzy search for a recipe e.g. indicating one word in the recipe title or even mis-spelling the recipe or search for recipes using a specific ingredient. You can’t generally solve these type of ad hoc queries with DynamoDB.
So, if this is a learning exercise for you and you don’t require ad hoc query support, then DynamoDB would be good. Otherwise, I’d suggest an RDBMS (or even Elasticsearch).
I might be confusing it with DocumentDB, but typically it goes like im asked “install this software”, “setup this service”, or “spin up this service” and im trying to convert the docker image to fargate.
then i get to the database or whatever it uses that i cant persist in fargate, or shouldnt run in fargate with out putting it on efs.
then it turns out whatever that container is in the compose that needs to be externalized from the fargate task is at minimum $50~/month for the aws service that replaces it.
or the cost is “well its based on usage if you use it a little you can afford it, but if you use it a lot dont use it”
so then i have to spin up that docker compose on a ec2 instance running docker just to try and figure out the usage amount.
Avoid Building RDS schemas by linking tables in your head get a proper RDS once you notice you are building defacto foreign key relations.
When you can live with a single table and some redundancy like in star schemas of some BA tools and you can foresee queries then dynamo may be good candidate