r/programming • • Feb 17 '16

Stack Overflow: The Architecture - 2016 Edition

http://nickcraver.com/blog/2016/02/17/stack-overflow-the-architecture-2016-edition/
1.7k Upvotes

461 comments sorted by

View all comments

Show parent comment

1

u/Tubbers Feb 17 '16

Are the websockets interacted with from the IIS deployed instance(s)? Or is it a totally separate thing? If they do communicate, how do you deal with relaunching/reloading the IIS deployed instances communicating with the websockets?

22

u/marcgravell Feb 17 '16

Totally disconnected, using Redis pub/sub as a bridge. The web-sockets server subscribes to channels relevant to each socket - for example /u/12345 or /q/361563 or /tag/java/newest - and from the web tier we simply publish to all possibly relevant channels whenever something interesting happens. So if you upvote a post, we publish (separately) to the question channel (to update the score on screen), the owner's user channel (for a rep update), etc. The web-socket server simply tracks which clients are interested in which channels, and hands out the messages. Actually, usually it only sends a "there's something new to know" - we leave the actual information to Ajax to simplify the security model.

Since Redis pub/sub channels don't need to be formally declared, it doesn't matter if either the web-tier or web-socket tier exist in isolation. Messages sent to a channel nobody is listening to just evaporate, and a listener without a publisher just doesn't do anything.

3

u/Tubbers Feb 17 '16

Very interesting, thanks for the response!

2

u/[deleted] Feb 17 '16

Sounds similar to the approach of nginx-push-stream-events. Do you any authenticated events, i.e. events only valid for specific users? Or do you treat the channels as always public info?