WebSockets · Redis · Realtime
2024-12-05 · 6 min read
One server handles thousands of socket connections. But as soon as you scale horizontally, you need state coordination across instances.
TypeScriptconst pub = redis.createClient();const sub = pub.duplicate();io.adapter(createAdapter(pub, sub));
I store presence in Redis with short TTL keys and refresh on activity. It keeps the data lightweight and resilient to disconnects.
Broadcasting to large rooms can blow up memory usage fast. Partition large rooms by region or use targeted channels for updates.