Design the front end of a collaborative design and drawing tool like Figma or Canva.
Users work on an infinite canvas: they draw rectangles, ellipses, lines, freehand paths and text, place images, group and layer objects, and move, resize and rotate them. Multiple people can edit the same file at once and see each other's cursors and selections live.
The interviewer adds:
Focus on the rendering technology choice, the scene data model, hit testing and spatial indexing, interaction handling, the multiplayer model, and performance.
A design tool is closer to a game engine than to a typical web app: a scene graph, a render loop, a camera, hit testing, and a tight interaction loop. On top of that sits multiplayer sync. The interviewer is looking for a clear rendering decision, a scene model that suits both rendering and syncing, and credible performance techniques for very large files.
Ctrl+wheel, zoom to fit/selection).| Concern | Target |
|---|---|
| Pan/zoom | 60 fps (16 ms frame) with 100k objects; 120 fps on high-refresh displays where possible |
| Drag latency | object follows the pointer within one frame |
| File open | interactive < 3 s for a 50k-object file; progressive loading by page/frame |
| Multiplayer | remote edits visible p95 < 300 ms; cursors ~20 updates/s, smoothed |
| Memory | < 1 GB for the largest supported files; texture memory budgeted on the GPU |
| Correctness | all clients converge; no orphaned or cyclic tree after concurrent reparenting |
| Accessibility | toolbar, panels and layers fully keyboard and screen-reader accessible; canvas objects reachable via the layers tree |
Assume Figma-like precision, short offline tolerance (reconnects), desktop browsers.
| Option | Strengths | Weaknesses | Fits |
|---|---|---|---|
| SVG/DOM | free hit testing, events, CSS, accessibility, crisp at any zoom, easy export | every object is a DOM node; style/layout cost grows linearly; > ~5k nodes gets janky on pan/zoom | diagram tools with hundreds of shapes, whiteboards with modest content |
| Canvas 2D | immediate mode, simple API, good text via fillText, thousands of shapes fine | CPU rasterisation; you build hit testing, dirty rects, text editing yourself; 50k+ shapes per frame is slow | Canva-like editors, Excalidraw-style whiteboards |
| WebGL2 (or WebGPU) | GPU rasterisation, instancing, tiles cached as textures, smooth zoom | you build everything, including text and vector path rendering (tessellation or SDF/stencil techniques); harder to debug; context loss handling | Figma-scale precision tools |
Decision: a WebGL2 renderer behind a renderer interface, with a Canvas 2D fallback for export and low-end devices, and WebGPU as a future backend. Figma famously renders with its own engine (C++ compiled to WebAssembly) on WebGL, and has been adding WebGPU. A smaller team building a Canva-like product should start with Canvas 2D (or a library like Konva/Pixi) and only move to WebGL when profiling demands it. The DOM is still used for everything that is not the canvas: toolbars, panels, menus, the text editing overlay and the accessibility tree.
| Component | Responsibility |
|---|---|
| Document store | the scene graph (nodes by ID, parent/child order), applies local and remote changes, emits change events |
| Scene index | spatial index (R-tree / quadtree) of world-space bounding boxes for hit testing and culling |
| Renderer | camera transform, culling, batching, tile cache, draws each frame on requestAnimationFrame when dirty |
| Tool state machines | one per tool (select, pen, text…): pointer events in, intents out (preview state + committed changes) |
| Selection and transform | selection set, handles, snapping engine, smart guides |
| Multiplayer client | WebSocket, outbound change batching, inbound application, ack tracking, presence |
| Undo manager | stack of inverse changes for local edits |
| Panels (React) | layers tree, properties panel, toolbar; subscribe to selected-node slices only |
| Workers | image decoding, path boolean ops, export rasterisation, file parsing |
Key separation: React never renders canvas objects. The scene graph is a plain mutable store optimised for the renderer; React panels subscribe to small slices (the selected node's properties, the layers tree for the visible part of the list).
type NodeId = string; // e.g. `${clientId}:${counter}`, globally unique without a server round trip
interface BaseNode {
id: NodeId;
type: 'frame' | 'group' | 'rect' | 'ellipse' | 'path' | 'text' | 'image';
parentId: NodeId | null;
// Fractional index string: ordering among siblings without renumbering
sortKey: string; // e.g. "a0", "a0V", "a1"
name: string;
transform: [number, number, number, number, number, number]; // 2D affine, relative to parent
width: number;
height: number;
opacity: number;
visible: boolean;
locked: boolean;
}
interface ShapeStyle {
fills: Paint[];
strokes: Paint[];
strokeWidth: number;
cornerRadius?: number;
}
interface PathNode extends BaseNode, ShapeStyle {
type: 'path';
// compact command encoding: M x y, C x1 y1 x2 y2 x y, Z
commands: Float32Array;
}
interface TextNode extends BaseNode {
type: 'text';
characters: string;
styleRuns: Array<{ start: number; end: number; fontFamily: string; fontSize: number; fontWeight: number }>;
}
interface ImageNode extends BaseNode, ShapeStyle {
type: 'image';
imageHash: string; // content-addressed blob, uploaded separately
}
type Paint =
| { type: 'solid'; color: [number, number, number, number] }
| { type: 'linear-gradient'; stops: Array<{ pos: number; color: [number, number, number, number] }> }
| { type: 'image'; imageHash: string; scaleMode: 'fill' | 'fit' | 'tile' };
Why these choices:
Map<NodeId, Node>) rather than nested children arrays: a change is "set
property P of node N", which is easy to sync, undo and diff. Children order comes from sortKey.interface RenderCache {
worldTransform: Map<NodeId, Float32Array>;
worldBounds: Map<NodeId, AABB>; // feeds the spatial index
tessellation: Map<NodeId, GpuMesh>; // per-node geometry, rebuilt on shape change
}
interface Camera { x: number; y: number; zoom: number } // world -> screen
interface Presence {
userId: string;
color: string;
cursor: { x: number; y: number } | null; // world coordinates
selection: NodeId[];
viewport: { x: number; y: number; w: number; h: number };
}
Transient interaction state (the rectangle being dragged out, the in-progress path) lives in the tool, not the document, until commit. Optionally broadcast it as "ephemeral" changes so collaborators see the drag in progress.
GET /api/files/:fileId -> { id, name, role, pages: [{ id, name }], version }
GET /api/files/:fileId/snapshot -> binary scene snapshot (all pages, or ?page=:id for lazy pages)
POST /api/images (multipart, returns { hash, width, height })
GET /api/images/:hash?w=512 -> resized image from CDN
POST /api/files/:fileId/exports { nodeIds, format: "png" | "svg" | "pdf", scale } -> { jobId }
// A change is a set of property writes on nodes, plus creates and deletes.
type NodeChange =
| { op: 'create'; node: SerializedNode }
| { op: 'set'; id: NodeId; props: Partial<SerializedNode> } // only changed properties
| { op: 'delete'; id: NodeId };
type ClientMsg =
| { t: 'changes'; batchId: number; changes: NodeChange[] }
| { t: 'presence'; cursor?: { x: number; y: number }; selection?: NodeId[]; viewport?: Viewport }
| { t: 'ephemeral'; changes: NodeChange[] }; // drag previews, not persisted
type ServerMsg =
| { t: 'init'; version: number; snapshot: Uint8Array }
| { t: 'changes'; version: number; authorId: string; changes: NodeChange[] }
| { t: 'ack'; batchId: number; version: number }
| { t: 'reject'; batchId: number; reason: 'PERMISSION' | 'CYCLE' | 'INVALID' }
| { t: 'presence'; userId: string; state: Partial<Presence> };
interface Tool {
id: string;
cursor: string;
onPointerDown(e: CanvasPointerEvent, ctx: ToolContext): void;
onPointerMove(e: CanvasPointerEvent, ctx: ToolContext): void;
onPointerUp(e: CanvasPointerEvent, ctx: ToolContext): void;
onKeyDown?(e: KeyboardEvent, ctx: ToolContext): boolean;
}
interface CanvasPointerEvent {
screen: { x: number; y: number };
world: { x: number; y: number };
pressure: number; // from PointerEvent, for pencil tools
modifiers: { shift: boolean; alt: boolean; meta: boolean };
}
A full text-style CRDT is unnecessary: objects and their properties are the unit of change.
sortKey strings; two clients generating the same key are tie-broken by ID.readPixels stalls the GPU; use sparingly (on click, not on
every move).webglcontextlost, rebuild GPU
resources from the scene graph on restore.setPointerCapture so drags continue outside the canvas; use getCoalescedEvents()
for smooth freehand strokes and pressure for pen input.requestAnimationFrame renders. Never commit a
document change per pointermove: commit once on pointerup (and send ephemeral previews at a throttled rate).ctrlKey set on wheel events in Chromium/Firefox) from scrolling; zoom around
the pointer position.Record the inverse of each local change (previous property values) as one undo step per gesture. Undo applies the inverse as a new change, so it syncs like any other edit. If a collaborator has since changed the same property, the product decision is usually "undo still applies my previous value" (Figma-style), which is simple and predictable; document it.
role="tree")
that mirrors the scene, so screen-reader users can navigate, select and edit objects through panels.prefers-reduced-motion for camera animations; ensure collaborator colours have accessible contrast
with labels.Tool interface.How do you implement the eraser or boolean operations (union/subtract)? Run path booleans in a worker or Wasm module on the paths' geometry; produce a new path node and delete the originals in one change and one undo step.
How does copy/paste across files work? Serialize the selected subtree (with new IDs on paste) to the clipboard as a custom MIME payload plus an SVG/PNG fallback for other apps. Images are referenced by hash, so no re-upload is needed if the hash exists.
How do you render 1 million objects? You mostly don't: culling and LOD mean only visible, pixel-relevant objects render; tiles cache static content; pages load lazily. Memory, not GPU, becomes the limit, so keep compact typed-array representations.
What happens when two people drag the same object? Both see their own drag locally; the server orders the two commits; the last one wins on drop. Showing the other user's selection outline discourages this in practice.
How would you build "follow presenter" for 500 viewers? The presenter's viewport and selection are published on a broadcast channel; viewers interpolate. The server rate-limits and fans out via a pub/sub tier separate from the edit path.
SVG for export? Yes: export walks the scene graph and emits SVG elements, independent of the on-screen renderer. This is another reason to keep the document model renderer-agnostic.
Spotted a mistake or a rights concern? Report an issue