-
You have 3 "Express" servers and a "load balancer" sitting infront of them.
-
This command "curl http://localhost:80" calls the load balancer, then the load balancer will forward that request to servers according to RR (Round Robin) algorithm:
-
1st request => 1st server
-
2nd request => 2nd server
-
3rd request => 3rd server
- clone the repo
- npm install
- Generate ".env" file and allocate these variables to unused ports on your local machine:
- SERVER_PORT=
- LOAD_BALANCER_PORT=
- SECOND_SERVER_PORT=
- THIRD_SERVER_PORT=
- npm run dev
-
Once you run the command "npm run dev".
-
When you send an HTTP request to the load balancer by:
-
It will forward the request to the active servers and you will get hello from server...
according to RR algorithm. -
This command is responsible for checking the health of server:
-
when you run the previous command you will get a response contains details abt you server.
-
Try to kill one of the servers(by uncommenting "throw new Error()" in "healthChecker.ts") and run this cmd:
-
curl http://localhost:PORT_NUMBER/health-check
and the broken server will be out.
docker build -t image-name:tag .
docker run -itd -p host_port:container_port --env-file .env image-name:tag
docker-compose up -d