How manthanguptaa/load-balancer works
Main Components
• Load Balancer Component (“lb” directory): This holds the main load balancer logic that distributes traffic, implements round-robin load balancing, and manages active-passive server health.
• Backend Server Component (“be” directory): These are the backend servers that handle requests. Each provides a /healthcheck endpoint for the load balancer to assess their status.
• Client/Request Source: Represent the incoming requests to the load balancer.
• Health Check Mechanism: The periodic health check functionality used by the load balancer to determine the status of each backend server.
• Configuration Element: (e.g., a list of backend servers configured within the lb/main.go file which could be visualized as part of the load balancer’s setup).
Relationships and Interactions
• Incoming client requests are first directed to the load balancer.
• The load balancer then uses a round-robin algorithm to forward requests to one of the configured backend servers.
• Meanwhile, the load balancer performs periodic health checks (e.g., via the /healthcheck endpoint) on each backend server.
• If a backend is marked as unhealthy (active-passive management), it is not included in the round-robin rotation until it recovers.
Architectural Patterns and Design Principles
• Separation of Concerns: The load balancing logic (lb) is separated from the backend server logic (be).
• Active-Passive Management: Only the servers in a healthy (active) state receive requests.
• Periodic Health Checks: A monitoring loop is implemented to periodically check the status of the servers.
• Round-Robin Scheduling: Simple load distribution algorithm is utilized.
Relevant Technologies and Libraries
• Golang (language/platform)
• HTTP server capabilities (for both load balancer and backend servers)
• Built-in libraries for HTTP handling, scheduling (for periodic checks), and possibly logging.
• Optionally, create a "configuration" note near the Load Balancer showing where the list of backend servers is defined.
Happy Diagramming!