Unread badges for a team chat app
Your task
Your team chat app has about 2 million daily users. Each person is in 20 to 200 channels, and channels have 2 to 50,000 members. Most people use the app on a phone and a laptop, and many on a tablet too. Every channel shows how many messages are unread, and the app icon shows the total.
People post about 3,000 messages a second at peak. A person reads a channel on one device and expects its count to clear on the others within a couple of seconds. Phones are often offline for hours and catch up when they reconnect. Messages can be deleted, and a deleted message no longer counts as unread.
Today each device keeps its own counts. It adds one for each new message and clears a channel when the person reads it on that device. People complain about badges that never clear.
What does the server store for each person and channel, and how does each device get its counts right?
It covers
- Unread state
- Multi device sync
- Offline clients