A Load balancer implementation in GO from John Cricket coding challenges
A simple implementation of a load balancer using the round-robin algorithm in GO. Part of my attempt at John Crickett's Coding Challenges.
I wrote a walk-through article on how to build from scratch here
- Round-robin algorithm.
- Development and Production mode.
- Dummy server created when a load balancer is started in dev mode.
- A config.json file to pass in server configuration.
- Loads DB for disk on startup.
- Asynchronous implementation using goroutines.
- Easy to use and extend.
-
Clone the repository:
git clone https://github.com/Fuad28/load-balancer.git cd load-balancer
-
Install dependencies:
go get
-
Edit the config.json file in the root folder:
- Sample dev config
{ "env": "dev", "port": 8000, "numberOfServers": 3, "randomServerOff": true }
- Sample prod config
{ "env": "prod", "port": 8000, "servers": [ { "address": "https://www.google.com/", "healthCheckPath": "/" }, { "address": "https://www.netflix.com/ng/", "healthCheckPath": "/" } ] }
-
Start the server:
go run .
-
The server begins to run on localhost port 8000. You can then test by sending a request
curl http://localhost:8000/
You observe that each time, a different server responds.
- Server