Race-free lobby allocation & matchmaking engine handling server instance concurrency, port assignment, and atomic state synchronization.
A distributed matchmaking architecture engineered to handle concurrent queue sweeps across multiple server nodes without race conditions or port collision.
Architectural Highlights
- Atomic Claim-or-Rollback Dequeue: Each consumer claims players with a blocking
RPOP, so a given player is handed to exactly one node across the cluster. If no partner is available within the window, the first player is pushed back to the queue rather than dropped. - Stateless Application Tier: Server instances hold no queue state. All matchmaking state lives in Redis, so any node behind the Nginx proxy can serve any player, and instances can be added or restarted without draining.
- Server-Authoritative 30 Hz Tick Loop: A fixed-rate loop (33 ms) owns all movement, cooldown, and state resolution. Clients transmit intents, never positions; the server broadcasts the resolved snapshot.
- Lock-Free Input Pipeline: Inbound packets are validated at the socket boundary, then buffered per-match in a
ConcurrentLinkedQueue. WebSocket threads only enqueue; the tick thread drains. - Handshake Authorization on Ticket + Port: The WebSocket handler validates the incoming
matchIdagainst Redis and checks that the connection landed on the port Redis assigned, rejecting spoofed or misrouted sockets before they join a room.