SystemKit

Chat System

Keep connections open, persist a message before claiming it was sent, deliver to online and offline devices, and recover after a gateway fails. Also covers ordering, group fanout, and presence.

Lessons

  1. 01Define the conversationDecide whose messages move where before selecting a transport or database.
  2. 02Choose the live transportCompare polling, long polling, server-sent events, and WebSocket against update frequency and connection cost.
  3. 03Place and recover connectionsRoute each device to a healthy gateway and track where its live channel resides.
  4. 04Follow one message end to endPersist a message once, then try live delivery or notify an offline recipient.
  5. 05Order and sync the historyGive each conversation a stable sequence and each device a recovery cursor.
  6. 06Treat presence as a hintUse leases and heartbeats so brief network gaps do not make status flicker.
  7. 07Fan out to a small groupWrite one group message, then deliver it to eligible members and devices.
  8. 08Design the failure pathRecover from broken sockets and stalled workers without losing or duplicating messages.

Practice this chapter

  1. TaskDesign a live customer-support inboxReuse the chat path for a product where people, not sockets, are the scarce resource, and customers often leave before the reply arrives.