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:
- Dynamic-config routes by host + path (
dc.Routes) - Dynamic-config host upstreams (
dc.HostUpstreams[host]) - Static host upstreams (
cfg.HostUpstreams) - Dynamic-config POP upstreams (
dynconfig.POPUpstreams) - Static POP upstreams (
cfg.POPUpstreams) - 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:
X-Veloflux-Client-PopX-Edge-PopCF-Ray(-POPsuffix)Fly-Region
This enables proximity steering, multi-edge and multi-region setups.
Load-balancing strategies#
| Strategy | How it works | Use when |
|---|---|---|
round_robin | Distributes requests in sequence, evenly across targets | Equal-capacity servers, stateless apps |
least_conn | Sends to the server with the fewest active connections | Long-lived connections, WebSockets, streaming |
least_time | Sends to the lowest-latency server (aliases: adaptive, least_latency) | You want the fastest server right now |
ip_hash | Routes by client IP (sticky sessions) | Stateful apps, session persistence |
weighted | Distributes by weights (implemented by duplicating entries in the array) | Heterogeneous servers (different CPU/RAM) |
single | Always the same target | One backend per upstream |
failover | Uses the first healthy target; others only engage if it fails | Active-passive, backup origin |
Examples
Round robin across three backends:
{ "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:
{ "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:
Client 192.168.1.1 -> always Server AClient 192.168.1.2 -> always Server BRetry 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 (TTLCIRCUIT_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 withis_healthy=trueenter 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.