linas mnew linas mnew - 2 months ago 6
Node.js Question

Is this logic for a profile image uploader be scalable?

Would the following generic logic for implementing a profile upload feature be scalable in production?

1. Inside a web app user selects an image to upload
2. Image gets sent to the server where it gets stored in memory and validated using nodejs package called: multer
3. If the image file is valid, a unique name is generated for the file
4. The image is resized to 150 x 150 using nodejs package called: sharp
5. Image is streamed to google cloud storage
6. Once image is saved a public URL of the image is saved under the user’s profile inside of the database
7. The image ULR is sent back to the client and the image gets displayed


Languages used to implement the above

This would be implemented using:


  • firebase cloud functions running on Nodejs as a backend

  • Google Cloud Storage for holding images

  • firebase database for saving image url for the user uploading the image



My current concerns with this are:


  • Holding an image in memory while it gets validated and processed will potentially lead to servers clogging up during heavy load

  • How would this way of generating a unique name for the image scale?: uuidV4 + current date in milliseconds + last 5 characters of the image's original file name


Answer Source

Both multer and sharp are efficient enough for your needs:

Uploaded 2MB pictures downsized to 150x150 resolution.

Let's say you'll have 100,000 users. Every user uploads a picture that gets downsized to 20kb image. That's 1.907GB ~ 2GB of storage.

Google Cloud Storage:

  • One instance in Frankfurt
  • 2GB regional storage

= $0.55 a year

Google Cloud Functions:

With 100k users, for simplicity, let's assume it will be evenly distributed and so we'll have 8334 per month users uploading their images. And let's be extremely pessimistic and say that one resize function will take 3s.

  • 8334 resize operations per month
  • 3s per function
  • Networking throughput 2MB per function

= $16.24 a year

So you're good to go. Happy coding!


This answer will get outdated eventually, so I'm including screenshot of google price calculator:

enter image description here