Skip to content

How to design a permission system

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Practice this question

The problem

A permission system for a workspace product answers one question on nearly each request: may this user do this action on this page? Grants sit on pages and folders, groups hold people and other groups, and a page inherits what its ancestors grant until someone sets an override on it. The answer turns on the ratio of checks to changes, about 170 to one by the figures here. So the design resolves inheritance when a check arrives and keeps writes to one row, caches each answer under the snapshot of data it read, flattens nested groups into an index, and stores a freshness token with page content so a removal is seen before any content added after it.

Clarifying questions

AskWhy it mattersA typical answer

Which roles exist, and do they form an order?

If viewer, editor, sharer and admin each include the ones below, the effective role is the broadest grant found and a check is a single comparison. If roles are unordered sets of actions, each action has to be resolved on its own.

Four roles: read, edit, share and admin, each including the ones below it. Treat the broadest grant a user has as their effective role; Notion documents that rule for its own sharing.

How deep do pages nest, and do groups contain groups?

Depth sets the price of resolving inheritance when the check arrives, and nested groups decide whether membership needs its own index or can be a direct lookup.

Our advice: assume no fixed depth limit, and size for a page five levels inside a shared folder as your example case. Groups nest too: a company group holds team groups, which hold smaller groups.

After someone is removed, how fresh must the next check be?

Reading the latest data on each check costs a round trip to the leader copy; a bounded window of staleness lets most checks read local copies. The requirement decides between the two.

A removed person must not see content added after the removal. For content that already existed, a few seconds of staleness is acceptable.

How many checks and grant changes arrive at peak, and how many grants are stored?

The ratio of checks to changes decides where to spend: on the write path (precompute) or on the read path (resolve and cache).

About 4.2 million checks and 25,000 grant changes a second at peak, about 2 trillion grants stored, and a check should answer in under 10 ms.

Can an override on a page narrow access, or is widening the most it can do?

If children can widen but not narrow, as Google Drive's API documents, a check can stop at the first allow it finds. If an override can also narrow, the check has to stop at the nearest override and ignore grants above it.

An override replaces the inherited access on that page, so it can narrow or widen. Blocking one group outright while another grant lets its members in comes later as a twist.

Who calls the check: just the page view, or search, exports and the public API too?

Each search result shown is its own check, which multiplies the load, and each caller that shows protected content has to carry the freshness token.

Page views, search results, the sharing dialog and the API. Search needs a check for each result on a page, so in this design one search request costs one check per result shown.

Is the audit log a hard requirement?

A write-once record of each grant and revoke is cheap to add at the start and awkward to retrofit, and it decides whether changes go through one service.

Yes. Each grant and revoke is recorded with who made it and when.

The requirements menu

RequirementScopeWhy

Give users and groups a role in a workspace, such as admin, editor or viewer

Core

The baseline everyone in the workspace starts from. It is one grant on the root resource, so the same check path handles it.

Share one page or folder with a person or a group, at a chosen level

Core

The product's main action. Sharing a folder must stay one write even when thousands of pages sit below it.

Nested pages inherit access from their parent unless an override is set on them

Core

This is what makes the check more than a row lookup: the answer for a page may live on an ancestor.

Check whether a user may read, edit, share or administer a resource, on every request

Core

The hot path. It runs on each page view and each search result, so its cost sets the size of the system.

List who has access to a page and why, and revoke it

Core

The sharing dialog needs each person's effective role and the grant it came from, and a revoke must be seen by checks on content added after it, and by other checks within the few seconds the requirement allows.

Move a page or folder to a new parent, with its inherited access re-evaluated

Optional

Worth raising: a move is the operation that separates resolving at check time (one parent pointer changes) from precomputing per page (a whole subtree rewrites). Access is then re-evaluated on move rather than rewritten.

An explicit deny on a user or group that wins over any grant

Optional

Take it if asked: it is the usual twist on this question. It adds an exclusion branch to the check, and it stops the check from stopping at the first allow.

Public links: anyone with the link can view

Optional

A grant whose subject is everyone, so it fits the model, but it changes what the cache can share and makes leaks easy. Name it and leave it unless the interviewer wants it.

Grants that expire at a set time

Optional

Cheap in the data model (an expiry column the check compares against the snapshot time), but it means a check result can change with no write, which a cache keyed by data version does not notice.

Request access when a check is denied

Optional

A product flow, not a permission mechanism. It reuses the grant API, so it costs little to mention and nothing to defer.

Guest users from outside the workspace

Out of scope

Guests are ordinary subjects of grants; what differs is identity and billing, which are both out of scope here.

Sign-in and how the user’s identity is established

Out of scope

Authentication hands the check a user id. Everything here starts after that.

Plans and billing that turn features on or off

Out of scope

Feature flags per plan are a separate lookup; mixing them into the permission check muddles both.

Real-time editing of the pages themselves

Out of scope

The page service calls the check and stores content. How it merges concurrent edits is another question.

Non-functional requirements

RequirementWhat it forces

Checks are fast: Google’s Zanzibar answers over 95% of them within 10 ms

No check may wait on a cross-region round trip in the common case. Grants are read from a copy near the caller, answers and partial answers are cached, and the parts of a single check run at the same time rather than one after another: six serial reads in a 10 ms budget leave under 2 ms each.

Highly available: Zanzibar reports over 99.999% across three years

About five minutes of downtime a year. The permission service runs in many locations with the grants copied to each, and a check must be answerable from local copies when the leader region is unreachable.

A removed user never sees content added after the removal

Each grant change gets a commit-ordered timestamp, and content saved after a change carries a token naming that time. Checking that content means reading a snapshot no older than the token, so it is not answered from a cache entry or a replica that predates the removal.

Checks and reads outnumber permission changes by about a hundred to one

Spend on the read path. Writes stay one normalized row; the read path gets the cache, the group index and the request routing. Precomputing access per page would move work onto the rare writes but make folder shares and moves rewrite whole subtrees.

Every grant and revoke is kept in an audit log

All grant changes go through one service and one store, so the change stream of that store can feed both the audit log and the group index. No other service writes grants.

Estimates

QuantityWorkingResultWhat it sizes

Checks per grant change at peak

4.2 million checks a second ÷ 25,000 changes a second ≈ 168

About 170 checks for each change

Which side to make cheap: a change may cost many index updates if that keeps a check to a lookup.

Grant rows read a second if each check climbs the tree

A page five levels inside a shared folder means six resources to read (the page and five ancestors); 6 × 4.2 million ≈ 25 million row reads a second, before any group lookup

About 25 million row reads a second at peak

The read load on the grants store when nothing is cached: the reason the check cache and partial-result sharing exist.

Time left per read if the climb is serial

10 ms budget ÷ 6 reads in sequence ≈ 1.7 ms per read

Under 2 ms for each lookup

Why the ancestor and group branches run concurrently and read local copies: one remote round trip blows the budget.

Checks that share one snapshot time

If evaluation times are rounded up to a 10-second step: 4.2 million × 10 ≈ 42 million checks per step; with a 1-second step, 4.2 million

Tens of millions of checks per snapshot step

The cache hit rate: each check in a step evaluates at the same timestamp and can reuse the same entries.

Storage across all locations

100 TB per copy × 30 locations = 3,000 TB

About 3 PB in total

Why grants stay normalized: copying a grant onto each descendant page would multiply a figure already in petabytes.

Audit log growth

25,000 changes a second × 86,400 seconds ≈ 2.2 billion events a day; sized, as a rough guess and not a measurement, at about 50 bytes each (the per-grant figure, borrowed), ≈ 108 GB a day

About 2.2 billion events and roughly 110 GB a day

The audit log: an append-mostly store with time-based partitions, not a table the check path ever reads.

Downtime that 99.999% allows

0.001% × 525,600 minutes a year ≈ 5.3 minutes

About five minutes a year

Why the service runs in many locations and answers from local copies: a single-region store falls short of it.

Core entities

EntityWhat it holds

Resource

A workspace, folder or page. Its parent pointer is the whole of the tree.

Grant

One row where access was given: a subject, a resource and a role. It is read at check time rather than copied downward.

Group

A named set of members. A member may be another group, which is what makes membership a graph question.

Group membership

One row per direct membership. The flattened index is derived from these rows, not stored in them.

Role

A name and the actions it allows. Roles are ordered so the broadest grant decides.

Audit event

Who changed which grant, and when. Written from the same change stream that feeds the group index.

Page content version

What the page service stores on each save: the content and the freshness token from the content-change check.

The API

EndpointNotes

check(user, action, resource) → allowed or denied

The hot call, used by the page service, search and the API. It also takes an optional freshness token stored with the content being shown; without one, the service evaluates at its default snapshot. A batch form takes a list of resources for one user, so a whole screen of search hits is one call. The answer carries the snapshot time it was evaluated at.

POST /resources/{id}/grants { subject, role }

Writes one row on that resource and one audit event in the same transaction, and returns the grant id plus a freshness token. Callers who then show the newly shared content send that token with their first check. Sharing a folder is this same single write, however many pages sit below.

DELETE /resources/{id}/grants/{grant_id}

Deletes the row, writes the audit event, and returns a token. The removal takes effect for each check whose snapshot is at or after its commit time; the revocation deep dive covers what the caches and replicas return in between.

GET /resources/{id}/access → each user’s effective role and the grant it comes from

The sharing dialog. It climbs to the nearest override, expands groups through the flattened index, and reports for each user the broadest role and the resource it was granted on, the way an inheritedFrom field would. Expensive, so it is not on the check path and is paginated.

POST /groups/{id}/members { user_or_group }

Adds a direct membership row. The change stream turns it into index updates; a change to a large group may fan out into a very large number of them, which is why it does not block the request.

The high-level design

opensharecheckwriteClientPage servicePermissionsPage storeGrants

Step 1 of 4

One service owns grants and answers checks

Start by separating who decides from who shows. The page service stores content and asks a permission service before it serves a page; the sharing dialog talks to the permission service directly. The permission service owns a grants store: one row per grant, stored against the resource it was given on, plus a parent pointer on each resource. A check loads the user's groups, reads the grants on the page, stops if the page has an override, and otherwise climbs to the parent and repeats until the workspace root, answering with the broadest role found. Each grant change writes its audit event in the same transaction.

opensearchsharecheckbatchmisswritesnapshotmemberClientPage serviceSearchPermissionsPage storeCheck cacheReplicaGrantsChangesGroup indexAudit logIndex builder
The whole design

What breaks first

The deep dives

Checking access on nested pages. A user opens a page five levels inside a shared folder. How does the service decide whether they may edit it, what does one check cost at peak, and where does that cost land?

A concept that helps here: Authorization modelsA concept that helps here: Fan-out on write and on readA concept that helps here: Caching strategies

Removing access without a stale yes. An owner removes a person from a folder and adds a sensitive page to it moments later. Which copies of permission data could still say yes to that person, and how do you keep the new page from them without reading the leader on each check?

A concept that helps here: Consistency modelsA concept that helps here: Cache invalidation and TTLsA concept that helps here: Clocks and ordering

Nested groups and hot pages. A page is shared with the whole company through a group that holds team groups that hold smaller groups, and thousands of people open it at once. How do you answer one person's membership, and what keeps the store behind that page standing?

A concept that helps here: Change data captureA concept that helps here: Request coalescing and leasesA concept that helps here: Hot keys and hot partitions

Concepts this guide uses

Sources

  1. The Google Zanzibar paper (Pang et al., USENIX ATC 2019), annotated by AuthZed
  2. Hemant Gupta: Insights from Paper (Part II), Zanzibar: Google's Consistent, Global Authorization System
  3. DEV Community: Google Zanzibar Deep Dive, handling 2 trillion ACLs in under 10 ms
  4. ByteByteGo: How Google Manages Trillions of Authorizations with Zanzibar
  5. Notion Help: Sharing and permissions settings in Notion
  6. Google Drive API guide: Share files, folders, and drives
  7. Authzed docs: Consistency (ZedTokens and consistency levels in SpiceDB)
  8. AWS IAM User Guide: Policy evaluation logic
Sign in to report a mistake