System Design Atlas
LOCAL GUEST MODERead and practice without an account.

Your saved topics and reading progress stay in this browser. Sign in to sync supported profile and progress data.

File Storage and Sync (Google Drive)

The object upload succeeds, but finalize times out and the client retries.

● HardSystem 092 min3 prerequisites
My progress
Topic tools

Layout updated

Explore the design, then rehearse the decisions without looking.

Problem statement

Design a file storage service like Google Drive. Users can upload and download files, access the latest version from multiple devices, and catch up on changes when a device comes back online.

Functional requirements

  • Upload, download, list, rename and delete files.
  • Resume transfers and sync changes across devices.
  • Detect conflicting edits.

Non-functional requirements

  • Aim for metadata under 200 ms.
  • Publish a file version only after its bytes are durable.

Back-of-the-envelope estimates

Illustrative estimate
10M active users × 20 metadata actions/day ≈ 2.3k/s average
1M uploads/day × 10 MB = 10 TB/day of new bytes

Entities

Entity / logical owner
File(fileId, ownerId, currentManifest, version, deleted)
(manifestId, chunkHashes, sizes, totalChecksum)
Change(accountId, sequence, fileId, version, type)

API design

Operation / inputResponse and retry contract
POST/uploads {fileId, expectedVersion, size}Return upload session and scoped signed chunk URLs.
POST/uploads/{id}/finalize {manifest, requestId, expectedVersion}Verify chunks, then atomically publish pointer/change; return 409 on stale base version.
GET/changes?cursor=...Bounded ordered changes plus next cursor; expired cursors trigger a consistent baseline resync.

High-level design

How to draw this design

  1. Transfer file bytesClient, signed upload , and object storage
  2. Commit file metadataMetadata service and PostgreSQL versions
  3. Publish file changesAccount change log, Kafka, and folder index projector
  4. Sync and recoverSync service, device cursors, and regional copies

Transfer chunks directly, then commit the verified and change row. Other devices pull changes by cursor.

State ownership
Object storage holds bytes. PostgreSQL owns the visible version and change log.
Scale
Keep byte traffic off application servers and partition metadata by access pattern.
Correctness
Compare the expected file version and commit the change row atomically.
Failure and recovery
Retry interrupted uploads and verify both metadata and bytes before regional recovery.
Google Drive / File Storage + Sync
G dev->gw 1. Request upload, metadata or sync gw->up 2. Create transfer session up->dev 3. Return signed transfer URLs dev->obj 4. Transfer chunks directly obj->region 5. Replicate verified chunks gw->meta 6. Commit file manifest meta->db 7. Commit version and change row gw->sync 8. Request changes since cursor sync->db 9. Read change log and index db->region 10. Meet metadata durability policy db->out 11. Relay committed metadata out->project 12. Consume versioned updates project->db 13. Update folder index dev Client Devices edge gw API Gateway / Auth edge up Upload / Download API compute meta Metadata Service compute sync Sync Service compute obj Object Storage state · durable region Cross-region Durability state · durable db PostgreSQL: Metadata, Change Log and Folder Index state · durable out → Kafka: Committed Metadata Changes messaging project Folder Index Projector compute
  • Edge
  • Compute
  • State
  • Messaging

━━ Synchronous┄┄ Asynchronous···· Recovery / control▧ Fault

Select a component or follow a numbered connection.

Each arrow is one interaction. Request, background and recovery branches are not one linear transaction.

Read the 13 flow steps

High-level design component walkthrough

Client / user

Client Devices

Chunk upload/download; local sync cursor

Why, tradeoff and connected operations

An application or user-facing endpoint starts or receives this flow.

Tradeoff: Offline divergence and retry logic

Connected operations: Request upload, metadata or sync; Return signed transfer URLs; Transfer chunks directly

Gateway / routing

API Gateway / Auth

Authorize files and requests

Why, tradeoff and connected operations

Centralize admission and routing while keeping business-state ownership downstream.

Tradeoff: Central auth adds latency

Connected operations: Request upload, metadata or sync; Create transfer session; Commit file ; Request changes since cursor

Backend service

Upload / Download API

Issue scoped signed URLs + sessions

Why, tradeoff and connected operations

Isolate this operation so it can scale and fail independently from storage.

Tradeoff: Signed URL expiry / upload cleanup

Connected operations: Create transfer session; Return signed transfer URLs

Backend service

Metadata Service

current-version pointer + manifests

Why, tradeoff and connected operations

Isolate this operation so it can scale and fail independently from storage.

Tradeoff: version checks may conflict

Connected operations: Commit file ; Commit version and change row

Backend service

Sync Service

Cursor pull; notifications are hints

Why, tradeoff and connected operations

Isolate this operation so it can scale and fail independently from storage.

Tradeoff: Devices can lag or miss notifications

Connected operations: Request changes since cursor; Read change log and index

Object / blob storage

Object Storage

Immutable checksum-verified chunks

Why, tradeoff and connected operations

Object storage keeps large immutable file chunks cheaply and durably. Checksums and stable object IDs support retries and content reuse. It stores bytes, not relational metadata; keeping blobs outside avoids bloating transactional tables.

Tradeoff: Orphaned chunks and storage bills

Connected operations: Transfer chunks directly; Replicate verified chunks

Object / blob storage

Cross-region Durability

Protect committed versions on region loss

Why, tradeoff and connected operations

Cross-region object copies preserve the same committed file chunks through a regional loss. They support restoring access near surviving metadata services. This is a durability copy of object storage, not another database model; replication timing defines the loss window.

Tradeoff: Cross-region commit latency and cost

Connected operations: Replicate verified chunks; Meet metadata durability policy

Relational database

PostgreSQL: Metadata, Change Log and Folder Index

Store file versions, sync changes and folder index rows under the same metadata authority.

Why, tradeoff and connected operations

PostgreSQL commits a file’s metadata version and sync change together. Indexes support folder listings and permission lookups without inventing separate authorities. suits linked metadata; large file bytes belong in object storage.

Tradeoff: can reduce write availability

Connected operations: Commit version and change row; Read change log and index; Meet metadata durability policy; Relay committed metadata; Update folder index

Queue / event stream

Kafka: Committed Metadata Changes

Carry committed metadata changes to the folder projection worker.

Why, tradeoff and connected operations

Kafka retained partitioned stream. Key events by the domain ordering key; replay and independent consumers motivate this choice. rows remain in the source database; a relay publishes after commit. Buffer independent producers and consumers, with bounded and replay semantics.

Tradeoff: Events arrive late or duplicate

Connected operations: Relay committed metadata; Consume versioned updates

Backend service

Folder Index Projector

Maintain the folder view from committed metadata events.

Why, tradeoff and connected operations

Apply versioned updates to index rows in the same PostgreSQL metadata database.

Tradeoff: Folder listings may briefly lag the authoritative file record.

Connected operations: Consume versioned updates; Update folder index

Engineering control room

Deep dives — decisions, failures and recovery

Open a deep dive to follow the steps, try an example and see how recovery works.

Deep dive 1

Publish only complete file versions

Verify the uploaded chunks before saving the new file pointer and change record.

Read the explanation and worked example
How it works

Upload immutable chunks under a unique upload identity, then verify their checksums and required durability. Finalize by committing the new file-version pointer and ordered change record together. Readers see either the old complete version or the new complete version.

Walk through an example

The last chunk upload succeeds but finalize times out. Retrying finalize with the same upload identity should return the committed version, not publish two versions accidentally.

Failure and recovery

Retain old versions through a recovery window and collect orphan chunks only after proving they are unreferenced. Object upload success alone must not make incomplete metadata visible.

Why this helps

Publishing metadata first can expose a version whose bytes are missing after a failure.

What you give up

Unreferenced uploads can be removed after a grace period. Referenced chunks must remain until version and recovery rules allow deletion.

Deep dive 2

Preserve both users' edits

Require the version an edit started from; report a conflict if it changed.

Read the explanation and worked example
How it works

Every edit names the file version it started from. The metadata authority compares that expected version with the current version inside the update transaction. If they differ, preserve both edits or invoke an explicit merge workflow instead of silently discarding one.

Walk through an example

Two offline laptops edit version 12. The first publishes version 13; the second must not overwrite it as if it were still based on the current file.

Failure and recovery

Keep conflict copies and enough ancestry to explain the decision. Automatic merging works for some formats, but arbitrary binary files need a visible product policy rather than a generic last-writer-wins claim.

Why this helps

The last network response to arrive is not necessarily the edit the user meant to keep.

What you give up

Automatic merging depends on the file format. For arbitrary files, keep a conflict copy rather than silently discard someone else's work.

Deep dive 3

Recover changes missed while a device was offline

Use a durable change log; push notifications only tell the device to check it.

Read the explanation and worked example
How it works

Give each account an ordered durable change log and a device cursor. Push messages merely tell a device to poll; the device requests every change after its cursor and advances only after applying it durably. This also handles missed pushes and reconnects.

Walk through an example

A phone is offline for a week while thousands of files change. It needs a retained log range or a new consistent , not a replay of unreliable wake-up notifications.

Failure and recovery

Detect expired cursors and perform -plus-catch-up. Keep deletes in the synchronization history long enough to prevent an old device from reintroducing removed files.

Why this helps

A lost push message must not leave a device permanently out of date.

What you give up

Keeping history costs storage. When a device's cursor is too old, it needs a fresh and catch-up rather than an incomplete replay.

Deep dive 4

What happens if a region fails?

Check that the recovery region has both file metadata and all its bytes.

Read the explanation and worked example
How it works

A regional file version is usable only when both its metadata and every referenced immutable chunk are available. Track replication completeness for the entire generation, and fence metadata-writer promotion separately from object transfer.

Walk through an example

Metadata reaches the disaster-recovery region before one large chunk finishes copying.

Failure and recovery

Do not publish a broken version. Serve the last complete permitted version or report temporary unavailability; resume chunk transfer and validate the before activation.

Why this helps

The file's durability guarantee spans metadata and object bytes together.

What you give up

Waiting for remote chunk durability before publication reduces loss risk but increases upload-finalization latency and bandwidth cost.

Tradeoffs and alternatives

DecisionTradeoff / alternative and recovery implication
Publish only complete file versionsUnreferenced uploads can be removed after a grace period. Referenced chunks must remain until version and recovery rules allow deletion.
Preserve both users' editsAutomatic merging depends on the file format. For arbitrary files, keep a conflict copy rather than silently discard someone else's work.
Recover changes missed while a device was offlineKeeping history costs storage. When a device's cursor is too old, it needs a fresh and catch-up rather than an incomplete replay.
What happens if a region fails?Waiting for remote chunk durability before publication reduces loss risk but increases upload-finalization latency and bandwidth cost.

Production scars & failure modes

Failure investigation

The object upload succeeds, but finalize times out and the client retries.

Look for: Inspect upload identity, object checksum and committed metadata version.

Recovery and invariant: Finalize idempotently against the upload/version identity; publish metadata and change event atomically. Garbage-collect unreferenced uploads after a grace period.

Component / failureImpactRecovery mechanismAlternative / tradeoff
Upload connection lostSome chunks exist but no complete file is visible.Resume by checksums/session state; finalize idempotently, then clean abandoned chunks after grace.Extra temporary storage avoids partial-file visibility.
Metadata writer crashesFinalization may have committed despite missing response.Retry requestId and inspect durable version; promote a fenced replica with a safe log position.Async replica promotion can lose acknowledged versions unless stronger durability was chosen.
Change projection lagsFolder listings or device notifications appear stale.Read authoritative file version for critical checks and replay /change records to repair projections.Fast eventual listings do not guarantee immediate read-your-writes without an overlay.
Cursor older than The server cannot replay the missing history.Return an explicit reset requirement and enumerate a consistent , then tail later changes.A full resync costs bandwidth; silently advancing the cursor loses edits/deletes.

90-second interview summary

I would separate immutable file bytes from transactional file metadata. Devices upload chunks directly to object storage under a stable upload identity. Finalization verifies chunk checksums and required durability, then PostgreSQL commits the new file-version pointer and account change record together. Upload success by itself does not publish a usable file version.

Concurrent edits carry the version they started from. The metadata transaction compares that expected version with the current version and either commits, creates a conflict copy or enters an explicit merge workflow. Arbitrary binary files cannot safely use a generic merge rule.

Devices synchronize through a durable ordered account log and advance their cursor only after applying changes locally. Push notifications just wake the device; missed pushes are repaired by pulling the log. An expired cursor requires a consistent followed by catch-up, including deletions.

Regional durability covers metadata and every referenced chunk. I would fence metadata promotion, track asset replication completeness and avoid claiming a complete recovered file from a metadata copy alone. Metrics include finalize latency, conflict rate, oldest sync cursor and orphan bytes. The tradeoff is more versioning and synchronization state in exchange for resumable transfer, offline recovery and a clear publication boundary.

Explain it without looking

Explain publish only complete file versions

Reveal answer

Verify the uploaded chunks before saving the new file pointer and change record.

Publishing metadata first can expose a version whose bytes are missing after a failure.

Unreferenced uploads can be removed after a grace period. Referenced chunks must remain until version and recovery rules allow deletion.

Explain preserve both users' edits

Reveal answer

Require the version an edit started from; report a conflict if it changed.

The last network response to arrive is not necessarily the edit the user meant to keep.

Automatic merging depends on the file format. For arbitrary files, keep a conflict copy rather than silently discard someone else's work.

Explain recover changes missed while a device was offline

Reveal answer

Use a durable change log; push notifications only tell the device to check it.

A lost push message must not leave a device permanently out of date.

Keeping history costs storage. When a device's cursor is too old, it needs a fresh and catch-up rather than an incomplete replay.

Explain what happens if a region fails?

Reveal answer

Check that the recovery region has both file metadata and all its bytes.

The file's durability guarantee spans metadata and object bytes together.

Waiting for remote chunk durability before publication reduces loss risk but increases upload-finalization latency and bandwidth cost.

Revision checklist

Revision checklist

  • Reconstruct publish only complete file versions: Verify the uploaded chunks before saving the new file pointer and change record.
  • Reconstruct preserve both users' edits: Require the version an edit started from; report a conflict if it changed.
  • Reconstruct recover changes missed while a device was offline: Use a durable change log; push notifications only tell the device to check it.
  • Reconstruct what happens if a region fails?: Check that the recovery region has both file metadata and all its bytes.
  • Name the authoritative state, boundary, retry identity and failure-domain durability guarantee.
  • Explain one alternative and exactly which guarantee you would relax.
  • Redraw the request and recovery paths without looking; mark what required a hint.

60-minute interview outline

60-minute interview walkthrough

TimeFocusWhat to cover
0–5 minIntroductionsIntroduce yourself briefly and confirm the interview format.
5–15 minScope and scaleScope uploads, downloads, and multi-device sync. Estimate object traffic separately from metadata writes.
15–30 minHigh-level designTrace a direct chunk upload, metadata commit, and a second device pulling changes by cursor.
30–45 minDeep divesExplain why the file version and change row commit together. Walk through two devices editing the same version.
45–55 minFailure and recoveryRecover an interrupted upload or a lagging device. Explain what must replicate before another region can serve the file.
55–60 minWrap-upSummarize the design and its main tradeoff. Leave time for questions.
On this page
  1. Problem statement
  2. Functional requirements
  3. Non-functional requirements
  4. Back-of-the-envelope estimates
  5. Entities
  6. API design
  7. High-level design
  8. High-level design component walkthrough
  9. Engineering control room
  10. Deep dives — decisions, failures and recovery
  11. Tradeoffs and alternatives
  12. Production scars & failure modes
  13. 90-second interview summary
  14. Explain it without looking
  15. Revision checklist
  16. 60-minute interview walkthrough

Save & sync your Atlas progress

Sync your profile and topic progress across browsers, then return to the same study desk.

Google sign-in will appear here after its Azure provider is configured.

Architecture diagram