WebSockets provide a way to establish a persistent, full-duplex communication channel over a single TCP connection between the client (typically a web browser) and the server.

Screenshot 2024-04-06 at 4.38.37 PM.png

Use Cases for WebSockets:

Good example - https://www.binance.com/en/trade/SOL_USDT?type=spot

Why not use HTTP/REST? Why do you need ws?

Screenshot 2024-04-06 at 4.43.39 PM.png

  1. Network Handshake happens for every request
  2. No way to push server side events (You can use polling but not the best approach)

<aside> 💡 Leetcode uses polling when you submit a problem

Screenshot 2024-04-06 at 4.55.10 PM.png

</aside>