System design paper · 2019
Zanzibar
How Google answers “may this person open this?” millions of times a second: permissions as small facts, rules that join them, and a token that keeps changes in order.
You’ll learn to
- Read and write permissions as relation tuples, and walk a check through a rule that makes one relation include others.
- Explain the “new enemy” problem and how a token saved with the content keeps a removed person out.
- Describe how an index of flattened groups, caching, merged duplicate requests and hedging keep checks fast.
- Compare what SpiceDB, OpenFGA and Ory Keto say they took from Zanzibar, and what each left behind.
Read first: Spanner
The idea in short
Every time you open a shared file, some service must decide whether you may. Google runs one such service for Drive, Photos, YouTube, Calendar and more. It stores each grant as a small fact, such as “Ana is an editor of this document”, and keeps a short rulebook that says how facts combine: an editor may also view, and anyone who may view the folder may view what is inside it.
The hard part is order. If Alice removes Bob and then adds a secret page, a check that runs on out-of-date data could still let Bob in. Every content change therefore stores a token marking when it happened, and every later check must look at data at least that fresh. Most checks still run on nearby copies, so the answer takes about 3 ms in the middle and stays up 99.999% of the time.
The problem
Open a shared document and, before a single word appears, something has decided that you may see it. That decision is : deciding whether a person may do a given thing to a given object. (Authentication is the step before it, proving who the person is.) Photo-sharing is the paper’s own example: owners share some photos with friends and keep others private, so the service must check each photo against each viewer before showing it.
By 2019 hundreds of client services at Google needed this answer, among them Calendar, Cloud, Drive, Maps, Photos and YouTube. The authors argue that one shared system beats one per service: permissions mean the same thing everywhere, products can work together, and the hard parts, consistency and scale, are solved once.
The paper gives five goals: correctness, flexibility, low latency, high availability and large scale. The numbers explain why each is hard:
- Scale. More than 2 trillion permission records, close to 100 terabytes, copied to more than 30 places around the world. More than 10 million requests a second. Over 1,500 separate namespaces (one per kind of object, such as documents or groups), defined by hundreds of client applications.
- Latency. A check sits in the path of everything a person does. A search result page may need tens to hundreds of checks, one for each candidate result.
- Availability. If the service cannot answer, a product has to refuse access, which looks to the user like a broken product.
- Correctness. Permissions change all the time, and the answer must respect the order of those changes. The next sections show what goes wrong when it does not.
So the question the paper answers is: how do you build one authorization service that is flexible enough for every product, honest about the order of changes, and fast and always on, across the whole world?