Skip to content
VELOFLUX docsOpen dashboard

Home / Routing & load balancing

Routing & load balancing

Host and path routing, POP steering, all seven load-balancing strategies, retry, circuit breaker and WebSocket support.

The Proxy Edge decides, for each request, which upstream receives the traffic. The decision combines routing (host and path), POP steering and the upstream's balancing strategy.

Destination selection precedence#

The central function is ReverseProxy.chooseUpstream. Precedence:

  1. Dynamic-config routes by host + path (dc.Routes)
  2. Dynamic-config host upstreams (dc.HostUpstreams[host])
  3. Static host upstreams (cfg.HostUpstreams)
  4. Dynamic-config POP upstreams (dynconfig.POPUpstreams)
  5. Static POP upstreams (cfg.POPUpstreams)
  6. Default upstream (DefaultUpstream)

Host and path routing#

  • By host: each domain has its upstreams. The proxy resolves the request host and applies that domain's configuration.
  • By path: routes (routes.path_pattern) send different paths to different upstreams — for example, /api/* to the API backend and / to the frontend.

POP steering#

Routes support pop_upstreams per route. When a mapping exists for the detected POP, it takes priority over the route's generic upstreams. If there is no mapping for that POP, the proxy falls back automatically to the default set.

The POP is detected from headers, in this order:

  1. X-Veloflux-Client-Pop
  2. X-Edge-Pop
  3. CF-Ray (-POP suffix)
  4. Fly-Region

This enables proximity steering, multi-edge and multi-region setups.

Load-balancing strategies#

StrategyHow it worksUse when
round_robinDistributes requests in sequence, evenly across targetsEqual-capacity servers, stateless apps
least_connSends to the server with the fewest active connectionsLong-lived connections, WebSockets, streaming
least_timeSends to the lowest-latency server (aliases: adaptive, least_latency)You want the fastest server right now
ip_hashRoutes by client IP (sticky sessions)Stateful apps, session persistence
weightedDistributes by weights (implemented by duplicating entries in the array)Heterogeneous servers (different CPU/RAM)
singleAlways the same targetOne backend per upstream
failoverUses the first healthy target; others only engage if it failsActive-passive, backup origin

Examples

Round robin across three backends:

json
{  "name": "api-backend",  "strategy": "round_robin",  "targets": [    { "url": "https://backend-1.example.com:8080" },    { "url": "https://backend-2.example.com:8080" },    { "url": "https://backend-3.example.com:8080" }  ]}

Weighted — server A receives more traffic than B:

json
{  "name": "api-backend",  "strategy": "weighted",  "targets": [    { "url": "https://backend-1.example.com:8080", "weight": 3 },    { "url": "https://backend-2.example.com:8080", "weight": 2 }  ]}

IP hash — the same client always lands on the same server:

text
Client 192.168.1.1 -> always Server AClient 192.168.1.2 -> always Server B

Retry and circuit breaker#

  • On an upstream failure, the proxy increments metrics and logs, marks the failure and tries alternatives with backoff (RETRY_ATTEMPTS, RETRY_BACKOFF_MS).
  • When the failure threshold is reached (CIRCUIT_BREAKER_FAILS), the target is temporarily ejected (TTL CIRCUIT_BREAKER_TTL_SEC) and stops receiving traffic until it recovers.
  • If no healthy alternative exists, the proxy answers 502 with an error page.
  • The upstream health_config (probe enabled, path, timeout and threshold) is converted into the effective probe policy and applied in the data plane. Only origins with is_healthy=true enter the edge configuration snapshot.

WebSocket#

VeloFlux supports WebSocket: the proxy dials TCP/TLS to the upstream, sends the upgrade handshake, hijacks the client connection and keeps a bidirectional tunnel. For long-lived connections, prefer the least_conn strategy.

Multi-edge and Anycast#

The platform supports multi-edge, Anycast and multi-provider topologies: several edge nodes, in different regions, serving the same domains, with health- and performance-based steering and failover between nodes. See also Edge & BYOS and Domains & DNS.