When I started building Carrel, a real-time collaborative CodeMirror 6 workspace, I thought auth was the easy part: hash room passcodes with scrypt , verify on join, done.
Then I tested what happens under brute-force traffic. scrypt is slow on purpose. Run it synchronously and it blocks Node's event loop; run dozens of async scrypt calls uncapped and they saturate libuv's threadpool. Either way, anyone hammering wrong passcodes starts stuttering live keystrokes for everyone typing in the room.
Here is how I ended up structuring the server and protocol across the 3-package TypeScript monorepo ( @carrel/shared , @carrel/server , @carrel/client ):
1. Bounded scrypt + single-use WS tickets
In server/src/throttle.ts , POST /api/rooms/:id/ticket runs async scrypt inside a 4-slot concurrency limiter paired with per-IP progressive lockouts (and ignores X-Forwarded-For unless TRUST_PROXY is explicitly enabled).…