Design & Architecture

Real-Time & WebSockets

Intermediate

Sometimes the UI needs live updates: a case status changing, a notification, a dashboard updating. Real-time connections (WebSockets, SignalR, server-sent events) make this possible. But a long-lived open connection is very different from a request/response call. It needs its own approach to auth, scale, security, and reconnection.

A normal API call is short: authenticate, do the work, respond. A real-time connection stays open and pushes data as things happen. This brings new questions. How do you authenticate and keep authorising over a long-lived connection? What happens when it drops (it will)? How does it scale across multiple server instances? And how do you avoid leaking data to the wrong connection? Use real-time where it genuinely helps, and apply the same security care as everywhere else.

Do not reach for it by default. Polling or normal requests are simpler and often enough. Real-time is worth its complexity when updates are frequent and latency matters.

Secure the connection

Build for scale and failure

Self-review checklist

Why it matters: Real-time features are powerful, but they add long-lived connections with their own auth, scaling, and data-isolation pitfalls. A misrouted message can leak one customer's data to another. Applying the same security and resilience discipline, and using real-time only where it is worth the complexity, keeps live features safe and reliable.