Liebe is a lightweight, configurable load balancer written in
that distributes traffic across multiple identical API instances, with built‑in health checks and simple routing strategies.
Configuration lives in liebe-config.json at the project root:
{
"health_check": {
"path": "/health",
"interval": "5",
"timeout": "2"
},
"strategy": "round_robin",
"upstreams": [
"http://localhost:8081",
"http://localhost:8082",
"http://localhost:8083"
]
}- health_check.path: endpoint called on each upstream (e.g.
/health). - health_check.interval: every X seconds, Liebe checks all upstreams.
- health_check.timeout: maximum time allowed for a response to be considered valid.
- strategy: load‑balancing strategy (currently available):
"round_robin": cycles through healthy upstreams in order, one request at a time."random": picks a healthy upstream at random for each request."least_connections": always routes to the healthy upstream with the fewest in‑flight requests."least_response_time": prefers healthy upstreams with the lowest average response time.
- upstreams: list of API instances that will receive traffic.
- On startup, Liebe loads
liebe-config.jsonand validates the strategy. - In a loop, a health check calls the configured endpoint on every upstream:
- if it returns
200beforetimeout, the upstream is marked healthy; - otherwise it is marked unhealthy and detailed in the logs.
- if it returns
- For each incoming request on
:8080, Liebe picks a healthy upstream according to the strategy and proxies the request to it.
- All URLs listed under
upstreamsmust point to running API instances. - Each upstream must expose the health endpoint defined in
health_check.path(e.g./health) that returns HTTP200when the instance is available.
If you want to quickly spin up multiple API instances for testing, you can try my tool Mirage.
Check the Mirage documentation to design mock APIs from a JSON file and launch one or many instances in no time.