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

Sections

  1. Courselore
  2. Requirements for Chat
  3. The Schema
  4. A Document Database
  5. The Chat API
  6. Messages Other People Send
  7. Polling
  8. Long Polling
  9. Long Polling on the Server
  10. Polling or Long Polling
  11. Unread Messages
  12. New Messages in Other Rooms