Skip to content

Decision ADR-0003 · The Lighthouse

Binary hot path + spatial-grid interest management

Accepted ·

Context

Naively broadcasting every player to every player costs O(n²). With 1,000 players at 10 Hz, that is millions of entity updates per second, which is far beyond a t4g.nano and the bandwidth budget.

Decision

  • Hot path: a versioned binary codec (packages/protocol). Each entity is exactly 8 bytes: a 2-byte id, position quantised to 16 bits per axis, yaw to 8 bits and animation as a full byte (packages/protocol/src/binary.ts). Control messages stay JSON, validated with zod.
  • Interest management: a spatial hash grid with 16 m cells.
    • Each cell is a uWebSockets topic.
    • Clients subscribe to their 3×3 neighbourhood.
    • Each tick, the server encodes one delta per changed cell.
  • Caps: each client sees at most the nearest 40 avatars. World layers hold at most 100 players.
    • Status (October 2026): the 40-avatar cap is planned, not built. Today each world layer holds 100 people, and a new layer opens when one fills.
  • Simulation: 20 Hz simulation, 10 Hz snapshots. Clients interpolate 100 ms behind and predict their own movement locally.

Consequences

  • + Cost grows with the number of active cells, not players². That is about 4 KB/s per player, so 1,000 players ≈ 4 MB/s.
  • − There is more client-side complexity: interpolation buffers and reconciliation.