Skip to content

Fuad28/load-balancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A Load balancer implementation in GO from John Cricket coding challenges

Load balancer implementation in GO

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

Features

  • 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.

Installation

  1. Clone the repository:

    git clone https://github.com/Fuad28/load-balancer.git
    cd load-balancer
  2. Install dependencies:

    go get

Usage

  1. 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": "/"
    		}
        ]
    }
  2. Start the server:

    go run .
  3. 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.

Basic example

  • Server
Screenshot 2024-03-11 at 3 52 53 PM
  • Requests

    Screenshot 2024-03-11 at 3 53 57 PM

About

A load balancer implementation in GO

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages