user1220169
user1220169

Reputation: 813

MEAN Stack - Storing many small images in MongoDB vs FS. If FS, how to handle loadbalanced servers

All,

I know this is all over the internet and there is no one compelling answer. However let me explain my situation so that I can get some relevant help.

I am having to store many small images (mostly user avatars) and having to show a list of users with avatars (requiring a bulk user list read along with their avatar pics). Tried storing the images as base64 in MongoDB, but it poorly affects the read performance - takes 900ms to retrieve just 10 records opposed to 70ms without the base64 fields. The application has the potential to grow quickly as we are developing it for an established clinic.

Considering our situation (store many small images, read a bulk of them at once) what would you great minds recommend ? I know there are other methods, like GFS or storing as binary in mongoDB. Still exploring those options - what do you think about those ? If FileSystem is your recommendation, I am unaware of how it would be handled in a loadbalanced app servers situation. For example if I am running 3 app servers, i am storing the image on the filesystem of the app server that received the upload request. While retrieving the image back how would the loadbalancer know which app server has this image to route the browser's GET request to ? Also how do I efficiently manage orphaned files situation. When a user record is updated or deleted via application I can remove the filesystem file right at the time of DB update/delete. is this considered a safe data synching strategy?

Upvotes: 0

Views: 94

Answers (1)

Mark B
Mark B

Reputation: 200970

Have you considered storing them in S3 instead? Storing them across load balanced app servers is a horrible idea. S3 is the solution generally recommended in this scenario. S3 can even directly serve the images for you, removing load from your web servers.

Upvotes: 2

Related Questions