r/programming • u/nickcraver • 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
r/programming • u/nickcraver • Feb 17 '16
View all comments
Show parent comment
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.