You are tasked with designing a chat system that supports real-time messaging between millions of users. Which architectural component is essential to ensure messages are delivered instantly and reliably?
Think about how messages can be pushed to many users instantly without delay.
A message broker or pub/sub system allows real-time distribution of messages to connected clients, ensuring low latency and scalability. Databases and batch processing are too slow for instant delivery, and static file servers cannot push updates.
Your application uses WebSocket connections to push real-time updates to users. As user count grows to millions, what is the best approach to scale WebSocket servers?
Consider how to handle many simultaneous connections and keep clients updated consistently.
Scaling WebSocket connections requires multiple servers behind a load balancer. A centralized message broker helps synchronize messages across servers so clients receive consistent updates. A single server cannot handle millions of connections, polling is inefficient, and databases add latency.
You need to implement a real-time notification system for a web app. Which tradeoff is true when choosing WebSocket over SSE?
Think about the direction and type of communication each protocol supports.
WebSocket allows two-way communication (full-duplex), so both client and server can send messages anytime. SSE only allows server-to-client messages (unidirectional). WebSocket supports binary and text, SSE supports only text. Both use HTTP for connection setup.
In a distributed real-time messaging system, what is the best approach to guarantee that messages are delivered to clients in the exact order they were sent?
Think about how to keep track of message sequence across distributed components.
A centralized message queue that preserves order and sequence numbers ensures clients receive messages in the correct order. Independent servers or unsynchronized brokers can cause out-of-order delivery. Parallel sending without coordination risks message reordering.
You are designing a real-time stock ticker system that pushes price updates to 5 million users. Each user receives 10 updates per second. Each update message is approximately 500 bytes. Estimate the total outgoing bandwidth required per second.
Calculate total messages per second and multiply by message size, then convert bytes to gigabytes.
Total messages per second = 5,000,000 users * 10 updates = 50,000,000 messages/sec. Total bytes per second = 50,000,000 * 500 = 25,000,000,000 bytes/sec = 25 GB/sec.
