eBPF XDP Load Balancing Cuts Tail Latency 40%

Networking
Date:December 2, 2026
Topic:
eBPF XDP Load Balancing Cuts Tail Latency 40%
⏱ 2 min read

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.

c
SEC("xdp")
int xdp_lb(struct xdp_md *ctx) {
    void *data = (void *)(long)ctx->data;
    void *end = (void *)(long)ctx->data_end;
    struct ethhdr *eth = data;
    if ((void *)eth + sizeof(*eth) > end) return XDP_PASS;
    
    __u32 key = bpf_ntohs(eth->h_proto) ^ ctx->rx_queue_index;
    __u32 *cpu = bpf_map_lookup_elem(&cpu_map, &key);
    if (!cpu) return XDP_PASS;
    
    return bpf_redirect_map(&cpumap, *cpu, 0);
}

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.

MetricHAProxy (16C)XDP + AF_XDP (16C)Delta
p50 latency12ms11ms-8%
p99 latency180ms108ms-40%
CPU cycles/pkt~45k~18k-60%
Max throughput1.2M RPS2.8M RPS+133%
💡
TipPin XDP programs to isolated CPUs via <code>taskset</code> or <code>cset</code>. Disable IRQ balance. Use <code>ethtool -L</code> to match RX queues to worker count. NUMA locality matters — keep NIC, memory, and CPU on same node.

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.


âœĻ
â„šī¸
NoteNext step: Clone <code>github.com/xdp-project/xdp-tutorial</code>. Run the <code>redirect_map</code> lab on a two-queue NIC. Measure p99 with <code>wrk -t4 -c100 -d30s --latency</code>. Then replace the hash with your sharding logic. Ship the diff.
Share𝕏 Twitterin LinkedInin Whatsapp