0
0
HLDsystem_design~3 mins

Why WebSocket for real-time communication in HLD? - Purpose & Use Cases

Choose your learning style9 modes available
The Big Idea

What if your app could talk instantly without waiting or refreshing?

The Scenario

Imagine you want to chat with a friend online, but every time you send a message, you have to refresh the page to see if they replied. This back-and-forth refreshing feels slow and frustrating.

The Problem

Manually refreshing or repeatedly asking the server for updates wastes time and resources. It causes delays, uses more internet data, and makes conversations feel unnatural and laggy.

The Solution

WebSocket creates a direct, open line between your device and the server. This lets messages flow instantly both ways without waiting or refreshing, making real-time chat smooth and fast.

Before vs After
Before
setInterval(() => fetch('/messages').then(showMessages), 5000);
After
const socket = new WebSocket('wss://server'); socket.onmessage = e => showMessage(e.data);
What It Enables

It enables instant, two-way communication that feels as natural as talking face-to-face.

Real Life Example

Online games use WebSocket to instantly share player moves so everyone sees the action live without delays.

Key Takeaways

Manual polling is slow and wastes resources.

WebSocket keeps a live connection for instant updates.

This makes real-time apps like chat and games smooth and responsive.