Design a Collaborative Code Editor
Design a browser code pad that people open from a link and edit together in real time, with live cursors, the same final text for everyone, and work that survives refreshes, dropped connections and server crashes.
Problem statement
Design a code editor that several people can type in at the same time from their browsers.
For this exercise, assume a person creates a code pad, picks a programming language for syntax highlighting, and gets a link. Anyone who opens the link can edit the pad without an account; they type a display name when they join.
Everyone in the pad sees the others' changes as they happen, and sees who else is there and where each person's cursor is. Two people may type at the same moment, even on the same line, and every copy of the pad must end up with the same text without dropping anyone's typing.
Someone who refreshes the page, or whose connection drops for a short time, comes back to the current code. A pad keeps working until nobody has edited it for 30 days.
Syntax highlighting happens in the browser. Running the code, user accounts, comments, chat and browsing old versions are out of scope.
Design how edits travel between the people in one pad, how a pad's text is stored, and what happens when two people edit at once or a connection drops.
What to build
- A person creates a pad, chooses its programming language, and gets a link; anyone with the link can open and edit the pad without an account.
- Each person's edits appear for everyone else in the pad as they type, and when two people edit at the same time every copy ends with the same text and nobody's typing is lost.
- Everyone in the pad can see who is currently there and where each person's cursor is.
- Refreshing the page or coming back after a short dropped connection shows the current code, and the link keeps working until the pad has gone 30 days without an edit.
At scale
- For this exercise, assume about 20,000 pads are being edited at the same time at peak, usually with 2 to 5 people each and never more than 10.
- For this exercise, assume about 50,000 small edits per second arrive across all pads at peak, and other people in a pad should see an edit within about 200 milliseconds.
- For this exercise, assume a pad holds at most about 500 KB of text (roughly 10,000 lines).
- For this exercise, assume an edit the server has confirmed must never be lost, even if a server crashes, and a connection that drops for up to a minute should recover without losing what the person typed.