When it comes to images, everyone says use S3. I understand different tools are built for different purposes it’s understandable S3 is the default go to. But for educational purposes, I’m curious when it would be a better idea to use DDB over S3.
Let’s say for an app like tinder, can’t you store the main profile image (let’s say image1) in the ImageTable1 with highest read write capacity and the rest of 5 or so images in the respective tables with low read write capacity settings. Each of these tables would only require a Hash Key and not a sort key.
Or is this design still a bad idea? Wouldn’t this design cost less than using S3 since S3 pricing is proportional to number of get put requests while DynamoDB pricing is based on preset read write capacity?
And yes, I’m very aware that DDB has a single item size limit of 400kb. So for this argument, let’s assume each image is <400 KB.
Hey, I’m learning too but I am going to take a try at answering this. I believe with SQL dbs, which I know DDB is not, if you attach an image into the database, the database obviously gets larger in faster steps requiring scaling of your instances faster. If you just attach a pointer to that image in another location (S3) then the database grows in smaller steps which keeps scaling at a slower pace.
Plus, I imagine you want to keep the pictures decoupled just in case of db failure.
I’m curious when it would be a better idea to use DDB over S3
The answer is not specific to AWS, but it’s a generic question: should I use database or filesystem to stores the images? The vast majority of use cases are in favor of the fs, one answer in favor of the database is for historization reasons (I want to know what was the picture used x years ago).
Concerning the tinder like app: S3 and its cloudfront integration offers, so many benefits (distribution, caching…) I can’t see anything in favor of dynamodb.
Business rule permissions are the first thing that comes to mind. Easier to enforce using a DB. A cache is a DB, but it has weak semantics and problematic timing side effects.
For a start, you need an HTTP front-end to serve images. S3 is an HTTP front-end to an object store, and has an even more efficient globally distributed HTTP front-end in CloudFront.
DynamoDB… I mean, you could jury rig something obnoxious with resource level policies and/or API Gateway, but… yikes, no. So you’d have to implement an HTTP front-end. And it would have to scale to some degree. All of which is heavy lifting that S3 and CloudFront were already doing for you.
I really don’t think pricing is the main issue here, but since you raised it: How much would it cost to tack a (weird, finicky) HTTP front-end layer on DynamoDB (with API Gateway or EC2) in infrastructure price and development time, versus using S3 and CloudFront for precisely what they were designed to do?
^(If you follow any of the above links, please respect the rules of reddit and don’t vote in the other threads.) ^(Info ^/ [1](/message/compose?to=/r/TotesMessenger))
It should be pointed out also that in almost all cases the image would be stored in S3 and then a reference to the image (url) would be held in a database of some kind.
Interestingly it is entirely possible to serve straight from DynamoDB without it having to be “obnoxious” (depending on your threshold for what makes something obnoxious I guess).
This way you could have a nice RESTful GET method for serving your images. You could even add record level authorisation with this approach (i.e. only let users see their own image).
It would be interesting to see the pricing comparison between the different options.
Overall I’d instinctively favour S3 - but it’s always good to consider alternatives as it opens up new ways of doing things.
S3 can be set to give you historical versioning as well if you like. There really is no case for using Dynamo unless it is for simplicity of an alpha app where you are already using dynamo for your data and you want to keep it all in one place.
All the others have pointed out some good answers, but I’ll address something not mentioned yet: $
This is going to be EXTREMELY expensive. ~1K item = 1 write capacity, and $0.0065 per hour for every 10 units. Do the math (suppose images of 100k, 500k, 1MB, etc.) with even low traffic, and you’ll see how much of a bad idea this is
Wouldn’t this design cost less than using S3 since S3 pricing is proportional to number of get put requests while DynamoDB pricing is based on preset read write capacity?
It’s always best to do the math. As someone pointed out, the fixed capacity is pretty expensive.
If you want fixed cost, you could start by serving the files on an EC2 instance, and move to S3 later. This could be cheaper (again, do the math, there’s a lot to consider.)
What you want to do is to store images in S3, but all the other metadata in the DB tables. You will be responsible for making sure the two are in sync. You will also have to have a plan for when the two are not in sync. But this solution would really scale.