Bound the Memory of an Editor Undo History
Last updated: November 29, 2026
Quick Overview
The rich-text task description editor keeps every edit for undo, and long sessions leak memory. Implement an undo and redo history capped by both entry count and total bytes.
Asana
November 29, 20260
0
0 solved
The rich-text task description editor keeps every edit for undo, and long sessions leak memory. Implement an undo and redo history capped by both entry count and total bytes.
Asana's web client is a long-lived single page app that people keep open all day, so unbounded client-side structures turn into real memory complaints. The interviewer checks basic data structure choice, correct accounting of a byte budget, and the redo invalidation rule.
What the Interviewer Expects
- Chooses a deque so evicting the oldest entry is O(1)
- Tracks a running byte total instead of recomputing it
- Clears redo on a new edit
- Handles a single entry larger than the budget
- Mentions measuring memory with browser heap snapshots before and after
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 would you coalesce consecutive keystrokes into one undo step?
- How would undo work when a collaborator edits the same description?
- Should the redo stack count toward the budget?
- How do you find what is actually retaining memory in the browser?
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
Record operations that carry a forward and inverse payload. undo returns the inverse to apply, redo the forward. Keep at most N entries and at most B bytes; drop oldest first. A new edit after und...
High-Level Design
A deque for undo (append and pop at the right, evict at the left), a list for redo, and an integer byte counter updated on every push and pop. The byte size here is the UTF-8 length of the inverse pay...