Server Sent Events backend written in go. Redis is used to distribute published messages across all backends so that the backend can be scaled horizontally.
The backend is stateless in that it doesn't matter to which instance the message is published, since it will be distributed to all other instances and them sent to the connected clients of the respective instance using event-stream.
Start the compose stack, then visit the webpage at http://localhost:8080. It is a basic chat page. Open it multiple times to see real time events published from one client on all other client pages.
docker-compose up
backend_2 | client connected: 192.168.16.2:37712
backend_1 | client connected: 192.168.16.2:47996
backend_2 | 2022/01/23 23:01:44 publishing message: {"user":"John","message":"Hi"}
backend_2 | 2022/01/23 23:01:44 receiving message: {"user":"John","message":"Hi"}
backend_1 | 2022/01/23 23:01:44 receiving message: {"user":"John","message":"Hi"}
backend_2 | 2022/01/23 23:01:53 publishing message: {"user":"Maria","message":"Hello :)"}
backend_1 | 2022/01/23 23:01:53 receiving message: {"user":"Maria","message":"Hello :)"}
backend_2 | 2022/01/23 23:01:53 receiving message: {"user":"Maria","message":"Hello :)"}