Design Offline-First Document Autosave and Synchronization
Design a browser-based autosave system that preserves edits offline, synchronizes them safely after reconnect, and resolves concurrent changes without silent data loss.
Problem statement
For this exercise, assume a signed-in user edits text documents in a browser on one or more devices. The editor must durably record each local change before labeling it saved locally, continue working without a network connection, and synchronize pending changes when connectivity returns.
A server-side document history is authoritative for cloud state. Stable operation identities and base versions make synchronization retries safe.
If local and remote edits do not overlap, the system may merge them automatically; if they overlap, it must preserve both versions and surface an explicit conflict rather than silently overwriting either one. The interface distinguishes saved locally, syncing, saved to cloud, and conflict states.
Design the browser persistence model, autosave lifecycle, synchronization contracts, server architecture, conflict handling, quota and crash recovery, and observability. Real-time multi-user cursor presence, permissions and sharing, rich-media attachments, and arbitrary binary files are outside scope.
What to build
- The browser durably records edits and restores the latest local document state after refresh, tab closure, or a short process crash, including while offline.
- A reconnecting client can retry bounded batches of pending changes and learn exactly which operations the server accepted without duplicating their effects.
- The system merges non-overlapping local and remote changes and preserves both sides of an overlapping conflict until the user resolves it.
- The editor reports whether work is only local, synchronizing, cloud-acknowledged, or blocked by a conflict or persistence failure.
At scale
- For this exercise, assume five million daily active users, up to three active devices per user, and a peak of 25,000 synchronization requests per second.
- For this exercise, assume a text document is at most 2 MB, one synchronization batch carries at most 500 operations or 256 KB, and a browser may retain up to 50 MB of unacknowledged and recovery data.
- For this exercise, acknowledge a healthy local autosave within 100 milliseconds at p95, acknowledge an online cloud save within two seconds at p95, and support catch-up after as long as 30 days offline.
- For this exercise, a cloud-acknowledged revision must survive a single-zone failure, while unacknowledged operations must never be evicted silently when browser storage approaches its quota.