Skip to content

Decision ADR-0002 · The Lighthouse

uWebSockets.js for the real-time gateway

Accepted ·

Context

The server has 512 MB of RAM and must hold 1,000+ concurrent WebSocket connections with headroom. Two common options were considered:

  • socket.io adds protocol overhead and per-connection memory.
  • ws is pure JavaScript, which is slower under high fan-out.

Decision

Use uWebSockets.js:

  • its core is C++;
  • it has built-in pub/sub topics, used for the interest-management cells in ADR-0003;
  • it handles backpressure;
  • it uses SO_REUSEPORT on Linux, which enables zero-kick restarts.

Consequences

  • + Low memory per socket, and fan-out is done natively in C++. A single pub/sub publish reaches every subscriber.
  • − It is installed from GitHub, not npm. The release artifact must bundle the linux-arm64 binary (ADR-0008).
  • − v20.71's ESM wrapper is broken, so the server loads the CommonJS entry with createRequire.