← All writing

Two people, one code box, no conflicts

Interview Room lets an interviewer and a candidate type in the same code at the same time. This is how both copies stay identical, and how the hidden tests stay hidden.

·5 min read
Interview Room seen by both people at once: the interviewer on the left and the candidate on the right, both on the Two Sum problem, each with the other's cursor and name label in the same code.

In a live coding interview, both people touch the code. The candidate writes the solution; the interviewer adds a comment, or fixes a typo to move things along. If both type at the same moment, the simple approach (the last one to save wins) quietly throws someone’s text away.

Interview Room is my answer: create a room, send the invite link, pick one of 21 practice problems, and both people type in the same code at once, with live cursors and no lost text.

Why typing at the same time is hard

Say the code is cat. At the same moment:

  • Ada adds s at the end, position 3: cats
  • Sam adds the at the start, position 0: the cat

If the server applies Sam’s change first and then Ada’s “insert s at position 3” as it is, everyone gets thes cat. Ada’s position was right for the text she saw, but wrong by the time it arrives.

The fix is to move Ada’s change past Sam’s: Sam inserted 4 characters before position 3, so Ada’s insert now goes at position 7, and everyone gets the cats. That shifting is called operational transformation (OT).

Server-ordered OT, written from scratch

The whole thing is one file of about 350 lines, no library, shared by the browser and the server.

  1. Every edit is an operation, like “keep 12 characters, insert abc, delete 3, keep the rest”.
  2. The server numbers every change. A browser sends its operation with the revision it was based on. If other changes were accepted since then, the server transforms the operation over each of them, applies it, gives it the next number and sends it to everyone else.
  3. Each browser keeps one change in flight. While it waits for the server to confirm, everything else you type is gathered into one buffered change. When someone else’s change arrives first, the browser transforms it over yours, so both survive.
  4. Ties are decided the same way everywhere, so two people typing at the exact same spot always end up with the same text.

Cursors and selections go through the same shifting, so each name label sits on the right character. Undo only undoes your own edits: your undo history is transformed over everyone else’s changes too, so Ctrl+Z removes your text and never theirs.

Why OT and not a CRDT? On Cloudflare, each room is one Durable Object: one place that sees every message in order. That’s exactly what server-ordered OT needs, and the document stays a plain string.

Proving every copy ends up the same

Hand-picked cases are not enough for this kind of code, so the tests also run random sessions: one server and two or three people typing, deleting, pasting and undoing at once, over a pretend network that delivers messages late and out of step.

300 sessions, 31,514 edits and 4,412 undos: every copy ended identical, and no emoji was ever split in half. Another 100 sessions check that no typed character is ever lost.

Keeping the hidden tests hidden

Each problem has examples everyone sees, and hidden tests, hints and a reference solution that only the interviewer should see.

Hiding them in the page isn’t enough: anyone can open the browser’s tools and read what arrived. So the problems live on the server only, and the server sends the hidden parts only to the interviewer’s connection. The tests check this on the raw messages the candidate receives, not on what the screen shows.

That creates a puzzle: how does the candidate run the hidden tests? Their Run tests is executed in the interviewer’s browser, where the tests are, and the server passes back only pass or fail. The values, the error text and any console.log output from a hidden test are removed first, so the candidate can’t simply print the inputs.

The same test run seen by both: the interviewer sees each hidden test’s input, expected answer and result; the candidate sees only “Passed (the input is hidden)”.

Code runs in a sandboxed Web Worker, and before the candidate’s code starts, the worker takes away fetch, WebSocket and the other ways to reach the network. An infinite loop is stopped after 2 seconds per test.

But that left one gap, closed in a later fix. import() is part of the language itself, not something you can take away. A sneaky candidate could write code that “imports” a file from their own site, with a hidden input tucked into the address, and the interviewer’s browser would send it out. The fix was a lock-down header on the worker script itself: it may load nothing but the app’s own scripts and connect nowhere. A worker follows the rules of the headers it was served with, so that one header blocks import() and anything else the clean-up might miss.

Hidden in the page is not hidden. Hidden means it never reaches that browser.

What it can’t do

  • Python can be written but not run. Running it would mean loading a full Python runtime (several megabytes) into the browser, or adding a server that runs code. You still get the starter code and highlighting, and can talk through a solution; the Run buttons explain why they’re off.
  • The candidate’s full test run needs the interviewer’s page to be open, because that’s where the hidden tests are.
  • The sandbox is made for two people who agreed to meet, not for running code from strangers.

Anyone can add a problem

There’s also a problem library. Anyone can submit a problem, and a Check it button runs its reference solution against all its tests before it can be sent. The owner, or a reviewer they invite, approves it, and it then shows up in every room’s list.

Try it

interview-room.pages.dev. Open it in two windows (one private), create a room in one and join in the other, and type in both at once.