Collaboration and heavy clients · senior
Case study: Figma-like canvas basics
A canvas editor keeps a scene graph of shapes separate from rendering, draws with Canvas or WebGL using a pan-and-zoom transform, finds what is under the pointer with a spatial index, redraws only what changed per animation frame, and syncs edits per object property.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Rendering choice: SVG/DOM is easy (hit-testing, accessibility) for hundreds to a few thousand shapes; Canvas 2D or WebGL scales to many more but you build hit-testing, text and accessibility yourself.
- Scene graph: nodes { id, type, parentId, position, props }; Figma stores the parent link and a fractional position on the child as one property, so moves are atomic.
- Viewport: world ↔ screen transform with pan (x, y) and zoom; zoom around the cursor so the point under it stays fixed.
- Hit-testing and culling: a spatial index (quadtree, R-tree or a simple grid) to find shapes under the pointer and to skip drawing off-screen shapes.
- Render loop and input: requestAnimationFrame with dirty flags, redrawing only changed regions or layers (OffscreenCanvas in a worker for heavy work); pointer events with setPointerCapture for selection, drag, resize handles and snapping; keyboard shortcuts.
- Multiplayer (Figma): WebSocket to a per-document server process; the server orders changes; last-writer-wins per property; client-generated ids so creation works offline; cursors on a separate channel.
- Undo/redo: commands with inverse operations, per user; Figma's rule: undoing many steps, copying, then redoing must leave the document unchanged.
- Accessibility: a canvas is invisible to screen readers, so keep a parallel DOM/ARIA layer list and full keyboard support.
The red pen
Common traps: mistake → fix
Mistake: Re-render a React tree on every mouse move
Fix: use an imperative render loop for the canvas.
Mistake: Mix screen and world coordinates
Fix: objects drift when zoomed.
Mistake: Loop over every shape to hit-test
Fix: slow with 100k shapes; use a spatial index.
Mistake: Last-writer-wins works for text too
Fix: concurrent text edits get lost; text needs OT/CRDT.
Easy to hard
Questions interviewers ask, easy to hard
- Design the frontend of a simple Figma-like design tool.
- SVG or canvas? Why?
- How do you zoom around the mouse pointer?
- Two users move the same rectangle at once. What happens?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.