Search code examples
amazon-web-servicesperformanceamazon-rdsdatabase-performancequery-performance

Querying to RDS vs Querying to S3(ListObject) regarding performance


I'm using RDS(Remote database), S3(Remote storage), and EC2 instance.

Whenever fetching users' avatars, to determine the member has an avatar or not, my application is doing:

  1. Using ListObject, determine whether avatar folder exists or not, and if exist, get an avatar image.(Cannot use Head request, because filename(key)'s consist of random number.

    VS

  2. I would like to change the way fetching an avatar using RDS(db). Whenever a user upload the avatar, the filename is stored in DB, and I can determine after querying to DB whether avatar image exists or not, and if exist, get an avatar image from S3.

So the difference between two way is querying to S3 using Listobeject vs queering to RDS whether user's avatar is exist or not.

Which way is better regarding performance and cost?

I don't know the ListObject exactly, however, I think it might use file_exist, opendir, readdir, closedir to list objects, so querying to DB is better way. I don't have confidence though.

Any tips are appreciated. Thank you. Have a good one! :)


Solution

  • You would always be better-off querying a database. That is because databases are designed for querying, whereas Amazon S3 designed for storing data. It won't necessarily be as fast.

    Presumably, your app will retrieve information about the user from the database when they login, so it could simply retrieve this information too (without needing another database access).