Design an Authorization Service like Zanzibar
Understanding the Problem
🛡️ What is an authorization service? An authorization service decides whether a given user may perform a given action on a given resource: can Alice edit this page, can Bob delete this file, can this service account read that bucket? Instead of every product keeping its own ACL tables and permission logic, they all store permission data in one system and ask it. Google's Zanzibar is the best-known design of this kind; open-source systems like SpiceDB and OpenFGA follow the same model.
This question comes in several costumes: "design permissions for Notion pages," "design RBAC for a B2B SaaS," "design IAM," or "design sharing for a file storage app." They're the same problem: a set of facts about who relates to what, and rules for turning those facts into yes or no. We'll design one service general enough to handle all four, and show how each maps onto it.
Functional Requirements
Make it clear up front that this is authorization, not authentication. Someone else has already proved the user is Alice; we decide what Alice can do.
Core Requirements
- Applications should be able to grant and revoke access: share a page with a user, add a user to a group, put a document in a folder, assign a role.
- Applications should be able to check whether a user has a permission on an object, including access inherited through groups, folders and roles.
- Applications should be able to list what a user can access (for search results and file listings) and who can access an object (for the share dialog).
- Each application should be able to define its own permission model, including B2B tenants defining custom roles.
Below the line (out of scope)
- Authenticating users. See /system-design/auth-service.
- A policy-authoring UI and audit-log search.
- Rich attribute-based rules (time of day, IP ranges). We'll mention how they plug in.
Non-Functional Requirements
Ask about scale. A central permission service for a large company might hold tens of billions of relationships for billions of objects, and answer on the order of a million checks per second, because every page view, API call and search result needs one.
Core Requirements
- Checks should be fast: p99 under 10 ms. A check is on the critical path of almost every request, sometimes several per request.
- The system must never let a user see content after their access was removed, even briefly, when that content was changed after the removal (the "new enemy" problem, explained below).
- The system should be highly available, 99.99%+. If it's down, nothing can be authorized, and every product fails closed.
- The system should handle writes on the order of 10,000 relationship changes per second, and much higher bursts (a folder shared with a 50,000-person group).
Below the line (out of scope)
- Per-product compliance work (data residency per tenant beyond region pinning).
Back-of-the-envelope: 20 billion relationships at roughly 100 bytes each is about 2 TB, plus indexes. That's a sharded database, not a single box, but not a huge one. The checks are harder. A check that walks a document's parent folders, a group nested two levels deep, and an organization role might take 5 to 20 lookups. At a million checks per second that's up to 20 million lookups per second, which no database serves at a 10 ms p99.
The insight to say out loud: a permission check is a graph search, and we can't afford to run it against the database every time. Most of the design is about caching graph walks without serving stale answers to the people it would hurt.