Google Zanzibar System Design
One consistent authorization service for Drive, YouTube, Cloud and more
By Ankur NayakReviewed
How Google answers 'can this user see this object?' millions of times a second for hundreds of services: permissions are stored as relation tuples in Spanner, checks are evaluated at consistent snapshots chosen with 'zookies', and caches, request deduplication and a special index for nested groups keep 95% of checks under 10 ms.
Open in Studio· edit a copy- Users
- Hundreds of client services
- Throughput
- 10M+ requests/s (Dec 2018)
- Storage
- 2T+ tuples, ~100 TB (2019)
- Check latency
- p95 < 10 ms
- Availability
- > 99.999%
- Servers
- 10,000+
- Namespaces
- 1,500+
Requirements
Functional
- Store who has which relation to which object (owner, editor, viewer, member)
- Answer whether a user has a permission on an object (Check)
- Support groups that contain users and other groups
- Let each service define its own permission rules
- Stream permission changes so services can keep their own indexes in sync
Non-functional
- Never apply old permissions to new content (the 'new enemy' problem)
- Low latency: checks sit on the critical path of every request
- Availability above 99.999%
- Scale to trillions of permissions and millions of checks per second
In depth
One permission system for hundreds of products
Every Google product has to answer the same question on almost every request: may this user see this object? Rather than letting each product build its own access-control system, Google built one. Zanzibar, described in a 2019 USENIX ATC paper, stores the permissions of hundreds of client services, including Calendar, Cloud, Drive, Maps, Photos and YouTube.
In 2019 it held more than two trillion relation tuples, close to 100 terabytes, across more than 1,500 namespaces. Over a sample week in December 2018 it served more than 10 million requests per second at peak (about 4.2 million checks), from more than 10,000 servers in several dozen clusters. It kept 95th-percentile latency under 10 milliseconds and availability above 99.999% for three years.
Permissions as relation tuples
Zanzibar's data model is small. A permission is a relation tuple: an object, a relation and a user, written like doc:readme#owner@alice. The user can also be a set of users, such as group:eng#member, which is how groups and nested groups work.
Each client service defines a namespace with its relations and their userset rewrite rules. A document namespace might say that every owner is an editor, every editor is a viewer, and anyone who can view the parent folder can view the document. Tuples store the raw relationships; rewrite rules derive the effective permissions. This keeps writes simple (sharing a folder writes one tuple) and lets the rules change without rewriting data.
The API has five main calls: Write tuples, Read tuples, Check whether a user has a relation to an object, Expand the effective userset tree, and Watch for changes.
The architecture
aclservers are the main server type. They are organised in clusters and answer Check, Read, Expand and Write. A check can fan out: if a document's viewers include a group, and that group contains other groups, sub-checks go to other aclservers in the cluster, all evaluated at the same snapshot timestamp. When one branch decides the answer, the others are cancelled.
The data lives in Spanner: one database of relation tuples per namespace, one database of namespace configurations, and one changelog shared across all namespaces, written in the same transaction as each tuple change. The data is fully replicated in more than 30 locations around the world.
watchservers tail the changelog and stream tuple changes to clients in near real time, in timestamp order. A periodic offline pipeline dumps namespace snapshots and garbage-collects old tuple versions. And the Leopard index handles namespaces with deeply nested or very wide groups: an offline builder flattens group memberships into set indexes, and an incremental layer, fed by Watch, adds every change since the last build.
The new enemy problem and zookies
The subtle part of authorization is ordering. Imagine Alice removes Bob from a document and then adds confidential text. If a later check reads a stale copy of the permissions, Bob might see the new text. The paper calls this the new enemy problem.
Zanzibar prevents it with a consistency token called a zookie. When a service is about to save new content, it makes a content-change check, evaluated at the latest snapshot. The response includes a zookie encoding that snapshot's timestamp, which is greater than the timestamp of any ACL change that protects the content. The service stores the zookie with the content in the same atomic write. Every later check on that content version sends the zookie back, and Zanzibar evaluates it at a snapshot at least as fresh.
That "at least as fresh" is the key freedom. Zanzibar doesn't have to use the very latest data, only data no older than the zookie, so most checks can be served from nearby replicas and caches while still respecting causality. It all rests on Spanner's TrueTime timestamps, which give external consistency and snapshot reads.
Staying fast under hot spots
Authorization traffic is bursty: a popular video or a company-wide group can attract a flood of identical checks. Zanzibar uses several defences:
- A distributed cache of final and intermediate results, spread across servers with consistent hashing.
- Timestamp quantisation: evaluation timestamps are rounded so most recent checks share the same snapshot and therefore the same cache entries.
- A per-server lock table of in-flight requests, so simultaneous identical checks wait for one evaluation instead of stampeding Spanner.
- Request hedging for calls to Spanner and Leopard: if a request is slower than a recent latency percentile, a second copy goes to another server and the first answer wins. Requests between Zanzibar servers aren't hedged, because duplicating the most expensive checks would make latency worse.
The trade-offs
A central service means consistent semantics everywhere and permissions that work across products, but it also means hundreds of products depend on one system that must never be slow or down. Bounded staleness through zookies buys speed while keeping correctness, at the cost of clients storing and passing tokens. Normalised tuples keep writes simple, but deeply nested groups need a separate index to stay fast.
What to take into an interview
"Design an authorization system" is an increasingly common question, and Zanzibar gives a strong answer:
- Store relationships as tuples; derive permissions with per-namespace rules
- Evaluate checks at a consistent snapshot, and give clients a token so they never apply old ACLs to new content
- Cache aggressively, deduplicate in-flight requests and hedge slow storage reads
- Add a specialised index only where group nesting makes recursive checks slow
- Provide a change stream so other systems, like search indexes, can follow permissions
Components
End User
Client. Opens a document, video or photo in a Google product.
Client Service
Drive, YouTube, Cloud…Service. A Google product that calls Zanzibar to check permissions before serving content and to record changes in sharing.
Client Content Store
NoSQL database. The service's own storage. It saves the zookie returned by Zanzibar alongside each content version, in the same atomic write.
aclservers
Service. The main server type, organised in clusters. They answer Check, Read, Expand and Write requests, fanning work out to other aclservers in the cluster.
Why: One shared service means every product gets the same semantics, consistency and performance instead of each building its own ACL system.
Check Evaluator
Service. Picks a snapshot timestamp at least as fresh as the zookie, then evaluates the relation as a boolean expression over tuples and rewrite rules.
Userset Rewrite Rules
Coordination. Per-relation rules from the namespace config, e.g. every editor is a viewer, and viewers of the parent folder are viewers of the document.
Peer aclservers
Service. Sub-checks (for nested groups or parent folders) go to other servers in the cluster, using the same timestamp.
Outstanding-Request Table
Cache. A per-server lock table that tracks in-flight reads and checks, so simultaneous identical requests wait for one result (avoiding cache stampedes).
Snapshot Tuple Reads
SpannerSQL database. Reads of relation tuples at the chosen snapshot. Calls to Spanner are hedged: a second request is sent only if the first is known to be slow.
Distributed Cache
Cache. Final and intermediate check results, spread across Zanzibar servers with consistent hashing. Evaluation timestamps are rounded so many requests share cache entries.
Building block: Cache, Consistent Hashing
Relation Tuples
SpannerSQL database. One database per client namespace, holding tuples like ⟨doc:readme#owner@alice⟩ or ⟨group:eng#member@bob⟩. Fully replicated in more than 30 locations.
Why: Spanner's TrueTime timestamps give external consistency and snapshot reads, which is exactly what the zookie protocol needs.
Namespace Configs
SpannerSQL database. One database holding every namespace's relations and userset rewrite rules.
Changelog
SpannerSQL database. One changelog database shared by all namespaces: every tuple write is appended here in the same transaction.
watchservers
Stream. Tail the changelog and serve a stream of tuple changes to clients in near real time, in timestamp order.
Offline Pipeline
Batch processing. Runs periodically over all Zanzibar data in Spanner: dumps namespace snapshots and garbage-collects old tuple versions.
Leopard Index
Search index. A specialised index for deeply nested or very wide groups. An offline builder creates flattened set indexes from snapshots; an incremental layer, fed by Watch, adds every change since.
Request flows
Edit a doc, then check a viewer
- Alice removes Bob from a document, then adds new, sensitive content.
- The ACL change is written to Zanzibar and gets a timestamp from Spanner.
- The tuple is deleted in a Spanner transaction; the change is also appended to the changelog.
- Before saving the new content, the service makes a content-change check and receives a zookie.
- The service stores the zookie with the new content version in one atomic write.
- Later, Bob tries to open the document.
- The check carries the stored zookie, so it is evaluated at a snapshot at least that fresh.
- That snapshot already excludes Bob's tuple: the check says no. Old permissions are never applied to new content.
A burst of checks on a popular object
- Thousands of users open the same popular video or file at once.
- Timestamps are rounded so these checks share a snapshot, and the result is found in the distributed cache.
- Most checks are answered without touching Spanner, in well under 10 ms.
Keep a search index in sync with sharing
- Every tuple write is also appended to the shared changelog.
- watchservers tail the changelog.
- A client service watching the namespace receives the changes in timestamp order, plus a heartbeat zookie to resume from.
Failure scenarios
What if: a hot spot on a popular group?
A widely used group or object attracts a flash of identical checks. Zanzibar caches final and intermediate results across servers, rounds timestamps so requests share them, and tracks in-flight requests so concurrent duplicates wait for one evaluation instead of hammering Spanner.
User impact: Usually none; without these defences, check latency would spike.
- Distributed cache with consistent hashing
- Deduplicating in-flight requests
- Leopard for deeply nested groups
What if: an aclserver cluster becomes unavailable?
Zanzibar runs several dozen clusters with data replicated in more than 30 locations, so clients' requests go to other clusters and replicas while the failed one is out.
User impact: Slightly higher latency for users far from the next cluster.
- Many clusters and replicas worldwide
- Monitoring that detects and avoids slow servers
Trade-offs
A central service instead of per-product ACLs
Run one authorization system for hundreds of services with a shared data model.
- Pros
- Consistent semantics everywhere
- Cross-product sharing (a group used in Drive and Calendar)
- One team optimises latency and availability
- Cons
- Every product depends on one critical service
- The data model must be general enough for all of them
Bounded staleness with zookies
Evaluate most checks at a recent snapshot no older than the client's zookie, instead of always the latest.
- Pros
- Checks can be served from nearby replicas and caches
- Still never applies old ACLs to new content
- Cons
- Clients must store and pass the zookie with their content
Normalized tuples plus a special index
Store relationships normalized and add Leopard only for namespaces with deeply nested groups.
- Pros
- Simple writes; one source of truth
- Fast set computation where it's needed
- Cons
- Leopard adds an offline builder and an incremental layer to run
Frequently asked questions
What is Google Zanzibar?
Zanzibar is Google's global authorization system. Services such as Calendar, Cloud, Drive, Maps, Photos and YouTube store their permissions in it as relation tuples and ask it whether a user may access an object. In 2019 it held more than two trillion tuples and served millions of checks per second.
What is a zookie?
An opaque consistency token that encodes a timestamp. A service gets one when it checks permissions for a content change and stores it with that content; later checks send it back so Zanzibar evaluates them at a snapshot at least as fresh as the content.
What is the new enemy problem?
The risk of applying an old permission to new content. If Alice removes Bob from a document and then adds secret text, an authorization check that read a stale copy of the ACL could still let Bob see the new text. Zanzibar's zookies prevent it.
How does Zanzibar keep checks fast?
It caches final and intermediate results across servers with consistent hashing, rounds timestamps so requests share cache entries, deduplicates simultaneous identical checks, hedges slow Spanner reads, and uses the Leopard index for deeply nested groups. 95% of checks finish within 10 ms.
Building blocks used
Sources
- Zanzibar: Google's Consistent, Global Authorization System · USENIX ATC
- Zanzibar: Google's Consistent, Global Authorization System · Google Research
- Spanner: Google's Globally-Distributed Database · Google (OSDI)