DEV Community

appsbymuss for #./TECHLAB.MA

Posted on

2 1

Real-Time Communication in Web

(This Blog post is part of a collaborative work between Me and Youssef El Idrissi, Consult his devTo page for more information: https://dev.to/0xw3ston)

What is Real-Time Communication ?

Image description

Real-Time Communication refers to the instant exchange of data between systems, often characterized by low latency, where responses are nearly immediate. This type of communication is critical in applications like messaging, live streaming, gaming, financial trading, and collaborative tools where updates need to be reflected immediately for a seamless user experience.

Some use cases for using RT Comm. Mechanisms:

  • Video and Audio Streaming: RTC is essential for low-latency, real-time media streaming in applications like video conferencing, virtual events, and online broadcasting where any delay can disrupt the user experience.
  • Live Updates and Notifications: RTC is used to push real-time notifications and alerts to users, such as updates in social media feeds, new messages, stock price changes, or sports scores, allowing users to stay up-to-date without needing to reload the page.
  • Instant Messaging and Chat: RTC allows for real-time text, audio, or video messaging, which is essential for communication apps and customer support platforms. Users can see messages immediately without refreshing the app.

What ways/methods exist to achieve that ?

There are 4 common ways to implement live data updates:

  • Short Polling: It involves sending HTTP GET Requests every X seconds (most commonly 5 seconds) in order to fetch if there are any updates from the backend server

Image description

  • Long Polling: This one only sends the backend one single HTTP Request, which the backend tries to delay as much as possible for incase an Update occurs to let the user be notified of it.

Image description

  • SSE (Server-Sent Events): This method is Unidirectional (from Backend to Frontend), which means the Client cannot send data to the server (not using SSE's anyways).

Image description

  • WebSockets: this is the best choice in terms of Bidirectional communication (it allows both the client and backend to communicate with eachother), it is the most common way of implementing real time communication.

Image description

There are other ways such as WebRTC for video streaming but we won't cover that in this post.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More