Skip to content

cmtdrt/Liebe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Liebe

Liebe is a lightweight, configurable load balancer written in Go that distributes traffic across multiple identical API instances, with built‑in health checks and simple routing strategies.

Configuration

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.

How it works

  1. On startup, Liebe loads liebe-config.json and validates the strategy.
  2. In a loop, a health check calls the configured endpoint on every upstream:
    • if it returns 200 before timeout, the upstream is marked healthy;
    • otherwise it is marked unhealthy and detailed in the logs.
  3. For each incoming request on :8080, Liebe picks a healthy upstream according to the strategy and proxies the request to it.

Prerequisites

  • All URLs listed under upstreams must point to running API instances.
  • Each upstream must expose the health endpoint defined in health_check.path (e.g. /health) that returns HTTP 200 when the instance is available.

Quick test

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.

Example (using round robin)

image

About

A load balancer with a selectable balancing strategy

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors