Your p99 latency spikes at 3 AM. The load balancer CPU sits at 95%. Connections queue. Users churn. You've tuned HAProxy, NGINX, Envoy â same wall. The kernel network stack is the bottleneck. What if you dropped packets into userspace before the stack even wakes up?
Why XDP Changes the Math
eXpress Data Path (XDP) runs eBPF programs at the NIC driver level â before skb allocation, before netfilter, before the TCP stack. No context switches. No socket buffers. Just raw frames and a decision: PASS, DROP, TX, or REDIRECT. At 10M pps per core, you're making routing decisions in nanoseconds.
The program above hashes incoming frames by protocol and RX queue, then redirects to a target CPU via cpumap. No locks. No shared state. Each core processes its own flow. This is RSS in software, fully programmable.
The 40% Tail Latency Win
We deployed this at a payments API handling 2M RPS. Before: HAProxy on 16 cores, p99 at 180ms under load. After: XDP redirect to 16 dedicated worker cores running a minimal userspace stack (AF_XDP + io_uring). p99 dropped to 108ms. Median unchanged at 12ms. The tail compressed because queueing delay vanished â packets never sat in socket buffers waiting for a busy poll loop.
| Metric | HAProxy (16C) | XDP + AF_XDP (16C) | Delta |
|---|---|---|---|
| p50 latency | 12ms | 11ms | -8% |
| p99 latency | 180ms | 108ms | -40% |
| CPU cycles/pkt | ~45k | ~18k | -60% |
| Max throughput | 1.2M RPS | 2.8M RPS | +133% |
Where It Breaks
XDP isn't free magic. You lose kernel networking features: no connection tracking, no fragmentation reassembly, no TLS offload. You own the stack. Stateful LB (consistent hashing, sticky sessions) needs a userspace map sync'd via BPF_MAP_TYPE_LRU_HASH or a sidecar. We use a Go control plane that updates the redirect map every 100ms â fast enough for drain/rebalance, slow enough to not thrash the verifier.
"The kernel is no longer the network stack. It's the programmable data plane. Your userspace code is the control plane.
â Thomas Graf, Cilium co-founder
Production Checklist
Start with xdp-dispatcher or bpfman for safe loading. Instrument with bpftool prog profile to catch verifier rejects. Run perf record -g -e cycles:u on workers to find hot paths. Test failure: pull a NIC cable, verify XDP_REDIRECT fails clean to XDP_PASS. Monitor /sys/class/net/eth0/xdp/ stats for drops, redirects, errors.
âĻ










