Back to Engineering Notes
Professional ExperienceEngineering Note

8. Real-Time Communication (Pusher)

I use WebSockets (e.g., Pusher) to build real-time features, where the server can instantly push updates to clients without waiting for a new request.

🧠 Pusher / WebSocket (Real-Time Communication)

I use WebSockets (e.g., Pusher) to build real-time features, where the server can instantly push updates to clients without waiting for a new request.


🎯 Core Idea

Traditional apps use request-response (HTTP):

client asks → server responds

For real-time systems:

👉 use persistent connection (WebSocket)

connection stays open
server can send data anytime

🔄 How It Works (Flow)

1. Client establishes a WebSocket connection

1. Client subscribes to a channel (e.g., chat, orders)

1. Server triggers an event

1. Pusher (or WebSocket server) broadcasts the event

1. Clients receive updates instantly


🧩 Key Concepts

Channels

represent topics or groups

Types:

public → open
private → requires authentication
presence → tracks active users

Events

messages sent from server to clients

Examples:

MessageSent
OrderUpdated

Broadcasting

server sends event → WebSocket service → clients

👉 enables real-time communication


🧠 Why I Use This

enables instant updates
removes need for polling
improves user experience
reduces unnecessary API calls

⚖️ Tradeoff Awareness

requires persistent connection
adds system complexity
must handle:
reconnection
authentication
scaling with many users

🆚 WebSocket vs Polling

👉 WebSockets are more efficient for real-time features


📌 Practical Rule

> use WebSockets only when real-time updates are required

Examples:

chat systems
notifications
live dashboards

💬 Summary

I use WebSockets to:

enable real-time communication
improve responsiveness
reduce server load from polling

👉 builds systems that are interactive and efficient for live updates 👍