{"id":29664126,"url":"https://github.com/mohanad-80/load-balancer","last_synced_at":"2026-05-04T20:33:11.653Z","repository":{"id":301283164,"uuid":"1000258732","full_name":"mohanad-80/load-balancer","owner":"mohanad-80","description":"A simple HTTP round robin load balancer with health checks built with Node.js and Express.","archived":false,"fork":false,"pushed_at":"2025-06-26T03:38:05.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-26T04:29:55.174Z","etag":null,"topics":["expressjs","load-balancer","nodejs","round-robin-algorithm"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mohanad-80.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-11T13:58:14.000Z","updated_at":"2025-06-26T03:38:08.000Z","dependencies_parsed_at":"2025-06-26T04:29:56.851Z","dependency_job_id":"3c40a5fb-1f4e-4d9a-9899-3b997644a9c6","html_url":"https://github.com/mohanad-80/load-balancer","commit_stats":null,"previous_names":["mohanad-80/load-balancer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mohanad-80/load-balancer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohanad-80%2Fload-balancer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohanad-80%2Fload-balancer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohanad-80%2Fload-balancer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohanad-80%2Fload-balancer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mohanad-80","download_url":"https://codeload.github.com/mohanad-80/load-balancer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mohanad-80%2Fload-balancer/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266489630,"owners_count":23937367,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expressjs","load-balancer","nodejs","round-robin-algorithm"],"created_at":"2025-07-22T12:06:31.177Z","updated_at":"2026-05-04T20:33:06.621Z","avatar_url":"https://github.com/mohanad-80.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Load Balancer\n\nA 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.\n\n## Architecture Diagram\n\n![Load Balancer Architecture](./load-balancer-diagram.svg)\n\n## Features\n\n- **Round-robin load balancing** across multiple backend servers\n- **Health checks** for backend servers (via `/health` endpoint)\n- **Automatic failover**: unhealthy servers are skipped until healthy again\n- **Detailed logging** of incoming requests and backend responses\n- **Handles all HTTP methods and paths**\n- **Graceful shutdown** on SIGINT\n- **Persistent connections** to backends using HTTP keep-alive\n- **Add relevant forward headers for proxy best practice** (client IP, protocol, host, port)\n- **Sanitize the client request and response headers for security**\n- **Customizable keep-alive and maxSockets settings**\n- **Detailed logging for errors and useful info**\n\n## Getting Started\n\n### Prerequisites\n\n- [Node.js](https://nodejs.org/) (v16 or newer recommended)\n- [npm](https://www.npmjs.com/)\n\n### Installation\n\n1. Clone the repository:\n\n   ```bash\n   git clone https://github.com/mohanad-80/load-balancer.git\n   cd load-balancer\n   ```\n\n2. Install dependencies:\n   ```bash\n   npm install\n   ```\n\n### Running Backend Servers\n\nStart multiple backend servers on different ports (e.g., 3001, 3002, 3003):\n\n```bash\nPORT=3001 node be.js\nPORT=3002 node be.js\nPORT=3003 node be.js\n```\n\nYou can use multiple terminals or a process manager like [pm2](https://pm2.keymetrics.io/).\n\n### Running the Load Balancer\n\nStart the load balancer (listens on port 3000 by default):\n\n```bash\nnode lb.js\n```\n\n### Usage\n\nSend HTTP requests to the load balancer:\n\n```bash\ncurl http://localhost:3000/\n```\n\nRequests will be forwarded to healthy backend servers in round-robin order.\n\n## Project Structure\n\n- `lb.js` - Main load balancer logic\n- `be.js` - Simple backend server for testing\n- `package.json` - Project metadata and dependencies\n\n## Customization\n\n- Edit the `servers` array in `lb.js` to add or remove backend servers.\n- Adjust health check interval or timeout as needed.\n- Tune keep-alive and `maxSockets` settings in the custom HTTP agent.\n- Add or modify forwarded headers as needed for your environment.\n\n## Logging\n\n- Logs which backend server handled each request.\n- Logs backend response times.\n- Logs health check status changes for each backend.\n- Logs errors and timeouts with details.\n\n## License\n\nThis project is licensed under the MIT License. See [LICENSE](./LICENSE) for details.\n\n---\n\n**Author:** Mohanad Ahmed\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohanad-80%2Fload-balancer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmohanad-80%2Fload-balancer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmohanad-80%2Fload-balancer/lists"}