So this is kind of a very common and popular problems some times for developers who are working on image uploads on there day to day programming life.So this was discussed within the past few weeks within our internal team.So I was selecting a one approach and another senior engineer was thinking about another approach and one of my friend was suggesting another approach.So I will take one by one and will see what approach is the best and cost efficient and efficient way of doing the file upload
So the first suggestion :- Convert the image to base64 and save it on mongo db
So yes this can be done and saved in the mongo db.But why am saying it’s bad.Let’s think about a mlab mongo db instance as an example it takes 15$ per month for a 1GB.Okay lets say if one file is 3mb and its around 330 files.
If we have 1000’s of users if they use to save at least one image oh man it will cost us a huge amount.Damn so yes this not the best way for me.
The second suggestion :- Attached hard drive with the server as the image saving location
Hmm.Not a very bad solution when it comes to efficiency and the cost.But let’s say if u have more than one server of the application(For an example if we have 3 ec2 instances connected from load balancer).
So now it will not work well with horizontal scaling.
So the third and best suggestion :- Save the image in a cloud bucket(aws s3,azure file storage,gcloud storage) and retrieve for further reference.
So why we say this is the best solution
- Every cloud platform supports and has this bucket concept and easy to upload with the sdk they provide.
- Cost effectiveness. $0.023$ per month for a 1GB.
- It can be scale at any level no need to worry about file size.
- Easy backup’s.
- Availability is very high( S3 => 99.999999999%).
Cool so the third solution is the on that I suggest as the best solution.So that’s it for now.Hope u will get something out of this cool