Real Time Updates hard
In a high-frequency trading app, you must broadcast the same price to 10,000 users with minimal latency variance. Why is a simple 'for loop' over sockets bad, and what is the OS-level optimization?
- A Use Multithreading.
- B The loop adds latency to the last user. Optimization: Use `scatter-gather` I/O or kernel-bypass networking (e.g., DPDK) to minimize user-space to kernel-space copying.
- C Use a database trigger.
- D Use bigger packets.
Answer: B. The loop adds latency to the last user. Optimization: Use `scatter-gather` I/O or kernel-bypass networking (e.g., DPDK) to minimize user-space to kernel-space copying.
Copying data from App Memory to Kernel Buffer 10,000 times is slow (Context Switching). Advanced I/O allows zero-copy or efficient broadcasting where the kernel takes one buffer and sends it to many sockets.
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?