S3 or DynamoDb for user storage?

2.5k views Asked by At

I'd like to use AWS Lambda and Cognito in a serverless architecture and was curious people's thoughts to use an S3 bucket for a user data store versus something like DynamoDb? What would be the pros/cons?

2

There are 2 answers

0
Mark B On

Do you want to index, query and update the data quickly (DynamoDB)?

Or do you just want to store it in a flat file that has to be completely overwritten whenever it is updated and can't easily be queried for its contents (S3)?

0
Ashan On

You can use either one or both based on different types of user data and query needs. In addition you can also keep basic user profile data in Cognito Sync store.

AWS S3

  • Its a fully-managed file storage and retrieval service.
  • Highly suitable to store user profile image, file uploads & etc.
  • You can store user attributes in a JSON file or in multiple files. One of the challenges are you need to retrieve entire file even to read a single attribute or save the entire file to save a single attribute.
  • Need to build a file name conventions to find the files directly for faster retrieval or listing files and reading each file to find the internal content is costly in performance.
  • Cost wise this would be and cheaper option compared to Dynamodb.
  • Won't be suitable to store dynamically changing user data which can impact application performance.

AWS Dynamodb

  • Its a fully-managed NOSQL database
  • Recommended to store user attributes for fast queries, updates and retrieval.
  • Has built in query support and conditional updates.
  • Possible to do partial updates.
  • Suitable if you need to query multiple users and update.
  • Generally costlier than S3.

Its a common pattern to use them together to get the best out of cost and performance by storing files in S3 and file metadata and frequently querying attributes in Dynamodb for fast queries. Also you can setup event driven patterns to update Dynamodb upon changes in S3.