feat(signaling): add sticky session load balancing with HAProxy

Merged
HA
3mo ago
+427-43

Closes: #36

Summary by cubic

Adds sticky-session load balancing for signaling via HAProxy so each client stays on the same Node instance. Nginx now forwards backend traffic to HAProxy on port 8080, and the backend exposes instance IDs for easier debugging.

  • New Features

    • HAProxy HTTP frontend (8080) with cookie-based sticky sessions (SERVER_USED + dynamic-cookie-key) and leastconn; TURN TCP remains source-balanced; template added for easy config.
    • Backend now requires INSTANCE_ID, includes it in connection logs, and emits a debug:instance socket event; Makefile targets to run node-1 (:3000) and node-2 (:3001).
  • Migration

    • Set INSTANCE_ID and NODE_ENV in backend env; render haproxy.template.cfg with BACKEND_PORT and TURN_TCP_PORT to produce haproxy.cfg; ensure Nginx points backend to 127.0.0.1:8080 (image v6).
    • Update any API callers to use the new prefix /api/v1 (was /backend/api/v1).

Summary by CodeRabbit

  • New Features

    • Added development configuration for environment and server instance identification.
    • Added commands to run separate backend instances on ports 3000 and 3001.
    • Added connection diagnostics showing which server instance handles a socket connection.
    • Added HAProxy support for TURN traffic and load-balanced signaling connections.
  • Bug Fixes

    • Updated API routes to use the /api/v1 path.
    • Updated proxy routing to forward backend requests to port 8080.
    • Updated the Nginx deployment image for improved compatibility.