Real Time Updates medium
To broadcast a message to 1 million connected users, iterating through a list and sending one-by-one (`for user in users: send()`) is bad practice. Why?
- A The loop will run out of memory.
- B It requires too much bandwidth.
- C It corrupts the TCP stack.
- D It blocks the Event Loop (in single-threaded languages like Node.js), causing high latency for the last users in the list and freezing the server.
Answer: D. It blocks the Event Loop (in single-threaded languages like Node.js), causing high latency for the last users in the list and freezing the server.
Serializing 1 million I/O calls takes time. If it takes 0.1ms per send, the last user gets the message 100 seconds late. Optimizations involve splitting the list into chunks or using multi-threaded fan-out.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- When a mobile app is closed/backgrounded, it cannot keep a WebSocket open. How does it receive real-time alerts (like 'New Message')?
- For a human user, what is generally considered the maximum acceptable latency for an interaction to feel 'Real-Time' (e.g., typing in a Google Doc)?
- If you want to update a news feed on a website every time a new article is published, what is the simplest (but least efficient) 'Real-Time' technique?
- In a persistent real-time connection, what is the purpose of a 'Heartbeat' or 'Ping/Pong' message?
- Why is Short Polling considered 'Chatty'?
- Server-Sent Events (SSE) are ideal for which type of real-time application?