How to host Node.js Auth service, Match service, Chat service with MongoDB, Neo4j, PostgreSQL, Redis, RabbitMQ?

April 26, 2018 424 views
Scaling Deployment PostgreSQL MongoDB NoSQL Node.js Ubuntu Ubuntu 16.04 Ubuntu 18.04

So I have

Nginx in front

4 Node.js apps where

API Gateway -> services
Auth service -> MongoDB
Match service -> Neo4j
Chat service -> PostgreSQL

Redis pubsub for the server-client connection, mostly for chat and match websockets
RabbitMQ message queue to communicate between services

How do you recommend I host this cheaply with room to scale if needed?

Any advice? I know there isn't a best answer, but any guidance would be highly appreciated!

2 Answers

I would recommend setting this up with 5 small droplets as this will provide you more options when it comes time to scale up. Your RabbitMQ can communicate between services over the private network so it's communications wouldn't count towards your bandwidth limits.

Starting out with the services and their associated DB on the same server will provide a less expensive deployment and once you begin to really scale you can set up dedicated DB servers to reduce the load on your app droplets.

  • This sounds great! I am excited to use DigitalOcean because the last time I tried to host an app like this with Heroku and 3rd-party integrations it was far too costly (thousands of $ a month) and the revenue couldn't keep up with the hosting costs...

    Would you mind clarifying exactly what you'd put in those 5 small droplets and any other things I should keep in mind? It sounds like I need to make sure I'm doing database backups for when it's time to move to the dedicated DB servers. Also, I am not sure what you mean by RabbitMQ and private network.

    When it comes to Load Balancing, do you think just NGINX will suffice for now or should I use DigitalOcean's Load Balancing across droplets? I think I'd only need NGINX because I only have that one entry point anyway.

    Thanks!

We're planning on using a similar structure to you. Be great to understand your thought process behind this structure.

You mention you have an NGINX in front, I presume this is acting as the API gateway which then points to the differing services? Or is this load balancing with a different Node server as the API Gateway?

In terms of chat vs auth services, would it not be better to swap round the types of databases? I would have thought a nosql like MongoDB would be better suited to chat/social media and similarly with Postgres for the Auth service?

  • I was thinking the latter - NGINX load balancing with a Node.js server as the API Gateway, in my case this is a GraphQL API Gateway.

    You're probably right for the Chat vs. Auth services. I just knew I wanted to use MongoDB and PostgreSQL (for my own learning experience as they are the most common databases). For Node.js there are a lot of tutorials on doing JWT auth/building an OAuth2 server with MongoDB (http://scottksmith.com/blog/2014/05/02/building-restful-apis-with-node/), so I just went with one of those. Then I just used PostgreSQL for chat because group chat is pretty relational and I've done it before e.g. tables: channels, messages, messages in channel, users in channel. They could easily be swapped around and MongoDB might even scale better for chat, sure. Something like Cassandra would probably be best though (but I am a one-man team and don't want to get stuck with DevOps complexity!).

    tl;dr: I don't really have a good reason and do whatever I want. :P

Have another answer? Share your knowledge.