Real-Time Chat
In this chapter, we add chat to Courselore and get a new message onto the screens of the room’s other members, first with polling and then with long polling.
After reading this chapter, you should be able to:
- State the requirements and load assumptions for chat in an existing application
- Explain the design decisions in chat’s schema and REST API
- Explain why a room as one document is a poor fit for chat, even though a room stops growing
- Explain why a server using HTTP cannot send a client data the client did not request, and define real-time in the everyday sense
- Compute the delay and the requests per second of polling, and explain the trade-off between them
- Explain how long polling works, what a kept request costs the server, and why a long poll ends after about 30 seconds
- Choose between polling and long polling from how soon a change must show up and how often it happens
- Revise a schema and an API for unread messages, with a read position
- Explain why unread marks for other rooms lead to one long poll per course instead of one per room