System design paper · 2009

Cassandra

Lakshman and Malik · LADIS 2009

How Facebook built a database that takes billions of writes a day, keeps copies on many servers and has no single machine to lose.

A write can arrive at any server. That server finds the three servers that keep copies of the key and answers once two of them confirm. Two of three is a majority (our example numbers).

You’ll learn to

  • Describe how data is placed around a circle of servers, and how a new server takes over part of the busiest one’s share.
  • Trace a write from the log on disk to the sorted files that hold it, and say why it never has to read old data first.
  • Explain how a majority vote on copies, timestamps and a failure detector keep the cluster useful while servers are down.
  • Name what Apache Cassandra kept from the paper and what it changed, such as transactions and many positions per server.

Read first: Dynamo, Bigtable

The idea in short

Facebook had to store billions of new messages a day for its inbox search, and keep working when servers, or a whole data centre, failed. Cassandra, built by Avinash Lakshman and Prashant Malik, joined two earlier designs: Amazon’s Dynamo, for spreading copies of data over many servers, and Google’s Bigtable, for how each server stores its share.

Any server can take any request, so no single machine is needed to serve it. A write is added to a log and kept in memory, then saved to disk in sorted files, so it never has to read old data first. When copies disagree, the newest timestamp wins. The open-source database has since added transactions, many positions per server and much more.

The problem

In 2008 Facebook added a feature that let people search their message inbox. It launched in June 2008 for about 100 million users. By the time the paper was written it had passed 250 million. Every message sent or received had to be added to a search index, so the system took in billions of writes a day, and the number grew with the number of users.

The feature offered two kinds of search. In a term search, a user types a word and gets the messages that contain it. In an interactions search, the user types a person’s name and gets every message they have exchanged with that person. Both had to answer quickly while new messages kept arriving. That mix, a steady stream of writes and quick reads on the same data, is the workload the rest of the guide is built around.

Two other facts shaped the design. Facebook ran tens of thousands of servers in many data centres, and the authors treated failure as normal: at that size, some servers and some network links are always broken. And users were served from data centres around the world, so copies of the index had to live in more than one place to keep searches fast.

The authors looked at what existed. Replicated relational databases give strong consistency, but the paper says they are limited in scale and availability. Two newer designs came close, and each missed in one place:

  • Dynamo, Amazon’s store for shopping carts, spread data over many servers with no leader. It tracks conflicting updates with version labels called vector clocks, and the paper notes that a write in Dynamo needs a read first: the new label is built from the old one. That is costly when writes far outnumber reads. (The Dynamo guide covers it in full.)
  • Bigtable, Google’s table store, handled a huge write load and stored data in a way that suited disks. But it handed the job of keeping data safe to a separate storage layer, whereas Cassandra keeps the copies itself. (The Bigtable guide covers it.)

So the question was: can one system take Dynamo’s way of spreading and copying data, and Bigtable’s way of storing it, and run on cheap commodity servers across several data centres, with a write path that never reads first?

The design choices

Cassandra is a combination, and the authors say so. The paper presents it as a mix of well-known techniques. Most of what is interesting is which piece came from where, and the few places where the authors chose differently.

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

More System design papers

All papers