All work

Go load balancer · Case study

A small load balancer. A closer look at shared state.

A Layer 7 load balancer written in Go that distributes HTTP requests across backend servers. The project explores round-robin routing, concurrent shared state, and background health checks.

Role
Personal systems project
Context
Public source available

My contribution

I built this personal systems project in Go to explore HTTP routing and concurrent shared state. The implementation combines a standard-library reverse proxy, round-robin selection, mutex-protected state, and background backend-health checks.

How requests move

The implementation uses Go’s standard-library HTTP reverse proxy. A shared round-robin index selects the next backend whose health flag is marked alive. If no backend is available, the handler responds with HTTP 503 Service Unavailable.

Protecting shared state

Concurrent requests share the routing index, which is protected by a mutex. Each backend’s alive flag has its own read/write mutex. These locks coordinate access between request handlers and the background health-check goroutine.

Checking backends

A background loop checks the configured backends every five seconds using a TCP connection with a two-second timeout. This tests whether a connection can be made, rather than whether the application itself is healthy. Backends start marked alive until a health check updates their state.

Limits of the implementation

The repository provides a small local setup with three backend addresses. A failed backend can still receive traffic between checks. Health checks test TCP connectivity rather than application health, and failed requests are not automatically retried. This is a local systems project, not a production-hardened service.

What this project demonstrates

The source makes the routing decision and its concurrency constraints easy to inspect: a round-robin index, per-backend health state, a background check loop, and an HTTP proxy. Its value here is as a personal systems project with a deliberately small scope.

Technologies & references

  • Go
  • net/http
  • httputil.ReverseProxy
  • sync.Mutex
  • sync.RWMutex
  • Goroutines

Let’s talk

Building something useful?

I’m interested in software engineering opportunities across backend systems and AI. If that sounds like your team, I’d like to hear from you.

Email me