Scrivio Interview library
DesignAdvanced6 min read · updated 13 November 2026

A collaborative whiteboard keeps each board's live state in memory on one server, and all users of a board must reach that server. There are 30 servers and 200,000 active boards; servers are deployed daily and sometimes crash.

Design the routing and failover, and explain why cookie-based stickiness is not enough here.

Affinity has to be by board, not by user, so the layer 7 proxy routes on the board id from the path or connection request, using consistent hashing or, better, a directory that maps each board to its owning server. Board state is persisted continuously as an operation log plus snapshots, so another server can load it within seconds after a crash. Deploys drain a server by handing its boards to new owners and telling clients to reconnect, and leases with fencing tokens prevent two servers from owning one board.

Why this question is asked

A collaborative whiteboard is a good example of a stateful service: the live state of each board sits in one server's memory, and every user of that board must talk to that server so they all see the same strokes in the same order. Interviewers ask this to see whether we can design routing around the unit of state and handle failure and deploys without losing work. In this answer, we will see why cookie stickiness fails, compare consistent hashing with a directory, persist board state, drain servers for deploys, and guard against two owners.

1Why Cookie Stickiness Is Not Enough

Cookie stickiness ties a browser to a server. That is the wrong unit here. Alice opens board 42 and her cookie pins her to server 7. Bob opens the same board from another office, gets a different cookie, and lands on server 19. Now board 42 has two live copies in two memories, and Alice and Bob each see only their own strokes. A user may also have several boards open, which may need to live on different servers.

So affinity must follow the board. Every request and every WebSocket connection for board 42 must reach the server that owns board 42, regardless of who the user is. The board id is in the path, for example wss://draw.example.com/boards/42/live, so a layer 7 proxy can read it and route on it.

2Choosing an Owner: Consistent Hashing or a Directory

The first option is consistent hashing at the proxy. Envoy, for example, can use a ring hash or Maglev load balancer with a hash policy on the board id. Each board hashes to a point on a ring, and the server that owns that segment owns the board. The benefit is that no extra service is needed, and when a server is added or removed only about one thirtieth of the boards move, not all of them.

The second option is a directory: a small, highly available service, backed by something like etcd or a replicated PostgreSQL table, that maps board id to server. The proxy asks the directory, caching the answer briefly, and routes there. A directory costs an extra component, but it gives us control that hashing cannot: we can move a specific hot board to a quiet server, place new boards on the least loaded server, and move boards explicitly during a deploy.

Routing boards to servers
ApproachStrengthWeakness
Cookie stickinessno change to the appper user, so one board splits across servers
Consistent hash on board idno extra service, about 1/30 of boards move per changecannot move a hot board or place by load
Directory lookupexplicit moves, load-aware placement, clean drainsanother critical service to run and cache
Affinity by board id is required; the directory adds control over placement.

With 200,000 boards on 30 servers, each server owns about 6,700 boards on average. Boards are very uneven, though: a classroom board with 300 users can be a hundred times heavier than a personal sketch. That unevenness is the main reason I would choose the directory, possibly starting from a hash for the initial placement.

3Persisting Board State So a Crash Is Survivable

If board state lives only in memory, a crash loses it. So the owning server writes every operation, a stroke, a move, a delete, to a durable log as it applies it, for example a Kafka topic partitioned by board id or an append-only table in PostgreSQL. Every few hundred operations, or every minute, it writes a snapshot of the whole board to object storage such as S3 and notes the log position the snapshot covers.

When a server crashes, the directory, or the hash ring, assigns its boards to other servers. A new owner loads the latest snapshot and replays the operations after it, which for a typical board takes well under a second, so users reconnect and continue within seconds. The only work at risk is the operations not yet written to the log, which is why the server acknowledges an operation to clients only after the log write succeeds, or accepts a tiny window of loss as a trade-off for latency.

4Deploying Without Disconnecting Everyone at Once

Servers are deployed daily, so moving boards must be a routine, graceful operation. The deploy marks a server as draining in the directory. For each of its boards, the directory picks a new owner. The old owner flushes the board's latest operations to the log, releases ownership, and sends its connected clients a message saying the board has moved. The clients reconnect, the proxy routes them by the new directory entry, and the new owner loads the board. When the server owns no boards, it stops.

Spread over a few minutes, this moves 6,700 boards without a thundering herd of reconnects, and users see at most a brief reconnecting indicator.

Step throughMoving a board during a deploy
ClientProxyOld serverDirectoryNew server
mark draining, board 42 -> new
flush log, release lease
board moved, please reconnect
connect /boards/42/live
who owns 42?
new server
route connection
take lease, load snapshot + log
board state, live again

9 messages in order. Play them, or step through them one at a time.

The old owner releases before the new owner takes over.

5Preventing Two Owners for One Board

The dangerous case is a server that is not dead but cut off, for example by a long garbage collection pause or a network partition. The directory gives its boards to a new owner, and then the old server wakes up and keeps applying operations. Two servers now write different histories for the same board.

The defence is a lease with a fencing token. Ownership of a board is a lease with an expiry, for example 10 seconds, renewed continuously, and each new grant gets a higher token number. Every write to the operation log includes the token, and the log, or the database, rejects writes with a token lower than the highest it has seen. A server whose lease has expired stops serving the board, and even if it does not notice in time, its writes are rejected, so it cannot corrupt the board.

6Follow-up questions

How do clients learn that their board moved?

In the planned case, the old server tells them directly with a moved message before closing the connection, and the client reconnects to the same URL, which the proxy routes by the updated directory. In the crash case, the connection simply drops; the client reconnects with exponential backoff and jitter, and the proxy routes it to whatever the directory now says. Clients should send the last operation number they saw when reconnecting, so the new owner can send just the missing operations instead of the whole board.

Why not keep every board in a shared database instead of in memory?

Live collaboration needs very low latency and strict ordering of many small operations per second. Putting each one through a shared database with locking adds latency and makes the database the bottleneck for all boards. A single in-memory owner per board gives ordering for free and keeps latency low, while the log and snapshots provide durability.

7Conclusion

In this answer, we saw that affinity must be by board, not by user, so the proxy routes on the board id. Consistent hashing works with no extra service, while a directory adds explicit moves and load-aware placement. Continuous operation logs and snapshots let another server load a board within seconds after a crash, deploys drain servers by handing boards over and asking clients to reconnect, and leases with fencing tokens stop two servers from owning the same board.

What to say in the interviewAbout 80 seconds aloud

Open with

Cookie stickiness is per user, but the state here is per board. Two people on the same board with different cookies would land on different servers and see two diverging copies.

Then, if they want more

So I route on the board id, which is in the WebSocket path. The proxy can do consistent hashing on the board id, for example Envoy's ring hash or Maglev, which needs no extra service and only moves about one thirtieth of boards when a server changes.

I would rather use a directory, a small replicated service mapping board to server that the proxy consults and caches, because boards are very uneven and I want to place busy boards deliberately and move boards explicitly.

For crashes, the owner appends every operation to a durable log, such as a Kafka topic keyed by board, and writes snapshots to S3, so a new owner loads snapshot plus log in under a second.

For daily deploys, I mark the server draining, reassign its boards one by one, the old server flushes and tells clients the board moved, and they reconnect to the new owner. Finally, ownership is a lease with a fencing token, so a paused old server cannot keep writing after a new owner takes over: the log rejects stale tokens.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design the routing and failover, and explain why cookie-based stickiness is not enough...": https://scrivio-interview-library.netlify.app/architecture/load-balancing-networking/0e85aef81e/