Design a Whiteboard App – Frontend System Design

We’ll walk through the frontend system design for a browser-based drawing tool like Figma, Canva, or Excalidraw. Our goal is an infinite canvas that pans and zooms, a scene of vector objects you can select and transform, and interactions that stay at 60fps even when the file has hundreds of shapes. You’ll see how the scene graph stays normalized, why the renderer is not the model, and why React must not commit on every pointermove. Put simply, the task is to design a whiteboard app that stays smooth with hundreds of shapes on screen.
The interview is a performance problem wearing a design-tool costume. If you draw the scene as absolutely positioned divs, or you setState on every mouse pixel, the demo dies at a few hundred objects. We’ll keep a flat map of shapes, draw on Canvas 2D, overlay HTML for handles and text, and batch paints with requestAnimationFrame.
Problem Statement
Build the frontend for a browser-based design tool like Figma, Canva, or Excalidraw.
Requirements:
- An infinite canvas with pan and zoom
- Shapes (rect, ellipse, text, freehand) that you can select, move, resize, and rotate
- A layers panel with z-order
- Smooth 60fps interactions even with hundreds of objects
- Optional multiplayer cursors (nice to have)
Describe the renderer, the scene graph, hit-testing, and how you keep interactions smooth.
Interviewers want a split you can defend: model vs renderer vs overlay. They also want camera math (screen ↔ world) and a hit-test that does not walk 2,000 shapes in React. Multiplayer is a bonus — nail single-player 60fps first.
Clarifying Questions
| # | Question | Interviewer’s Answer |
|---|---|---|
| 1 | Raster pixels (Photoshop) or vector objects (Figma)? | Vector objects on a canvas. |
| 2 | Do we need boolean ops, components, or auto-layout? | Out of scope. Basic shapes, text, and transforms. |
| 3 | WebGL, Canvas 2D, or SVG? | Your call. Explain the trade-off. |
| 4 | Multiplayer? | If we have time. Single-player is enough to pass. |
| 5 | File format and export? | JSON scene + PNG export. |
| 6 | Undo / redo? | Yes. |
“Vector objects” means you store geometry, not a bitmap. Boolean ops and auto-layout are a different interview. When they say “your call” on the renderer, pick Canvas 2D and explain when you would graduate to WebGL — that is the senior move.
Requirements
Functional
- Pan (space+drag or middle mouse), zoom (pinch / wheel toward cursor)
- Create, select, move, resize, rotate shapes
- Layers list with reorder
- Undo / redo
- Save and load a JSON scene
Non-Functional
- 60fps while dragging or zooming
- Hit-testing stays fast at 1,000+ objects
- Keyboard accessible toolbar and layer list
60fps is a 16ms budget for hit-test + invalidate + paint. That budget is why the drag cannot live in React state. Accessibility applies to the chrome (toolbar, layers, properties). The canvas itself is a custom widget — you still owe a role, a label, and keyboard equivalents for move/delete.
Napkin Math
| Metric | Estimate |
|---|---|
| Objects on a typical file | 200–2,000 |
| Pointer events while dragging | ~60/sec |
| Full scene redraw cost | Too high if every move walks every object in JS and paints SVG nodes |
Scalability Estimates
The napkin table is the constraint. Expand it so the interviewer sees you can turn “2,000 objects” into a frame budget.
| Metric | Estimate | Calculation | Notes |
|---|---|---|---|
| Shapes in a typical file | 200–2,000 | Given | Figma-scale (10k+) needs WebGL. Stay honest. |
| Pointer events while dragging | ~60/sec | One pointermove per frame |
React commit at this rate will jank. |
| Naive hit-tests per second | 60,000–120,000 | 2,000 shapes × 60 moves/sec | AABB first; spatial hash if this shows up in a profile. |
| Visible shapes after cull | ~50–300 | Viewport ∩ bounds, then draw | Zoomed-out “show all” is the worst case. |
| Paint budget | ≤16ms | Hit-test + dirty check + canvas draw | One rAF per frame, never per event. |
| Save payload | ~50–400KB JSON | 2,000 shapes × ~100–200 bytes | Debounce PUT. PNG export is a separate raster pass. |
| Undo stack | tens to a few hundred commands | Inverse ops, not full snapshots | A snapshot per move at 2,000 shapes will OOM. |
The number that matters is “60 moves × 2,000 shapes.” If your architecture multiplies those in the React tree, you have already failed the non-functional requirement.
Architecture

A drawing tool is two trees and a camera, not a page of components. The scene graph is the source of truth: a normalized map of shapes plus a z-order array. The renderer is a function of (scene, camera, viewport) that paints pixels. The overlay is HTML/SVG for selection handles and the text editor, because those need DOM events and accessibility the canvas will not give you.
The View Model owns the scene and the tool state (select | rect | ellipse | pen | text | pan). Pointer events land on the canvas, convert to world coordinates, and mutate the scene through commands. React renders the toolbar, the layer list, and the properties panel. It does not render the shapes.
<CanvasContainer>
useViewModel()
<Toolbar />
<LayerPanel />
<CanvasSurface /> // WebGL or Canvas 2D
<SelectionOverlay /> // HTML/SVG handles on top
</CanvasContainer>
Keep two trees:
- Scene graph (the model): a flat, normalized map of objects by id, plus a z-order array.
- Renderer: draws only what’s on screen. HTML overlays (selection handles, text editing) sit on top so you don’t rebuild those in WebGL.
Component Structure and Responsibilities
- CanvasContainer mounts the View Model, loads the file, and owns the undo stack. It is the only place that talks to
/api/files/:id. - Toolbar is presentational. Clicking Rect sets
tool: "rect". It does not create a shape; the next pointerdown on the canvas does. - LayerPanel lists
zOrderfrom top to bottom. Reorder writes a{ type: "reorder", id, fromIndex, toIndex }command so undo works. - CanvasSurface is a
<canvas>. It listens to pointer events, converts them with the camera, and asks the View Model to hit-test or drag. It paints in rAF when a dirty flag is set. - SelectionOverlay is HTML (or SVG) aligned to the selected bounds in screen space. Handles receive pointer events so you do not have to hit-test resize grips in canvas math on v1.
- TextEditor is a positioned
<textarea>over the text shape. On blur, commit{ type: "setText", id, from, to }and tear the textarea down.
Network Layer and Data Management
A File Manager is enough. This is not a chatty real-time app unless they ask for multiplayer.
- Load:
GET /api/files/:id→ hydrateScene - Save: debounced
PUT /api/files/:id(~1s after the last command) - Export:
POST /api/files/:id/exportor a localcanvas.toBlob()for PNG - Optional sync: if multiplayer comes up, shapes are CRDT items and presence is camera + pointer
Keep a module-level scene store (or a ref in the View Model) so pointer handlers can read the latest shapes without a render. The properties panel subscribes at ~10Hz while dragging, and at every command commit otherwise.
Core Interaction Workflow
- User picks the Rect tool. Toolbar writes
tool: "rect"into the View Model. - Pointer down on the canvas.
screenToWorldgives the origin. A draft shape is stored in a ref, not in React state. - Pointer move updates the draft bounds. A dirty flag is set.
requestAnimationFramepaints the scene plus the draft. - Pointer up commits a
{ type: "add", shape }command. The shape entersshapesandzOrder. Undo can pop it. A debounced save starts. - Select tool: pointer down hit-tests
zOrderfrom the top. On hit, selection is[id]. Overlay handles appear. - Drag: again, mutation lives in a ref until pointer up, then one
{ type: "move", id, from, to }command. The layer list and properties panel catch up on commit (or at 10Hz if you want live numbers).
In an interview, say: Canvas 2D for the scene, HTML overlay for selection and the text editor. That’s how most design tools start.
| Renderer | Pros | Cons | Use when |
|---|---|---|---|
| SVG / HTML | Easy hit-test, accessible text | Dies around a few thousand DOM nodes | Excalidraw-scale diagrams |
| Canvas 2D | Simple API, fast enough for hundreds of shapes | You write hit-testing and text editing yourself | A strong interview default |
| WebGL / WebGPU | Tens of thousands of objects, GPU transforms | More code, text is hard | Figma-scale files |
SVG is tempting because elementFromPoint is free. It falls over when every shape is a DOM node and a drag mutates attributes 60 times a second. WebGL is the right endgame for huge files, but text, selection, and your timebox suffer. Canvas 2D plus an overlay is the answer that ships in 45 minutes.
The product category picks the renderer. Do not say “Figma uses WebGL” and stop.
| Category | Examples | What is hard | Renderer bias |
|---|---|---|---|
| Diagram / whiteboard | Excalidraw, FigJam, Lucid | Connectors stay crisp when zoomed | SVG or Canvas 2D |
| Graphic design | Canva, Illustrator-in-browser | Big images + filters + export | Canvas 2D, worker for filters |
| UI / product design | Figma, Penpot | Tens of thousands of nested frames | WebGL scene + HTML overlay |
| Raster / paint | Photopea | Brush strokes on huge bitmaps | WebGL / WebGPU pixel buffer |
Ask which product they mean before you pick WebGL. A whiteboard interview that starts with shaders is a miss.
Commands, not “the canvas mutated”
Delete, Align Left, and a drag-handle move are the same intent from different inputs. Route them through one command layer.
MOVE_SELECTION is the intent. The command turns it into concrete operations on stable ids ({ type: "move", id, from, to }). The reducer is the only thing that writes the store. Arrow keys, the inspector, and the pointer all fire the same command. A remote collaborator never replays MOVE_SELECTION against *their* selection — they apply the already-concrete op.
That split is why undo, multiplayer, and a command palette stay honest. If the pointer handler writes shape.x directly, none of those work.
Scene Model and Transforms
The model is flat on purpose. Nested groups are a follow-up (a parentId plus a transform stack). For v1, world space is enough.
If they ask about frames: a child stores x/y/rotation in the parent’s space, not the page. Hit-test and the overlay compose ancestor transforms to get world bounds. Reparenting converts the child’s transform into the new parent so the shape does not jump. (parentId, orderKey) is the stacking order — do not rely on array index once you have groups.
type ShapeType = "rect" | "ellipse" | "text" | "path";
export type Shape = {
id: string;
type: ShapeType;
x: number;
y: number;
width: number;
height: number;
rotation: number; // degrees
fill: string;
stroke: string;
text?: string;
points?: { x: number; y: number }[]; // freehand
};
export type Camera = { x: number; y: number; zoom: number };
export type Scene = {
shapes: Record<string, Shape>;
zOrder: string[];
selection: string[];
camera: Camera;
};
Camera math (screen ↔ world) is the bit people skip:
function screenToWorld(p: { x: number; y: number }, cam: Camera) {
return { x: cam.x + p.x / cam.zoom, y: cam.y + p.y / cam.zoom };
}
Zoom toward the cursor is the other half. If you only multiply cam.zoom, the scene jumps. You convert the pointer to world, change zoom, then shift cam.x / cam.y so that same world point is still under the cursor.
Hit-testing: walk zOrder from the top. For a first version, test axis-aligned bounding boxes. For rotation, inverse-transform the pointer into the shape’s local space.
Local-space hit-test, in words: subtract the shape origin, rotate by -rotation, then test against 0..width × 0..height (or the ellipse equation). Freehand paths use the polyline plus a stroke-width tolerance. If this walk shows up above a couple of milliseconds at 1,000 shapes, put objects into a uniform grid keyed by world cell.
State and Data Flow
Pointer events are high frequency. Document commands are not. Treat them differently.
- Pointer event → world point via the camera.
- Active tool updates a transient ref (draft shape, drag delta, lasso).
- Set
dirty = true. One rAF callback paints the canvas from (scene + transient). - On pointer up (or tool commit), push a command onto the undo stack and write the scene store.
- React subscribers (layers, properties, toolbar) re-render on commit. Optionally tick the properties panel at 10Hz during a drag.
- File Manager debounces a PUT. Export is user-triggered, not automatic.
Performance, Prefetching, and Caching
- Invalidate, don’t schedule per event. Ten
pointermoves in one frame become one paint. - Viewport culling: skip shapes whose bounds miss the camera rect. Zoomed-out “fit all” is when you need a cheaper LOD (draw as rectangles, skip strokes).
- Spatial index: a 256px world grid is enough for interview scale. Insert on commit, not on every move.
- Layer list virtualization: 2,000 rows in the DOM will hitch even if the canvas is fine. Virtualize the panel.
- Prefetch: the files list can prefetch JSON for the hovered thumbnail. Do not rasterize a PNG preview on the main thread during hover.
- Device pixel ratio: size the canvas backing store at
cssWidth * dpror zoom looks blurry on retina. Re-size onresizeand on browser zoom.
The scene JSON can live in memory for the session. Persist to IndexedDB after each successful PUT so a refresh before the debounce lands still restores. That is a nice-to-have — mention it, do not build it first.
Data Model
Commands are first-class. The scene is the fold of the command log. That is how undo stays cheap.
type Tool = "select" | "pan" | "rect" | "ellipse" | "text" | "pen";
type Command =
| { type: "add"; shape: Shape }
| { type: "remove"; shape: Shape; index: number }
| { type: "move"; id: string; from: { x: number; y: number }; to: { x: number; y: number } }
| { type: "resize"; id: string; from: Bounds; to: Bounds }
| { type: "reorder"; id: string; fromIndex: number; toIndex: number }
| { type: "setText"; id: string; from: string; to: string };
type Bounds = { x: number; y: number; width: number; height: number };
type FileRecord = {
id: string;
name: string;
scene: Scene;
updatedAt: string;
};
type TransientDrag = {
ids: string[];
startWorld: { x: number; y: number };
originById: Record<string, { x: number; y: number }>;
};
TransientDrag never goes to the server. On pointer up you emit one move per id (or a grouped command) from origin → current. Redo is the command itself; undo is the inverse (swap from/to, or re-insert a removed shape at index).
Keeping 60fps
- Don’t React-render on every pointermove. The drag lives in a ref. React commits on pointerup (or at 10Hz for the properties panel).
- Invalidate, don’t redraw blindly. A dirty flag +
requestAnimationFramebatches many moves into one frame. - Culling: skip shapes whose bounds miss the viewport.
- Spatial index: a simple grid or R-tree if hit-testing a thousand shapes on every move is slow.
- Undo: command stack of inverse ops (
{ type: "move", id, from, to }), not full scene snapshots.
The rAF loop is the piece to write on the board. Events only set data. The loop is the only thing that talks to the canvas.
The paint pipeline (what “draw the scene” actually means)

A drawing tool is not ctx.fillRect in the pointer handler. It is a pipeline you can invalidate at each stage.
- World → visible set. Camera rect vs shape bounds. Miss = skip. At high zoom-out, replace ellipses and paths with their AABB (LOD). A thousand 1-pixel strokes will miss 60fps even if they are “in view.”
- Dirty region. A drag of one rect does not clear the whole backing store if you can clip. Compute the union of (old bounds, new bounds, selection handles) in screen space,
ctx.save(); ctx.beginPath(); ctx.rect(dirty); ctx.clip(), then redraw only shapes that intersect that rect. Full-scene clear is the honest v1; dirty regions are the follow-up that shows you have shipped a canvas. - Layered canvases. Scene on the bottom canvas (redraw on commit, or on dirty). Overlay on a top canvas: selection outline, handles, alignment guides, the in-progress draft. Pointermove then redraws 1 overlay, not 400 shapes. This is the single highest-leverage split in the interview.
- Offscreen raster for static layers. A locked background image or a hundred untouched shapes can live on an
OffscreenCanvasand getdrawImage’d. Invalidate that cache only when those shapes change. - DPR and resize.
canvas.width = cssWidth * devicePixelRatio, thenctx.setTransform(dpr, 0, 0, dpr, 0, 0)so the rest of the code stays in CSS pixels. On resize, rebuild backing stores. Do not CSS-scale a 1× canvas — it blurs.
Hit-testing is the inverse of paint. Walk zOrder from the top, inverse-transform the pointer into each shape’s local space, test the geometry (AABB, ellipse equation, polyline + stroke width). If this walk exceeds ~1ms at 1,000 shapes, index them in a uniform grid keyed by world cell and only test the cell under the pointer plus neighbors.
Text editing is not canvas text input. Double-click a text shape, mount a textarea on the overlay at that shape’s screen rect, commit on blur. Same pattern as Sheets’ one input and Docs’ IME caret. The canvas paints the committed string; it does not own composition.
Export is a separate pipeline: paint the scene at 1:1 world pixels onto an offscreen canvas (no selection, no handles, no DPR trick), then toBlob("image/png"). Do not screenshot the live canvas — you would bake in the overlay and the current zoom.
const dirtyRef = { current: false };
const draftRef = { current: null as Shape | null };
function invalidate() {
if (dirtyRef.current) return;
dirtyRef.current = true;
requestAnimationFrame(paint);
}
function paint() {
dirtyRef.current = false;
const ctx = canvas.getContext("2d");
if (!ctx) return;
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
ctx.clearRect(0, 0, cssWidth, cssHeight);
ctx.setTransform(cam.zoom * dpr, 0, 0, cam.zoom * dpr, -cam.x * cam.zoom * dpr, -cam.y * cam.zoom * dpr);
for (const id of scene.zOrder) {
const shape = scene.shapes[id];
if (!shape || !intersectsViewport(shape, cam, viewport)) continue;
drawShape(ctx, shape);
}
if (draftRef.current) drawShape(ctx, draftRef.current);
}
canvas.addEventListener("pointermove", (e) => {
if (!draftRef.current) return;
const world = screenToWorld({ x: e.offsetX, y: e.offsetY }, cam);
draftRef.current = { ...draftRef.current, width: world.x - draftRef.current.x, height: world.y - draftRef.current.y };
invalidate();
});
setTransform applies the camera once per frame so drawShape can use world coordinates. That is cheaper and less error-prone than converting every vertex by hand.
API
// GET /api/files/:id -> { scene: Scene }
// PUT /api/files/:id -> { scene: Scene } // debounce 1s after edits
// POST /api/files/:id/export -> { pngUrl: string }
Multiplayer, if asked: same CRDT idea as Docs, but the CRDT items are shapes, not characters. Presence is camera + pointer.
Endpoints
| Action | Method & Endpoint | Description |
|---|---|---|
| Load file | GET /api/files/:id | Returns { id, name, scene }. 404 if missing. |
| Save file | PUT /api/files/:id | Body { scene, clientRev }. Debounce ~1s. Last-write-wins unless multiplayer. |
| Create file | POST /api/files | Empty scene. Returns { id }. |
| Export PNG | POST /api/files/:id/export | Server raster, or client toBlob then upload. Returns { pngUrl }. |
| Optional sync | WS /api/files/:id/sync | Only if they ask. Shape-level CRDT updates + awareness (pointer, camera, color). |
Example: Debounced Save from the View Model
function useFileSaver(fileId: string, getScene: () => Scene) {
const timer = useRef<number | null>(null);
const scheduleSave = () => {
if (timer.current) window.clearTimeout(timer.current);
timer.current = window.setTimeout(async () => {
await fetch(`/api/files/${fileId}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ scene: getScene() }),
});
}, 1000);
};
useEffect(() => () => {
if (timer.current) window.clearTimeout(timer.current);
}, []);
return scheduleSave;
}
Call scheduleSave() from command commit, not from pointermove. On tab hide, flush immediately with the same PUT (or sendBeacon if the body stays small).
If they ask for multiplayer, do not CRDT every pointermove. Broadcast committed commands (add, move with from/to). Live drag is presence: a ghost rect on the overlay, same as Docs carets — ephemeral, not in the file. One in-flight save per file; coalesce commands into the next PUT.
Optimizations
The 60fps list above is the core. Two more that show up in follow-ups: handle overlay alignment, and not exporting on the main thread.
Selection handles are HTML, so they must track the camera. Compute screen-space bounds ((shape.x - cam.x) * cam.zoom) and write overlay style once per paint, not via React per handle. If you have eight grips + a rotate knob, that is nine DOM nodes, not a tree per selected shape.
PNG export of a large scene can hitch. Prefer OffscreenCanvas in a worker when the file is big; for the interview, say “rasterize at export scale off the UI canvas so we do not wipe the live view.” Revoke the object URL after download.
Handling User Edge Cases
| Case | Strategy |
|---|---|
| Drag goes outside the window | setPointerCapture on pointerdown so moves keep flowing. Pointer up still commits the command. |
| Zoom on trackpad is also a pan | Treat ctrlKey + wheel (and pinch) as zoom-to-cursor. Plain wheel pans. Do not hijack browser-zoom unexpectedly — document it. |
| Double-click text | Enter text tool, mount the overlay textarea, focus it. Esc or blur commits. |
| Undo during a live drag | Ignore undo until pointer up. Otherwise the command stack and the draft ref diverge. |
| 1,000-point freehand | Simplify the polyline on pointer up (Ramer–Douglas–Peucker). Keep raw points in a ref while drawing. |
| Paste / drop images | Out of scope for v1 if they said basic shapes. If allowed, store a CDN URL like Docs — not a data URL in the JSON. |
| Tab refresh mid-edit | Flush the debounced PUT on visibilitychange. Optional IndexedDB write of the latest scene. |
| Multiplayer two people drag one shape | If asked: last-write-wins on transform is acceptable for v1, or lock the shape (awareness “Ada is dragging”). Do not OT pixel coordinates on the board. |
Pro-Level Optimizations
| Area | Suggestion |
|---|---|
| Paint | One camera setTransform per frame. Cull before draw. Skip shadows while the camera is moving. |
| Hit-test | AABB then local-space. Grid index if a profile says the walk is hot. |
| React boundary | Scene in a ref. Commit on pointerup. Properties panel at 10Hz max. |
| Undo memory | Inverse commands. Cap the stack. Never snapshot 2,000 shapes per move. |
| Retina | Back the canvas at dpr. Recompute on resize. |
| Export | Separate raster target. Revoke blob URLs. Worker if the file is huge. |
Accessibility and Security
- Toolbar and layer list are real buttons; the canvas itself is
role="application"with an aria-label and a text fallback (“200 objects, 3 selected”) - Arrow keys nudge the selection; Delete removes it
- Sanitize
textand exported SVG to avoid XSS - Object URLs for exports get revoked after download
The canvas will never be as accessible as a document. Compensate with chrome: every tool is a focusable button with a shortcut (R, V, T), the layer list is a listbox, and the live region announces “Rectangle added” / “3 shapes selected.” Shift+arrow can nudge by 10px. Do not trap focus inside the canvas so the user can tab to layers.
Security is smaller than Docs but real. Shape text is rendered to canvas (safe) and also into the HTML text editor (must escape). If you add SVG export, treat it like HTML — strip scripts and event handlers. Signed URLs for file JSON if files are not public. Do not put other users’ files behind a guessable integer id without an ACL.
Conclusion: How to Design a Whiteboard App
A drawing tool is a scene graph plus a renderer, not a pile of absolutely positioned divs. Keep the model normalized, draw on canvas, overlay HTML for handles and text, and never let React re-render on every mouse pixel.
The 60fps story is the interview. Pointer events write a ref and flip a dirty flag. One rAF paints a culled scene with a single camera transform. Commands land on pointer up so undo is a small inverse, not a copied file. Hit-testing walks z-order (then a grid if needed) in world space after screenToWorld.
If they ask how this becomes Figma, you already have the seam: swap Canvas 2D for WebGL, keep the same scene and commands, and add a shape-level CRDT for multiplayer. If they ask how this stays Excalidraw-simple, SVG is allowed — say where it dies. Either way you picked a renderer on purpose, and you kept React off the hot path.
