17. How would you design a real-time chat service?
HardSystem design
Technical
Show model answer
Clients keep persistent connections (WebSockets) to gateway servers. Messages go to a chat service that assigns an ID and timestamp, persists them (a partitioned store keyed by conversation), and fans them out through a pub/sub layer to the gateways holding recipients' connections.
Cover delivery and read receipts, ordering within a conversation, offline users (store and push notifications), presence, horizontal scaling of gateways, and end-to-end encryption trade-offs.