System Design
2. Networking Fundamentals10. API Design and ManagementAnimated
WebSockets
A persistent two-way channel between browser and server.
The idea
After an HTTP upgrade, both sides can send messages at any time over one open connection.
Watch it work
Press play, pause, or step through. Some animations have settings you can change.
- current message
- earlier
- failure or attack
The browser starts with an ordinary HTTP request asking to upgrade.
- step:
- 1/5
- from:
- Browser
- to:
- Server
1/5
Time runs downward. Solid arrows are requests, dashed arrows are replies.
Step by step
- 1Client requests an upgrade
- 2Server accepts
- 3Connection stays open
- 4Either side sends messages
Where it is used
Chat, live dashboards, games.
Watch out for
Many open connections use server memory and need sticky routing or a pub/sub layer.