Boss lesson · Unit 04
Design a chat app
Open connections, ordered messages, and offline users
What you practise
- WebSockets vs polling, delivering to offline users, ordering within a conversation, presence, group fan-out, storing history, and what breaks first at scale
Try a question from this lesson
Pick one
Bo sends Ana a message while her app is open. With plain HTTP, where the client asks and the server answers, how does her phone find out?
Correct answer
The phone has to keep asking: anything new?
Why
In request and response the server can only speak when spoken to. So the phone must ask again and again, which is called polling. It works, and it is wasteful and slow in exactly the way chat cannot afford.
The idea
Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.
Concept
WebSockets
A WebSocket starts as an HTTP request and is upgraded into one long-lived connection. After that, either side can send at any moment.
The server pushes a message the instant it arrives, with no asking. The price: each gateway server holds many thousands of open connections, and the system must remember which gateway holds whom.
Polling C: new? S: no
C: new? S: no
C: new? S: yes, 1 msg
WebSocket C <===== open =====> S
either side sends, any time11 more exercises in the app
- 3× type the answer
- 6× multiple choice
- 1× order the lines
- 1× true or false
Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.