Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/prayag2003/go-load-balancer
Implemented a Round-Robin Load Balancer in GoLang
https://github.com/prayag2003/go-load-balancer
Last synced: 23 days ago
JSON representation
Implemented a Round-Robin Load Balancer in GoLang
- Host: GitHub
- URL: https://github.com/prayag2003/go-load-balancer
- Owner: Prayag2003
- Created: 2024-03-19T08:01:15.000Z (10 months ago)
- Default Branch: main
- Last Pushed: 2024-03-19T08:04:54.000Z (10 months ago)
- Last Synced: 2024-06-20T22:29:08.550Z (7 months ago)
- Language: Go
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Load Balancer in Go
This is a simple implementation of a load balancer in Go, capable of distributing HTTP requests among multiple backend servers. The load balancer uses round-robin scheduling to evenly distribute requests among the available servers.
## Usage
1. **Clone the Repository**: Clone this repository to your local machine.
2. **Build and Run**: Navigate to the directory containing the `main.go` file and build the project using the following command:
```bash
go build main.go
```Then, run the executable:
```bash
./main
```Alternatively, you can run the application directly without building:
```bash
go run main.go
```3. **Accessing the Load Balancer**: The load balancer listens on port 8000 by default. You can access it through `http://localhost:8000`.
## Code Explanation
The main components of the load balancer include:
- **Server Interface**: Defines the methods required for a server.
- **Simple Server**: Implements the `Server` interface and represents a backend server.
- **Load Balancer**: Manages multiple backend servers and distributes incoming requests.
- **getNextAvailableServer()**: Determines the next available server to handle the request using round-robin scheduling.
- **serveProxy()**: Forwards incoming requests to the appropriate backend server.
- **Main Function**: Initializes the load balancer with sample backend servers and starts the HTTP server to listen for incoming requests.## Sample Backend Servers
The load balancer is initialized with the following sample backend servers:
- [YouTube](https://www.youtube.com)
- [DuckDuckGo](https://www.duckduckgo.com)
- [Bing](https://www.bing.com)## Dependencies
This project utilizes standard Go libraries and does not require any external dependencies.
## Contributing
Contributions are welcome! Feel free to fork this repository and submit pull requests for any improvements or features you'd like to add.