Prepare setup with nodejs and mongodb for traffic

February 27, 2014 4.7k views
Currently, I am hosting a backend for my mobile app and website with one droplet running nodejs and mongodb. The service lets the user upload and view pictures (around 2-300 kb). These images are stored with GridFS. Right now we don't have that many users because we haven't launched it yet (test phase). However, everything is working just fine right now. In the near future, we are expecting a lot more users - about 2 000 users uploading and viewing photos during one day. One uploaded photo will remain in my server for about a month. 1. Is it stupid to store these photos in the droplets? Should we consider using a third party service for that purpose? Is the current setup sustainable? 2. What would be the best way to organize the application server with nodejs and the database (mongodb). Should the database be stored on a dedicated droplet, and is it okay to have it on the same droplet? 3. What is the smartest way to ensure a fault-tolerant and load-balanced service with this setup? I don't expect any really detailed answers here, but I was hoping someone could point me in the right direction in terms of how I should be organizing this service. What are the best tools suited for the job?
2 Answers
1. Is it stupid to store these photos in the droplets? Should we consider using a third party service for that purpose? Is the current setup sustainable?
You're eventually going to run out of space, however, since you have GridFS set up, you can just add more droplets. It might get expensive later on since droplets don't have a lot of space so you might want to look into caching the most recently accessed files on a droplet while hosting everything on Amazon S3 or a similar service.
2. What would be the best way to organize the application server with nodejs and the database (mongodb). Should the database be stored on a dedicated droplet, and is it okay to have it on the same droplet?
A MongoDB cluster should help so that if one server fails and goes down, another server becomes the primary and kicks off. You can start off with two droplets and an arbiter hosted on your app server. I recommend reading all about replication before setting it up: http://docs.mongodb.org/manual/replication/.
3. What is the smartest way to ensure a fault-tolerant and load-balanced service with this setup?
You can load balance your nodejs by running it on two or more app servers and load balancing between them using HAProxy: https://www.digitalocean.com/community/articles/how-to-use-haproxy-to-set-up-http-load-balancing-on-an-ubuntu-vps.
As for MongoDB, I answered that in #2.

I hope that helps! :]
by Jesin A
This article runs through how to use HAProxy to setup HTTP load balancing on an Ubuntu VPS.
Awesome, exactly what I needed. Thanks!
Have another answer? Share your knowledge.