Zero allocations, one thread — a simpler load balancer

zoxy 1.0 reserves every byte it will use at startup and serves from one thread. Why a load balancer can be built that way, how HAProxy and Pingora are built instead, and what each choice costs.

zoxy 1.0 is out. It’s a load balancer in Zig with two rules that everything else follows from: nothing allocates after startup, and when something runs out, the newest work gets a fixed answer at a fixed point. A third choice comes with them: one thread, one event loop, one io_uring.

Most proxies are built the other way. They allocate as traffic arrives and use every core from one process. HAProxy and Pingora are both very good at that, and this post isn’t about them being wrong. It’s about what a load balancer actually needs, what the simpler shape gets you, and what it costs.

The work is countable#

For every request, a load balancer reads a head, picks an origin, writes a head, and copies a body across. None of that needs memory whose size depends on the request, as long as heads have a size limit (8 KiB by default) and bodies stream through fixed buffers instead of being held. So the memory a load balancer needs isn’t a function of the traffic. It’s a function of how much traffic is in flight at once, and that you can cap.

zoxy turns the caps into a budget. Every pool is sized from the config, the sizes add up, and the process prints the sum before it takes a port:

$ zoxy --check config.json
zoxy 1.2.0
budgets (DESIGN.md §5/§8; closed-form except where marked):
  memory  total 47926 KiB = conn slots 1386 x 600 B + stream slots 1386 x 1904 B
          + relay buffers 1386 x 32808 B
          + upstream slots 1311 x 56 B + head buffers 0 x 8192 B (+ ring 0 B)
          + …
  fds     4093 required (asserted against RLIMIT_NOFILE)
  ring    4096 entries, completion queue 8192, in-flight ops <= 5559
  check   config.json: valid, and this box can start it

--check exits with 0 when this machine can run the config, 1 when the config is wrong, and 2 when the config is right but the machine can’t fit it. That’s the first thing zero allocation buys: the most memory the proxy will ever use is a number you can see in CI, before it serves anything.

The catch is just as plain: you pay for the peak up front. What keeps that affordable is making an idle connection cost almost nothing. A keep-alive connection that isn’t sending anything holds a connection slot and a stream slot, and no buffer at all. Its receive is armed without one, and the kernel picks a buffer from a shared ring only when bytes arrive:

The buffer belongs to the request, not to the connection

So the pools are sized for requests in flight, not for connections open. For the config above, that’s 1,386 at once in about 47 MiB.

Three shapes#

Here’s how the three are put together, drawn the way they run on one machine:

Where a request's memory comes from, and who can use a parked origin connection

HAProxy is one process with a thread per CPU by default, and “each thread has its own polling loop and scheduler”. A new connection goes to whichever of a sample of threads has the fewest, and stays there. Memory comes from pools: “Pools are used for runtime allocation; malloc/free are for boot code only.” Each pool is a per-thread cache in front of the system allocator, filled as traffic arrives, so the first busy hour pays for memory that the next one reuses. Buffers are 16 KiB, taken when a stream needs one and handed back when it’s empty. maxconn sizes the file descriptor table at startup and reserves nothing else, so the docs leave the multiplication to you: “about 33 kB of RAM being consumed per established connection”.

When an allocation fails, HAProxy doesn’t fall over. A stream that can’t get a buffer waits in a queue until another stream releases one, and an accept that can’t get memory for its connection closes the socket and pauses the listener for up to 100 ms. That’s graceful, but it’s a queue, and the docs warn that under a long shortage “some tasks may freeze until their timeout expires”.

Pingora is a Rust library rather than a program: you write the proxy as a set of callbacks, and it runs them on tokio. Each service gets its own runtime, by default a work-stealing one, and every accepted connection is a task of its own that any thread may pick up. Memory comes from the allocator as the request goes. Every callback is an async_trait method, which returns a boxed future, and a plain HTTP/1 request goes through about nine of them. On top of that, the request header gets a 4 KiB buffer, the session is boxed (next to the comment // TODO: keepalive pool, use stack), two channels connect the upstream and downstream halves, and body reads get a 32 KiB buffer, sized to “fit jemalloc’s default tcache limit”. The one thing pooled is upstream connections, in a single pool all threads share.

There’s no ceiling on any of it either. Pingora 0.9 has no connection limit (one is on its main branch, opt-in), and when the allocator does fail, Rust’s default is to abort the process. On Linux, with overcommit, the OOM killer usually gets there first.

zoxy is one thread. It owns the io_uring, every pool and all of the work: accepts, TLS handshakes, health probes, metrics scrapes and the access log. To use more cores, you run more processes on the same port with SO_REUSEPORT, and the kernel spreads connections across them. They share nothing.

Running out on purpose#

When a proxy that allocates as it goes runs out of memory, it finds out inside an allocation, in the middle of someone’s request, and has to decide there what to do about it. zoxy finds out at a slot checkout, before anything has been done. Every pool has a rung on what the design calls the ladder, and every rung has an answer:

what runs outnoticed atthe answer
connection slotsaccepta TCP reset; accept stays armed
head buffersthe client’s first byte503, then close
relay buffersafter routing503
upstream slotscheckout503
every endpoint at its in-flight cappicking an origin503
kernel memoryany completionwhatever owned that operation is torn down

Nothing on that list blocks, queues or allocates, and each rung has its own counter. A 503 on a dashboard then says which pool to widen, and “the proxy’s capacity and the origin’s capacity are counted apart”: running out of upstream slots means widen the pool, an endpoint at its cap means the backend is full.

It’s tested the blunt way. The L4 path runs under an allocator that fails every call, and the live gate runs the real binary twice through the same load and fails if resident memory grows by more than 64 KiB between the passes.

One thread#

The other half of the shape is the thread count, and it buys a lot for one decision:

The third one is the reason Pingora exists. Cloudflare moved off NGINX, where “the NGINX connection pool is per worker”, to threads that share one pool: “We chose multithreading over multiprocessing in order to share resources, especially connection pools, easily.” For one big customer, connection reuse went from 87.1% to 99.92%, and new connections to their origins went down 160 times.

Inside one process, zoxy gets the same thing for free. Past one core, it runs into the same wall NGINX did: with N processes there are N pools, and an origin connection parked in one process is no use to a request in another. The design says so in as many words: “Upstream reuse is then per process.”

HAProxy has been here too. It used to run as several processes (nbproc), deprecated that in 2.3 and removed it in 2.5, because it “suffers too many limitations compared to threads”. Its manual still lists them for anyone who runs more than one process: health checks run per process, so servers get as many checks as there are processes; maxconn and queues are per process; stick tables aren’t shared. All of that is true of zoxy’s processes as well.

The bet is that one core goes a long way when nothing on the hot path allocates or locks, so you need far fewer processes than NGINX needed workers, and for many deployments just one.

The other cost is that anything slow blocks everything. An RSA signature during a TLS handshake can take milliseconds, and the loop waits for it. zoxy prefers ECDSA certificates when a client accepts both, resumes sessions to skip signatures, and counts RSA handshakes so you can see them.

What it looks like on one core#

zoxy runs a benchmark every night against HAProxy, nginx, Pingora and Envoy. Each proxy gets one core, a thousand client connections, and an open-loop ramp from 200 to 40,000 requests a second, and every request fetches the same 10 KiB response through a pool of four origins.

Most requests a second each proxy kept up with, on one core
zoxy 1.2.0
23.5k
nginx 1.31
19.6k
haproxy 3.4.8
18.9k
pingora 0.9
10.9k
envoy 1.40.2
8.0k

The nightly run of November 22, 2026, over HTTP/1.1. Kept up: still serving at least 90% of the offered rate.

The same run says where the simple shape doesn’t win. At a light 2,000 requests a second, zoxy has the lowest median latency (0.44 ms), but HAProxy has the best tail: 1.48 ms at p99 against zoxy’s 2.23 ms, and 4.24 ms at p99.9 against 11 ms. And reserving for the peak shows up as memory:

Peak resident memory in the same run, MiB
zoxy
162.6
haproxy
115.9
envoy
94.0
nginx
68.5
pingora
66.3

The container's resident memory as cAdvisor sampled it, kernel and allocator overhead included.

zoxy uses the most memory there. Its pages become resident as traffic first touches them, so a quieter night shows less, but it never goes past the banner’s total. That’s the deal: you pay for the ceiling, and you know the ceiling before you start.

So which one?#

HAProxy if you want the proxy everyone knows, with twenty-five years of features and the best tail latency in that table. Pingora if you’re building your own proxy in Rust and want a framework to hang your code on. zoxy if you want what the proxy will use, and what it will do when that runs out, to be things you can read before it serves its first request.


The whole design is in DESIGN.md, and the benchmark’s method and fairness rules are in zoxy-io/benchmark.