Storage
Network
Bandwidth
// Create channel
POST /channels -> Channel
// Omit other CRUD methods
// Joins a channel and retrieves the last N messages
POST /channels/
// POST message
POST /channels/
User
Channel
Message
ChannelService
MessageService
MessageQueue
MessageProcessor
BroadcastService
Channel management
Client joins a channel
Client rejoins a channel after disconnection
Send message
Database
SSE service
Message queue
Caching
We choose SSE instead of websocket because most of the traffic goes from server to client (unidirectional).
ChannelService, MessageService and MessageProcessor are stateless and we can horizontally scale it.
As discussed, we reduced the number of topics of MessageQueue to ~2000. For 1M message / sec, it averages to 500 per topic, and if we create say 5 partitions. We should tune this based on performance testing.
SSE services should be in a consistent hash ring so we can scale the servers out and in with minimal disruption of existing connections.
Client disconnections are handled as discussed.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?