KatInterview

Design a Threaded Annotation Layer for a Live Collaborative Canvas

System DesignModel answer
MediumModel answerSystem Designreal-timewebsocketsfan-out

Last updated

Design the backend and real-time infrastructure for a threaded comment system that pins to canvas coordinates or live objects on a shared infinite whiteboard.

Context

Your team is building a collaborative diagramming tool where multiple users edit a shared infinite 2D canvas in real time. Users need to leave feedback directly on the canvas — either pinned to a fixed spatial position or attached to a specific diagram element (a shape, container, or label). When elements move or resize, their attached annotations should follow. When elements are deleted, the system must handle the resulting dangling references without losing the annotation content.

Design the backend and real-time delivery infrastructure to support this annotation system.

Requirements

Functional

  • Anchor modes: An annotation thread can attach to either an absolute canvas coordinate (x, y) or to a canvas element by ID, with a relative offset within that element. Annotations on moving elements must track the element's new position. Annotations on deleted elements must degrade gracefully — content is preserved and the annotation renders at its last known position with a visible indicator.
  • Thread operations: Users can create a thread, reply, edit or delete a comment, and mark a thread resolved or reopen it.
  • Live delivery: All annotation activity — new comments, edits, resolution, and typing indicators — must reach active board viewers with sub-100 ms latency.
  • Mentions: Inline @mentions in comment bodies must trigger async notifications via email, push, and in-app channels.
  • Offline resilience: Client retries after a network interruption must not create duplicate comments. Reconnecting clients must recover any missed events.

Non-Functional

  • Scale: 10 million DAU, 50 million annotation operations per day. Peak scenario: a single "hot board" with up to 20,000 concurrent viewers.
  • Ordering: Comments within a thread must be strictly ordered. Spatial position updates may be eventually consistent.
  • Durability: Any annotation the server acknowledges must never be lost.

What to Cover

  1. Data model and anchor strategy — Schema for threads, comments, and anchors. How concurrent element transforms (move, resize, delete) are reconciled without coupling the comment service to geometry logic.
  2. API and transport — REST endpoints for durable writes and the real-time protocol (WebSocket or SSE) for live delivery, including reconnect and deduplication.
  3. End-to-end architecture — Flow from a client write through persistent storage, an outbox/CDC pipeline, a pub/sub layer, and the fan-out tier to connected clients.
  4. Hot-board problem — How the system stays healthy when tens of thousands of viewers are watching the same canvas simultaneously.

Hints

Hint 1

Start by separating the two fundamentally different traffic types: durable comment writes (low volume, must not be lost) and ephemeral signals like typing indicators (high frequency, can be dropped). They need different treatment throughout the stack.

Hint 2

For element-anchored pins, think about what coordinate space you store. Absolute pixel offsets become wrong every time the element moves or resizes. A normalized local offset — a fraction of the element's bounding box — stays correct through transforms and means the comment service never needs to recompute geometry.

Hint 3

The hot-board fan-out problem is not about write throughput; it is about delivery. One comment to 20,000 viewers is 20,000 pushes. The key is hierarchical fan-out: each edge gateway subscribes once per board, not once per connection, so the broker emits a small number of messages regardless of viewer count.