Cowboy and Websockets
Theory and practice of building a webchat with Cowboy
Loïc Hoguin - @lhoguin
Erlang Cowboy and Nine Nines Founder
Background
Cowboy
- Nearing release of version 0.8
- 100% Websocket standard compliant
- Tested with > 1 million Websocket connections
- Now with a user guide!
Websocket
- RFC 6455 The Websocket Protocol
- HTTP Upgrade
- Two-way connection between the client and the server
- Text and binary
Theory
Webchat architecture
- Users
- One or more room
- One or more users per room
- Messages sent to one room broadcasted to all members
Practice
- This is gonna be LEGEN-- wait for it!
More theory
Many connections per user
- User session processes buffer messages
- User sends messages to rooms
- Room broadcasts to session processes
- Session processes broadcast to connections
Handle disconnects
- Messages get tagged with an auto-incremented id
- Client sends last known eid on connect
- Server atomically replies with all messages > eid
- Connection continues as before
Thanks!
- http://ninenines.eu
- https://github.com/extend/cowboy
- #ninenines on Freenode
- @lhoguin on Twitter
Questions?