Skip to content

mohanad-80/load-balancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Load Balancer

A simple HTTP load balancer built with Node.js and Express. It distributes incoming requests to multiple backend servers using a round-robin algorithm and performs periodic health checks to ensure requests are only sent to healthy servers.

Features

  • Round-robin load balancing across multiple backend servers
  • Health checks for backend servers (via /health endpoint)
  • Automatic failover: unhealthy servers are skipped until healthy again
  • Detailed logging of incoming requests and backend responses
  • Handles all HTTP methods and paths
  • Graceful shutdown on SIGINT

Getting Started

Prerequisites

Installation

  1. Clone the repository:

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

    npm install

Running Backend Servers

Start multiple backend servers on different ports (e.g., 3001, 3002, 3003):

PORT=3001 node be.js
PORT=3002 node be.js
PORT=3003 node be.js

You can use multiple terminals or a process manager like pm2.

Running the Load Balancer

Start the load balancer (listens on port 3000 by default):

node lb.js

Usage

Send HTTP requests to the load balancer:

curl http://localhost:3000/

Requests will be forwarded to healthy backend servers in round-robin order.

Project Structure

  • lb.js - Main load balancer logic
  • be.js - Simple backend server for testing
  • package.json - Project metadata and dependencies

Customization

  • Edit the servers array in lb.js to add or remove backend servers.
  • Adjust health check interval or timeout as needed.

License

This project is licensed under the MIT License. See LICENSE for details.


Author: Mohanad Ahmed

About

A simple HTTP round robin load balancer with health checks built with Node.js and Express.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published