System design paper · 2016

Maglev

Eisenbud, Yi, Contavalli, Smith, Kononov, Mann-Hielscher, Cilingiroglu, Cheyney, Shang and Hosein · NSDI 2016

How Google’s Maglev shares internet traffic over many ordinary servers, and keeps each connection on one server while machines come and go.

Maglev sits between the router and the servers. Only incoming packets pass through it. Replies, which are usually larger, go straight back to the router.

You’ll learn to

  • Trace a packet from the router through a Maglev machine to the server that answers it.
  • Build a Maglev lookup table by hand for three servers and seven slots, then remove a server and count what changes.
  • Explain why a load balancer needs both a memory of recent connections and a lookup table that every machine shares.
  • Name the techniques that let one ordinary server handle small packets at full network speed.

Read first: Consistent hashing

The idea in short

A busy website receives more requests than one machine can handle, and something has to share them out over thousands of servers. Google used to buy special hardware boxes for this. Maglev does it with ordinary servers running software. A router spreads the incoming packets, the small pieces that internet traffic is cut into, over a group of Maglev machines, and each Maglev machine passes every packet on to one of the servers that do the real work.

Two ideas keep a connection on one server even when machines are added, removed or fail. Each Maglev machine remembers where it sent each recent connection. And every Maglev machine holds an identical lookup table, a long list of slots that each name a server, built so that the servers get almost equal shares and removing one changes very few slots. The addresses and port numbers in a packet pick a slot, so a machine with no memory of the connection still makes the same choice.

The problem

A service like Google Search or Gmail receives far more traffic than one machine can handle. To cope, Google runs each service on many servers, in clusters of machines in several places around the world. Inside a cluster, traffic has to be shared out evenly, or some servers will be overloaded while others sit idle.

That is the job of a . It sits between the routers, the devices that move traffic around a network, and the servers. Traffic arrives as packets: small chunks of data, at most about 1,500 bytes each, every one addressed to a destination. For each packet the load balancer works out which service it is for and forwards it to one of that service’s servers. The paper calls these servers service endpoints. We call them backends.

For years load balancers were dedicated hardware boxes. The authors list four limits:

  • Capacity. One box can only handle so much, and Google’s traffic grew faster than any box could.
  • Availability. Boxes were often deployed in pairs, so a failure was covered by exactly one spare. The paper calls this 1+1 redundancy.
  • Flexibility. A hardware box is hard, often impossible, to change, so trying a new feature was slow.
  • Cost. More capacity meant buying a new box and installing it physically.

Google already had clusters full of ordinary servers. So the authors asked whether the load balancer could be a program running on some of them. Say there are N Maglev machines and each can handle T packets a second. Total capacity is then N × T, so adding a machine adds T, and the load balancer grows by adding ordinary servers. The paper describes the redundancy as N+1: N machines plus one spare.

Two things make this hard.

The first is speed. If each machine handles few packets a second (a small T), the load balancer needs far more machines for the same total, and the paper warns it becomes uneconomical. Ordinary server software is not built to handle small packets at the rate a busy network delivers them.

The second is connection persistence. A connection is a conversation between a user and a server, such as loading one web page over . It is made of many packets, and all of them must reach the same backend. If a packet suddenly arrives at a different backend, that backend knows nothing about the conversation and the connection breaks. Clusters are dynamic and failures are common, so the set of machines will change in the middle of connections.

Maglev has run at Google since 2008. The paper says it now serves almost all of Google’s incoming user traffic. The question it answers is this: how can a group of ordinary servers running software take all of a huge service’s traffic, at full speed, and keep every connection on one backend while machines are added, removed and fail?

The design choices

Everything in Maglev follows from a few decisions.

Our biggest sale ever · Black Friday

Flat 50% Off

Pro

Continue reading

Unlock every course, now and later

  • System Design, live
  • AI Engineering, live
  • Data Engineering, live
  • Machine Learning Engineering, live
  • Inference Engineering, coming soon
  • AI Research, coming soon
  • Performance Engineering, coming soon
  • Agent & Harness Engineering, coming soon
  • LLM Fine-tuning, coming soon
  • LLM Pre-training & Post-training, coming soon
  • Reinforcement Learning, coming soon
  • AI Infrastructure & Platform Engineering, coming soon
  • AI Evaluation & Safety, coming soon
  • Forward Deployed Engineering, coming soon
  • Cloud Computing, coming soon
  • DevOps, coming soon

50% off · Annual and Lifetime

BLACKFRIDAY50Applied at checkout

Choose a plan

About the paper

Maglev: A Fast and Reliable Software Network Load Balancer by Eisenbud, Yi, Contavalli, Smith, Kononov, Mann-Hielscher, Cilingiroglu, Cheyney, Shang and Hosein, NSDI 2016.

Read the original paper

More System design papers

All papers