Ch.65: Google Drive System Design: Who Still Has Access?
Transcript
0:00 Open a team file in Google Drive, and the service has to decide whether you're allowed to see its contents. It lets people share stored files with teammates. We'll design that sharing backend, including permission changes and the path that returns file bytes. For example, Alex removes Blair's direct share to a launch-plan file. Blair can still open it. Has removal failed, or is another permission keeping it open? I'd want to know whether Blair has another valid permission before calling that a leak. A link identifies the file; it doesn't decide access.
0:30 We'll trace the surviving access, then remove the last permission and follow Blair's next read. Our proposed backend gives that question a testable answer. First, the complete map shows Blair's two connected paths: the access decision and the content download. Clients enter through an authenticated gateway, which confirms who's making the request. Blair's request reaches the sharing service, which reads metadata and permissions from a transactional store and can reuse a matching cached evaluation.
0:58 An allowed result lets the gateway fetch the selected bytes from private blob storage. Committed changes feed audit records and workers that discard old cached answers. Those background jobs explain and clean up changes; Blair's open still follows the gateway's permission decision. First, the functional requirements: what can a teammate ask this backend to do? Take Alex's file: register its stored content, then grant a user or group reader or writer access. A grant is a stored permission relationship.
1:27 Readers can open content; writers can also publish changes. A folder's permissions apply to files below it, so the service must evaluate inheritance. List permitted files, open them, remove a particular grant, and explain remaining access. Current checks filter the list. Blair sees the file there; is his download already approved? No. Opening it requires another current check. Each non-root file or folder has one parent in its workspace, an isolated team space. Groups contain local users, never other groups.
1:59 We're keeping every caller identified, so anonymous public links are outside this version. Real Drive offers more controls, including limited-access folders; we're using simpler downward inheritance. Upload transport and live editing stay outside our sharing exercise. Next, we need the constraints that decide how safely and quickly those operations finish. Next, our non-functional requirements put a response boundary around removal: when must a later access check stop trusting the old permission?
2:27 Suppose Alex receives removal success, then Blair starts a server access check. It must include the committed change and deny if no applicable permission remains. Provided nobody legitimately shares the file again later. Removing one path doesn't erase another, and a new authorized share can correctly restore access. I'm not sure that promise covers an open download. Consider a request already being checked when Alex removes access. Do we stop its stream? No. An overlapping check may finish under its earlier decision.
2:57 Already-started streams and downloaded copies are outside recall; subsequent requests need new checks. For a fictional workload, assume 20,000 checks per second, 200 sharing, membership, or move changes per second, and 2000 workspaces. Our regional measurement target is a 95th percentile access-check latency of 50 milliseconds. We'd have to test whether the design can meet it. 95% must finish within that limit. Each check still pays for a current authoritative read, even with caching. And unavailable authority leads to a retryable error without file bytes.
3:32 A genuine deny requires evidence that no valid grant permits the operation. Now take Blair's original request and draw its relationship graph: records connecting membership, folders and allowed actions. Alex has authority to manage sharing. That file has a direct reader grant to Blair; its parent team folder also grants the team group read access. Blair belongs to that group. Trace Blair directly to the file, or Blair through group membership to the folder, then down to the file. Effective access means the combined answer across every applicable grant path for the requested action. A matching direct, group, or ancestor-folder permission can allow it.
4:10 My first thought was that removing Blair's named share removed Blair entirely. Why does the service still return yes? Because we removed the direct record only. Blair's membership and the folder's reader grant remain, so inherited access still permits the read. Oh, right. Show Alex the remaining group and folder. Otherwise it's a confusing support ticket: the removal worked, but Blair still opens the file. Before answering that ticket, could Blair also have a permission path we haven't drawn? Yes. Check user and local-group grants on the file and every ancestor, including user grants on folders or group grants directly on files.
4:48 With the surviving folder path established, follow a concrete open request through the decision and into the exact bytes it returns. For instance, the gateway authenticates Blair and sends the server-established user, workspace, file identifier and requested action to the check service. Start a new strong read-only transaction for every check. A snapshot is one consistent database view, so related reads describe the same state. Picture one fresh photograph of the permission rules beside the file's content version.
5:19 Strong means a check beginning after an acknowledged change can't select a view from before that change. Then Blair can't choose an older photograph? Correct. The server selects the view; a caller can't recover removed access by asking for an older snapshot. Within that snapshot, read the current file version and workspace policy revision. The revision is a version number for the workspace's permission rules. On an uncached check, evaluate relationship data there too. File, folder, group, and role information can't come from independently timed views.
5:50 I'd choose Spanner here, keeping metadata and policy together in one database. Request its strong read-only mode for these access checks. The name doesn't establish correctness by itself. Every check must request that fresh read mode, avoiding stale replicas or reused snapshots. The internal allow is restricted to this request and this immutable content version. What does immutable mean for the download? A stored blob generation whose bytes won't change under that identity. The gateway's decision names those particular bytes.
6:22 The gateway fetches that exact generation. If storage returns a mismatch or can't supply it, fail instead of silently asking for the latest contents. Storage generation checks verify version identity, not Blair's rights. What stops the browser from going around this gateway on the next request? We keep storage private and issue no reusable signed URL. Anyone holding such an address could otherwise fetch while it's valid, despite our application removal. Byte caches stay behind the gateway too. A range request asks for part of a file; each new range or reconnect goes through the decision path again.
6:57 Suppose Blair pauses halfway through a download. Alex gets success removing the final grant, then Blair resumes. Is that a new check? Yes. The first half is already outside recall. Resuming makes a new request, and without another valid grant the gateway returns no further bytes. A trusted download path still needs a trustworthy removal response. Let's remove the final applicable grant in our original case. Alex's earlier individual file grant has gone. Next, remove the team group's reader grant on the parent folder, with no other path allowing Blair's read.
7:32 That's a folder-sharing change affecting other group members too. If Alex only wanted Blair out, removing Blair's local membership would be a different operation. Before sending, Alex keeps a stable request number. That identifies this removal attempt, not a permission. Then start one serializable transaction; concurrent changes behave as though ordered one at a time. Within it, verify Alex's current management authority and the expected grant's identity and state. Does being a writer automatically give Alex management authority?
8:01 No. Read and edit rights needn't include permission to change sharing. Require that separate authority inside this mutation. Remove the expected grant and advance its workspace revision. The same commit stores Alex's request, its reply, and a change record for background workers. Success follows commit. Suppose the transaction commits, And then Alex never receives the response. I can't tell whether repeating the removal is safe. Reuse that number with unchanged details. Its recorded outcome settles the earlier attempt; we read it instead of running the removal again.
8:34 But an administrator legitimately re-shares the folder before Alex retries. Does reusing that request number delete the newly created grant? No. The request record holds Alex, the workspace, the original folder grant and the saved reply. Return that reply. A newly created permission has its own grant record. Ah, a replay leaves the restored grant alone. Now suppose Alex loses management rights but remains a workspace member. Can he still retrieve that reply? Our proposal lets Alex retrieve his own saved result after authentication, with the same workspace and request details.
9:09 It reveals no current permissions and grants no new file access. So he learns the historical outcome. A new removal requires Alex to have management rights at that moment, and Blair's next download still gets its own access check. But imagine the decision cache saying yes after Alex removes that final grant. A stale result could reopen the file. How do we prevent that? Why not delete that entry when the change commits, then trust whatever remains? Because an eviction message can arrive late or be lost.
9:40 A cached allow becomes reusable only after a fresh authoritative revision and content-version read. Okay, take a new open request from Blair. Before consulting that cached answer, the server obtains a fresh database snapshot under the strong-read contract. Read the workspace's policy number alongside the file generation in that snapshot. Match the complete key: workspace, user, file, action, content version, and policy revision. If we're caching the answer to save work, why send Blair back to the database on every open?
10:11 To establish the current revision and file version. A matching cache entry saves relationship evaluation; on a miss, evaluate those relationships in that same snapshot. Is the cached answer like a note filed under Blair, this file and this action, with its policy and content versions written on it? Yes, and the workspace too. Before reusing the note, we check those versions in the fresh view. The note saves us tracing the permission paths. Oh, I see. The old note stays stored; the fresh policy number makes it unusable.
10:42 Then evaluate the current paths. Deny only when none permits Blair to read. And the revision has to change whenever a grant, local membership, parent edge, or any other relevant policy input changes, in that same mutation transaction. Otherwise equal numbers could hide a permission change. Content changes have a separate version to follow. Now Alex publishes private details. Could Blair's old yes still open those new bytes? Let's use the same file. Alex's final removal commits first; only afterward does Alex publish a new version containing the confidential launch details. The link still names one file, but its contents have changed.
11:20 An old permission view paired with the new bytes would expose those details. The new blob is immutable and already stored. Publishing changes the file's current-version pointer in a transaction that verifies Alex's current write authority. The Zanzibar paper from 2019 describes this ordering risk; it's linked with the database docs in the description. Our database orders sharing changes and content-pointer updates together. Select policy and version in one fresh strong snapshot. But what if Alex publishes again between that check and the download?
11:52 It still fetches the selected generation. The gateway never resolves latest a second time. If those exact bytes are missing or wrong, return an error without substituting newer contents. Next, carry that snapshot rule into a folder move. A different parent can change which inherited permissions reach our file. Take an alternative to removing the folder grant: Alex moves the file from the team folder into a restricted folder. Blair has no grant there. Right. Alex needs permission at both ends: removing the source entry and adding it at the destination.
12:25 Check the expected parent, and prevent a folder becoming its own ancestor. Commit the stored parent change and higher workspace policy revision together. If Alex misses the reply, use the same identifier to retrieve what that move committed. A later check follows the committed parent chain. The old team folder's grant no longer reaches the file, but an independent direct grant would still count. So moving a file doesn't make it private while another grant survives. Keep both locations inside one workspace for this version.
12:56 Cross-workspace moves would cross our chosen policy boundary and need a separate design. So a parent move changes inheritance. Another branch removes Blair from the local team group, potentially changing access to many files at once. Take another branch of the case: Blair no longer holds a direct permission, but the folder's team grant remains. Alex instead deletes Blair's group membership. Do we rewrite the permission records on every file Blair used to reach through that group? No. Commit membership removal with the revised policy number, using the same actor, expected-state and operation-result checks.
13:31 Blair opens another file under that same folder. Which record changes his access if neither file's own grants changed? The missing membership breaks that group route for both files. Their next fresh checks use the advanced revision and evaluate the relationship again. That makes sense. If Blair also has a separate direct grant, though, the read can still succeed for that reason. That's for local membership. What changes if an outside directory takes time to send us group updates? We can't promise this boundary until that update reaches our authoritative store.
14:03 External synchronization and nested membership aren't supported here. But the workspace revision has a cost: membership and moves are easy to account for, while unrelated changes also discard useful cached answers. Take an earlier moment when Blair still had folder access. Someone shares a different file in this workspace. What happens to Blair's cached yes? That counter advances, so the next read misses. It rebuilds the same allowed answer. Nobody changed Blair's path, but he pays the evaluation cost anyway.
14:34 I see where you're going. One busy teammate can make everyone else's saved answers useless. I'm not sure the cache earns its keep for that team. We'd compare evaluation cost and hit rate under actual sharing traffic before claiming it helps. So the dashboard says the cache is full, and Blair still needs another evaluation. That's an awkward success metric. I'd measure useful hits before celebrating occupied space. We could track only this answer's grants, memberships and parent edges. But... ...missing one changed dependency could preserve an allow that should have disappeared.
15:08 Exactly. Any refinement has to prove the same freshness invariant, meaning a rule that remains true through every allowed change. We'd measure before adding that complexity. So that cache churn carries into capacity. Even perfect reuse at our fictional peak of 20,000 checks every second still requires that many fresh read transactions. Can you put that load in workspace terms without assuming every workspace is equally busy? If traffic were even, each workspace would average 10 checks a second and one change every 10 seconds.
15:39 Alex's team may be much busier. Suppose Alex's team gets most of the traffic. Its changes all update the same revision row. Other teams' rows don't take that work away. The workspaces are separate, but Alex's writers still compete on that shared revision? Right. That's contention, changes competing for the same row. We'd measure those update waits alongside Blair's read latency, folder depth and group size. I can picture Blair waiting while another team has almost no requests. I'd test this busy team before trusting the average.
16:11 Admission control means delaying or rejecting excess requests before overload. If a check can't complete safely, return retryable unavailability rather than skip a possible grant. So Blair may have to retry. We keep the permission check intact, then measure how much traffic this team can actually serve. Now the removal commits, its reply is lost, then the policy store goes offline. Alex doesn't know what happened. What can we tell him and Blair? Keep the request number. On recovery, retrieve his stored reply before another mutation.
16:42 But what should Blair see until we can check current permissions? No file bytes. While current policy can't be read, permission remains unknown; a cached yes can't fill that gap. So return an unavailable response that Blair can retry. It doesn't tell him whether he has a permission. Exactly. Denial means the service checked all relevant paths and found none allowing this request. Failing to check isn't evidence that his permission was removed. An on-call engineer trying to keep downloads alive could ask, can we serve the old version Blair could read before?
17:16 No. That request may start after the final removal; old bytes don't establish current rights. The prior-stream exception doesn't apply to a fresh download. And what if the recovered store still can't establish Alex's saved request record? Keep the outcome uncertain and retryable until it can be established. The committed grant change and its result must survive recovery together; we can't invent success or failure. Now I want to catch the test cheating. How do we make sure Blair's request really starts after success?
17:47 For example, use two clients and a barrier, a test step that waits for another event. Client one removes the last grant and receives committed success. Only then let client two send an open request. With no independent grant or later re-share, expect denial under the updated policy and no returned bytes. Preload Blair's old allow, then hold back its eviction message. An implementation that trusts that cached yes would return bytes and fail our test. The fresh revision must make it miss. Then keep the group path in a second run.
18:20 Blair should get bytes with that path named. We'd reuse this test setup for membership, move and publication changes. Force a version mismatch at storage too: it must fail without silently serving latest. During authority failure, expect retryable unavailability and no content bytes. Test lost mutation replies by retrying the same operation, including a manager legitimately restoring sharing before the retry. The retry must report its saved result without deleting the new grant. For that rejected check, record the actor and operation, policy revision, content generation checked, and any matching path.
18:55 Those records explain why no bytes returned. Delayed audit delivery never decides permission. And test overlapping requests separately. An earlier allowed check finishing later isn't evidence that the post-acknowledgment promise failed; compare the actual start ordering. Finally, return to the identical complete architecture map. Blair's original open passes the gateway, and the sharing service follows the group through its parent folder. Removing the direct grant was therefore consistent with continued access.
19:24 Later, the last folder-grant removal commits a higher revision in the metadata and policy store. The next check reads fresh state there, rejects the stale cache entry and denies. Private blob storage receives no fetch for Blair's bytes. Allowed requests fetch only their selected generation. Audit workers inspect committed records; cache workers use them to discard old entries. Neither worker can give Blair permission to download. We pay for strong reads and extra cache misses. If authority is down, reads are unavailable.
19:54 Saved copies and checks begun before success remain outside recall. Thanks for listening to Learning Podcasts.