boozi
boozi

Reputation: 506

How to load balance correctly and efficiently in AWS

At the moment I have one EC2 Instance (2 CPU, 8GB RAM, Linux) that has on it:

  1. NodeJS Express Server (Backend)
  2. NodeJS "Microservice" Express Server (communicates with APIs etc)
  3. PostgresQL DB
  4. Redis (as a message broker between my server (1) and my Microservice server (2)
  5. ReactJS App (Frontend) that communicates with the server (1)

Now this works fine with low traffic, but as the traffic increases (10k visits in minutes/hours) the whole thing is getting overwhelmed and the CPU is going into the burstable zone. This is also a dangerous approach, as all my functionality is on one instance. As a fast solution I clustered the server (1) using my PM2 manager and it's working a bit better now. But as a long term solution I need to split the things and use load balancing. This is how I thought to split it into different EC2 instances:

  1. NodeJS Express Server (Backend) + NodeJS Express Server (Backend) + Load Balancer between both - each with 512MB RAM, 1 CPU
  2. NodeJS "Microservice" Express Server - 512MB RAM, 1 CPU
  3. PostgresQL on AWS RDS (1GB RAM, 1CPU)
  4. Redis on AWS ElastiCache (cache.t2.micro)
  5. ReactJS App (Frontend) - 512MB RAM, 1 CPU

Now I have two questions:

Upvotes: 0

Views: 434

Answers (1)

mcfinnigan
mcfinnigan

Reputation: 11638

  1. you need two instances of each of your services, so that's 2x backend, 2x microservice, 2x frontend, preferably running in different availability zones.
  2. LB between each pair of services
  3. service A calls LB for service B, never service B directly.

this means you always have at least one healthy instance of each service behind a load balancer, and as you add or remove individual service nodes your DNS records etc remain the same - you can scale your microservice to 3 nodes without needing to change anything anywhere else.

this adds cost, but provides redundancy - which is one of the primary points of using cloud infrastructure.

Upvotes: 1

Related Questions