Load balancers

HTTP or TCP traffic spread across apps, with health checks and weights.

Overview

A load balancer has one address and spreads traffic across apps’ replicas, skipping any that fail its health check. Weights let you move traffic between versions gradually.

When to use it

  • One address for an app with several replicas.
  • Shifting traffic from one service to another by weight.
  • Balancing TCP for something that isn’t HTTP.

How it works

HAProxy 3.2
One HAProxy container per load balancer, pinned by digest, in master-worker mode.
Graceful reloads
A new configuration is checked first, then loaded without dropping established connections.
Health checks
TCP connection or HTTP request checks per replica; algorithms round robin, fewest connections or same client to the same replica.

The load balancer joins its targets’ network and follows each target app’s replicas by name. When apps deploy or scale, its configuration is rendered again, checked and reloaded in place.

Architecture

Load balancers architectureOne address in front of several replicas; a failing replica gets no traffic.no trafficClientsHAProxyfront · port 8080api replica 1api replica 2api replica 3failing check: skipped
One address in front of several replicas; a failing replica gets no traffic.
  • Clients to HAProxy
  • HAProxy to api replica 1
  • HAProxy to api replica 2
  • HAProxy to api replica 3: no traffic

Flows

A request

  1. A client connects to the load balancer’s address.
  2. HAProxy picks a healthy replica by the algorithm and weights.
  3. The replica answers through it.

Set it up

In the console

  1. Open Load balancers and choose New load balancer.
  2. Choose HTTP or TCP and the port.
  3. Add target apps with weights.
  4. Choose the health check and Create.

With the CLI

enclave lb create front --port 8080 --target api --wait

With OpenTofu

OpenTofu configuration
resource "enclave_load_balancer" "front" {
  name = "front"
  port = 8080
  target = [
    { app = "api" },
  ]
}

Settings reference

Every setting and output of the OpenTofu resource; the console and the CLI use the same names in their own words. Generated from platform 4d30582.

enclave_load_balancer
NameTypeUseWhat it does
nametextrequiredName of the load balancer: 3–40 lowercase letters, digits or hyphens, starting with a letter. Changing it replaces the load balancer.
portnumberrequiredPort it listens on.
targetlist of objectsrequiredApps to send traffic to (1–8, one network).
algorithmtextoptionalround_robin (default), least_conn or source.
health_checklist of objectsoptionalHow replicas are checked (default: tcp every 2 s).
machinetextoptionalThe machine to run on (default: EnclaveStack chooses, and this reads back its choice). Changing it moves the resource, with its data, in place; apply waits for the move.
machine_labelsmap of textoptionalLabels the machine must have, when machine isn't set (key=value, all must match).
projecttextoptionalThe project to create it in. Defaults to the provider's project (ENCLAVE_PROJECT, else default). Changing it replaces the resource.
protocoltextoptionalhttp (default) or tcp.
publishtrue or falseoptionalAlso listen on a host port.
healthy_targetsnumberoutputReplicas passing their checks (refreshed on read).
host_portnumberoutputPort on this machine when published.
idtextoutputResource ID.
internal_hosttextoutputHost other resources in the network use.
private_dnstextoutputName it answers to inside its network: <name>.loadbalancer.internal.

Limits and security

Good to know

  • Targets must be in the same network as the load balancer.

Security

  • Firewalls on target apps allow their load balancers on the target ports automatically.