Skip to content
Shubham JangleResources
Networking

Explore topics

Real time communication techniques

Polling, SSE, WebSockets, gRPC, or WebRTC: what's the difference?

  • All of these are real-time communication patterns.
  • The easiest way to understand them is through their use cases.

Category 1: Fetching updates

Short Polling

  • Imagine tracking a food delivery order.
  • Your app asks the server every few seconds where the order has reached.
  • The server responds with the rider's current location.
  • This is Short Polling because the client repeatedly polls the server.

Long Polling

  • Imagine you have submitted an image-generation request.
  • If your app asks every second whether the image has been generated, the server will usually respond with "No" until it eventually returns the generated image.
  • Long Polling reduces those unnecessary requests:
    • The client sends a request.
    • The server keeps that request open until the image is generated.
    • Once the response is ready, the server sends it and closes the connection.

Category 2: Server-to-client streaming

  • When you ask a question on ChatGPT, the server continuously sends the response as it is generated.
  • HTTP Streaming makes this possible by sending data in chunks over one open connection.
  • Server-Sent Events (SSE) is one standard way to implement this in applications:
    • The server can continuously send the generated response to the client.

Category 3: Bidirectional communication

  • This pattern is commonly used in real-time chat applications.

1. WebSockets

  • The connection starts with a normal HTTP request, then upgrades to a persistent, two-way connection.
  • Both the browser and server can send messages to each other at any time, without starting a new request every time.

2. gRPC Bidirectional Streaming

  • This is another option that uses HTTP/2.
  • Both the client and server can independently send messages over the same RPC stream.
  • This enables full-duplex communication, which is useful for real-time backend services.

Category 4: Real-time media

  • For video calls, use WebRTC.
  • WebRTC can establish a direct peer-to-peer connection between users.
  • A server initially helps users connect and handle firewall restrictions.
  • This enables low-latency communication, which is important for live calls.
  • In group calls, a media server helps distribute live streams among participants.

Summary

  • Need to check for updates? → Short Polling or Long Polling.
  • Need to continuously send data from server to client? → SSE (HTTP Streaming).
  • Need bidirectional real-time communication? → WebSockets or gRPC.
  • Need live peer-to-peer audio or video communication? → WebRTC.