AI Summary
The video explains four methods for pushing real-time updates to web clients: short polling, long polling, server-sent events (SSE), and web sockets. It highlights the trade-offs of each and emphasizes that SSE is often overlooked despite being sufficient for many use cases.
Client asks the server every n seconds for updates. Simple but wasteful and can cause latency.
Client asks, server holds connection open until data is available, then responds. Better than polling but not ideal for high-frequency updates.
Server opens a one-way stream to the client over HTTP. Perfect for scenarios like live comments where clients mostly receive data.
Enables continuous two-way communication, ideal for multiplayer games or terminal emulators.
SSE often provides sufficient low latency, and you can use POST/PUT for writes. Recommended for many real-time update patterns.
Choose the real-time update method based on your use case: polling for simplicity, SSE for one-way streams, and web sockets for full-duplex communication. SSE is often the best balance of simplicity and performance.
Mentioned in this Video
Study Flashcards (5)
What is short polling?
easy
Click to reveal answer
What is short polling?
Client asks the server every n seconds for updates.
00:02
What is long polling?
easy
Click to reveal answer
What is long polling?
Client asks, server holds connection open until data is available, then responds.
00:18
What are server-sent events (SSE)?
easy
Click to reveal answer
What are server-sent events (SSE)?
Server opens a one-way stream to the client over HTTP.
00:32
When are web sockets used?
medium
Click to reveal answer
When are web sockets used?
When both sides need to talk continuously at the same time, like multiplayer games or terminal emulators.
00:46
Why is SSE often overlooked?
medium
Click to reveal answer
Why is SSE often overlooked?
It gives low latency needed in most cases, and you can use POST/PUT for writes.
01:00
💡 Key Takeaways
SSE is the standout
Challenges common assumptions by suggesting SSE is often sufficient, saving complexity.
01:00Full Transcript
[00:02] data to web clients and you don't need web sockets for everything. Start with short polling. The client asks the server every n seconds, anything new? everywhere, but it's wasteful and it can cause latency for your clients. Long
[00:18] polling is where the client asks and the server holds the connection open until there's data and then responds. It's better than polling and it works over infrastructure. But it's not great for high frequency
[00:32] updates that really need to churn. Next are server sent events. For these the server opens a one-way stream to the client over HTTP. This is perfect for applications like Facebook live comments where viewers are almost exclusively
[00:46] receiving a deluge of comments, but they're only sending a few. Finally, we have web sockets. You'll use them when you need both sides to be able to talk continuously at the same time like a multiplayer game or a terminal emulator.
[01:00] SSE is the standout that a lot of engineers gloss over. In most cases it gives you the low latency you need and you can make a post or a put when you need to write. Read more in our real time updates pattern on Hello Interview
[01:13] time updates pattern on Hello Interview and follow us for more system design.