All posts
Edge
Why the weond edge proxy is written in Rust cover

Engineering note

Why the weond edge proxy is written in Rust

Tomas Berg3 min readEdge

A request has roughly 15 milliseconds to be understood, authorized, routed and answered. Here is why we rewrote our edge layer in Rust — and what we gave up to get there.

Every request to a weond project passes through the same edge layer: TLS termination, host resolution, cache lookup, redirect rules and finally a proxy hop to the healthy release. That path is short, but it is also the one place where a small inefficiency is multiplied by every visitor of every project.

We used to run this layer as a Node service. It worked, but the cost of garbage collection and per-request allocation showed up in the p99 numbers long before it showed up in our bill.

What the edge actually does

Before choosing a language, we wrote down the work a single request performs:

  • Terminate TLS 1.3 and parse the HTTP request.
  • Resolve the hostname to a project and environment.
  • Apply canonical redirects and preview password gates.
  • Check the cache and negotiate Brotli or Gzip variants.
  • Choose a healthy release and proxy the request.

None of these steps need a garbage collector. They need predictable memory, predictable latency and a way to fail without taking down a worker.

The edge is not a place for clever code. It is a place for code that does the same thing every time.

The rewrite

The new proxy is a small Rust binary built around an async runtime and a precompiled route table. Hostnames are resolved through an immutable snapshot that is swapped atomically when the control plane publishes a change. There is no lock on the hot path.

let route = snapshot.resolve(host)?;
let upstream = route.healthy_release();

proxy::forward(req, upstream, route.policy()).await

Static assets are served with ETag negotiation and precompressed variants, so the common case never touches an application container. Dynamic requests are proxied with connection reuse and a bounded queue, which keeps a slow upstream from exhausting edge workers.

What we measured

After the migration, the p50 request overhead dropped from 21ms to 6ms in our benchmark, and the p99 became far less noisy. More importantly, memory usage is flat under load: a worker that has served ten million requests looks the same as one that has served ten.

The trade-off is real. Rust is slower to iterate in, and every new routing rule needs tests. We accepted that because the edge changes less often than the application platform, and because correctness at this layer is worth the friction.

You can see the result on any project domain: the pricing page itself is served through the same proxy. If you want to inspect the headers, curl -I is enough.

Edge network heat map

What comes next

The next step is regional route snapshots, so a control-plane update in one region does not wait for a global publish. After that, we want to expose edge timing in the dashboard next to build and runtime logs — one timeline from git push to the browser.