-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add notes for system-design/live-comment (#145)
Signed-off-by: Xiaoming Guo <danniel1205@gmail.com>
- Loading branch information
1 parent
bf29180
commit 5f74c1a
Showing
43 changed files
with
487 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...sign/topics/realtime-comments-on-live-video/long-polling-vs-sse-vs-websocket.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Long Polling vs SSE vs WebSocket | ||
|
||
## HTTP Long Polling | ||
|
||
Mechanism: Client sends a request, server holds it open until data is available or a timeout occurs, then responds and | ||
closes the connection. Client immediately sends another request, creating a continuous loop. | ||
|
||
![](resources/long-polling.png) | ||
|
||
### Pros | ||
|
||
* Simple, works over standard HTTP without special libraries. | ||
* Works behind most firewalls and proxies. | ||
|
||
### Cons | ||
|
||
* Inefficient for high-frequency updates due to frequent polling and connection overhead. | ||
* Server-side resource usage can be high due to many open connections. | ||
|
||
## Server-Sent Events (SSE) | ||
|
||
Mechanism: Unidirectional communication from server to client over a single, long-lived HTTP connection. Server pushes | ||
events to the client as they occur. | ||
|
||
![](resources/sse-workflow.png) | ||
|
||
### Pros | ||
|
||
* More efficient than Long Polling for one-way updates. | ||
* Reduced server-side resource usage. | ||
* Simpler JavaScript API for client-side handling. | ||
|
||
### Cons | ||
|
||
* Still relies on HTTP, not as efficient as WebSockets for bidirectional communication. | ||
* Limited browser support compared to WebSockets. | ||
|
||
## WebSockets | ||
|
||
Mechanism: Full-duplex, bidirectional communication over a persistent TCP connection. Enables real-time, two-way data | ||
exchange between client and server. | ||
|
||
![](resources/websocket.png) | ||
|
||
### Pros | ||
|
||
* Most efficient for real-time, bidirectional communication. | ||
* Low latency, low overhead. | ||
* Wide browser support. | ||
* Can handle binary data and messages of any size. | ||
|
||
### Cons | ||
|
||
* Requires WebSocket-specific libraries and protocols. | ||
* Might be blocked by some firewalls or proxies. |
Oops, something went wrong.