Question

Can you suggest an architecture for a Node.js application with reverse proxy, MongoDB and static client app?

Posted June 28, 2016 4.1k views
NginxMongoDBNode.jsSecurityScalingLoad BalancingMEANUbuntu 16.04

I need to host a production application for a relatively small number of users (say about 100 initially, but maybe increasing to 1000-5000 over the next years).

At the moment, I am trying to decide between hosting it all on PaaS providers like Google Cloud and mLab, or taking the do-it-yourself approach with Digital Ocean, to save some money.

If I were to host this application myself on Digital Ocean, what architecture would you recommend to use? And how many droplets?

My current thinking is to setup a Nginx web server to host the static client files and to act as a reverse proxy for the Node.js Express app and possibly a load balancer in the future. In addition, I will need a MongoDB database server as well.

There will be no need for a mail server, as I will be using Sendgrid to send emails.

Should I dump this all on one droplet or split it up in multiple? I want to avoid having to pay too much (e.g. have too many droplets) at this initial stage, so can I for example have 1 droplet for the Nginx web server and 1 droplet for the Node.js app + MongoDB database? Or should I run the MongoDB on a separate server?

And as a bonus question: what if I wanted to host a couple of static sites in addition to this application, could I safely do so on the same Nginx droplet? We’re talking minimal traffic for those small sites, and on a separate domain.

What are your thoughts? Are there any other considerations I need to think of?

What about scaling, security, load balancing?

Any feedback would be greatly appreciated!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

With low traffic to start off you could choose to go with a single droplet though it may be easier later on if you use one droplet for nginx and a second for node + mongo. That way when you are ready to scale up you could add more web workers or separate your db onto a separate server. We have a variety of tutorials here on various load balancing methods. Not too long ago we released floating IPs which along with a server to monitor your active services would allow you easily fail-over as needed. For smaller deployments I also recommend CloudFlare. Their free tier provides a worldwide CDN and reverse proxy service which in many cases will reduce the load on your servers substantially as well as providing some basic protection against DDoS attacks.

  • Hi Ryan, thanks for your suggestion. Yes, I was inclined towards using at least 2 droplets to start with, to make scaling easier later on.

    As for CloudFlare, do you mean for me to use it for the static content (e.g. front-facing SPA app)? I was contemplating of putting it on Firebase. Would that be suitable as well?

Submit an Answer