One-to-one and group messages: long-lived connections, delivery receipts, offline inboxes and end-to-end encryption.
What is on this board
Parts
- Ana's phone Mobile app
- Ben's phone Mobile app
- Chat gateway WebSocket / realtime server · Erlang
- Who is connected where Key-value store · Redis
- Messages Service · Stores and routes
- Inbox Document DB · Cassandra
- Groups Relational DB · Postgres
- Wake up an offline phone Email / SMS / push · APNs, FCM
- Encrypted media Object storage · S3
- Public keys Secrets manager
- Start Initial state
- Sent State
- Delivered State
- Read State
How they connect
- Ana's phone → Chat gateway: sends a message
- Chat gateway → Messages: route
- Messages → Who is connected where: where is Ben?
- Messages → Inbox: keep until delivered
- Messages → Chat gateway: deliver
- Chat gateway → Ben's phone: message
- Messages → Wake up an offline phone: Ben is offline
- Messages → Groups: members
- Ana's phone → Encrypted media: encrypted photo
- Ana's phone → Public keys: Ben's public key
Notes and decisions
- Chat gateway: One connection per phone
- Inbox: Kept until delivered
- Public keys: The server never sees the message
- Message order: per conversation, with a sequence number from the server, not the phone's clock.
More like this
News feed, like TwitterFan-out on write or on read? Timelines in a cache, the celebrity problem, and how a post reaches millions of followers.
News feed, like TwitterFan-out on write or on read? Timelines in a cache, the celebrity problem, and how a post reaches millions of followers.
URL shortener, like BitlyThe first system design interview question: key generation, heavy reads, a cache in front, and click analytics off the request path.