Design Undo and Redo for a Collaborative Doc Editor
Last updated: November 29, 2026
Quick Overview
Design the object model for undo and redo in a text editor like Google Docs: commands that can be applied and reverted, a history with redo invalidation, and coalescing of consecutive keystrokes into one undo step.
0
0
0 solved
Design the object model for undo and redo in a text editor like Google Docs: commands that can be applied and reverted, a history with redo invalidation, and coalescing of consecutive keystrokes into one undo step.
Docs and other Workspace editors make this a natural OOP question at Google. Interviewers check the command pattern, what state each command must capture to revert, history semantics, and whether you can extend the design (coalescing, collaboration).
What the Interviewer Expects
- Uses a command abstraction with apply and revert
- Captures enough state to revert, such as deleted text
- Clears the redo stack on new edits
- Coalesces consecutive typing into one step
- Bounds history memory
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- How does undo work when another user edited the same paragraph?
- How would you add formatting commands?
- How would you persist history across sessions?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
- Commands: insert text at a position, delete a range. Undo reverts the last step; redo re-applies.
- A new edit after undo discards the redo branch.
- Typing "hello" character by character undoes as ...
High-Level Design
Command is an abstract base with apply, revert, and an optional merge. Insert reverts by slicing out its text. Delete records the removed text during apply, since it cannot know it in ad...