Design a Collaborative Spreadsheet (Front End)
Design the browser side of a collaborative spreadsheet like Google Sheets, where several people view and edit one sheet at the same time. Scope it to one active sheet: cells hold literal values or formulas and are edited in the grid or in a formula bar; users select single cells and rectangular ranges with mouse and keyboard; formatting applies at cell, row and column level; rows and columns can be resized; and collaborators' presence, selections and edits show up within about half a second. Sheets can have thousands of rows and columns, almost all empty. A server persists the sheet. Charts, pivot tables, comments, macros and offline editing are out of scope.
Cover the client data model, how the grid is rendered and scrolled, how formulas are recalculated after an edit, the protocol that keeps collaborators converged, and how the client recovers from a reconnect or stale state.
Hints
Hint 1
Do not model the sheet as a dense two-dimensional array. A sparse map keyed by cell address, separate maps of row heights and column widths, and formatting stored in layers (column, then row, then cell, each overriding the last) keep memory proportional to what is filled in.
Hint 2
Virtualise on both axes: render only the visible window of rows and columns, position it with prefix sums of the variable row heights and column widths, and float one editor over the active cell. Selection is a rectangle of addresses, not a flag on every cell.
Hint 3
Formulas form a dependency graph. An edit marks its transitive dependents dirty and recalculates that subgraph in topological order after a cycle check. Edits travel as operations — set cell, format range, resize — tagged with the revision they were based on, applied locally at once and reconciled against the order the server assigns.
Asked at
Sign in to talk to the interviewer — ask what's in scope, what scale to design for, or for a nudge when you're stuck. Conversations save to your account.
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.