5 ms·
What applications can use a load balancer with WebSockets? All the stuff I've built has required the WS connection to point to the same server anyway (multiplay
by Kiro 10y ago
What applications can use a load balancer with WebSockets? All the stuff I've built has required the WS connection to point to the same server anyway (multiplayer etc) and I feel that's the most common case but I might be completely wrong.
- jdub 10y agoIf your backends aren't stateless, then yeah, you'll have to make sure connections hit the same backend (with session affinity via client IP, cookies, etc). But session affinity is a scalability anti-pattern, which should generally only be used to support legacy applications. Ideally, you'd design your application to use stateless backends, which tend to share state at another layer (the database, memcache, Redis, etc).
- caleblloyd 10y agoI disagree that session affinity, or any affinity for that matter is a scalability anti-pattern. Why add more load on Redis or the Database if you can do it in the app server? Your just adding latency and increasing database load. Unused memory in the app server is free candy.
- jdub 10y agoThere are plenty of good reasons to avoid app server state (and thus session affinity), among them: Inefficiently imbalanced load balancing can affect performance and reliability, app server changes (service restart, reboot, scale down) will drop state causing interruptions (often user visible), etc. If you don't want unused memory on your app servers, don't provision it. :-)
- caleblloyd 10y agoThere's pros and cons to each method, as we've both pointed out. My main point is that it's not an anti-pattern, it's an architecture decision, and the pros and cons of each should be weighed when designing an app. I just finished working on a real-time collaborative document editing service and chose to use document affinity so that the app server could handle collaboration directly. It is extremely performant and I'd choose this approach again any day versus farming out to Redis/RethinkDB/etc. It persists to a database as writes come in, and performs initial load from the database. Local memory accesses are orders of magnitude faster than going over the network, and it reaps the benefits.
- gizzlon 10y agoNot necessarily. The servers can communicate between themselves so it doesn't matter which server the clients connects to. On GCP there's PubSub [1]. Of course this is much slower than shuffling bytes in memory in the same process. It also moves some complexity from service-discovery and into the backed architecture. [1] https://cloud.google.com/pubsub/ https://cloud.google.com/pubsub/
- phelmig 10y agoQuite a few frameworks use redis et. al to manage websocket sessions. I can recommend Django Channels [1] with redis for chat and real time object binding. [1] https://channels.readthedocs.io/en/stable/ https://channels.readthedocs.io/en/stable/