How Google Docs Handles Simultaneous Edits
Google Docs allows many people to edit one document at the same time.
What happens when two people edit the exact same line at the same second?
A standard system works by reading, modifying, and saving data. If two people save at once, the second person overwrites the first. The first person loses their work.
Google Docs avoids this using Operational Transformation (OT).
It does not send the whole document every time you type. It sends small operations.
For example:
- User A inserts "Beautiful" at position 6.
- User B inserts "Amazing" at position 6.
If the server applied these without changes, one edit would disappear.
Instead, the server transforms the operations.
The server sees User A updated the document first. The document grows. When the server processes User B, it changes the position from 6 to 16.
The final text becomes: Hello Beautiful Amazing World.
Both edits survive.
The system relies on these technical pillars:
- WebSockets for a constant connection.
- Version tracking to know which edit came from which version.
- Real-time event streams to broadcast changes.
Google Docs does not lock the document. Locking would stop everyone else from working while one person types.
Instead, it uses intelligent merging.
The system also transforms your cursor position. If someone adds text in front of you, your cursor moves forward so you do not lose your place.
While Google Docs uses OT, many new tools like Figma use Conflict-free Replicated Data Types (CRDT). CRDTs allow users to merge changes without a central server.
If you are studying system design, remember these points:
- Use WebSockets for low latency.
- Use OT or CRDT for conflict resolution.
- Use version numbers to track changes.
- Sync cursors to improve user experience.
Google Docs does not prevent conflicts. It resolves them by transforming edits so everyone sees the same result.
