Building Real-Time Applications: Architecture Guide
Real-time — chat, notifications, live dashboards — requires persistent connections. WebSockets, SSE, or polling. Here's how to architect real-time features.

Table of Contents
WebSockets
Full-duplex. Server pushes to client. Best for: chat, collaboration, gaming. Socket.io, ws. Need sticky sessions or Redis pub/sub for horizontal scaling.

Server-Sent Events
One-way: server to client. Simpler than WebSockets. Best for: notifications, live updates. Native browser support.
Polling
Client requests periodically. Simple, works everywhere. Higher latency, more requests. Use when real-time isn't critical.
Scaling Real-Time
Redis pub/sub to broadcast across instances. Sticky sessions or shared state. Consider managed: Ably, Pusher, or Supabase Realtime.
Frequently Asked Questions
Build or buy real-time?
For simple (notifications, live updates): Pusher, Ably, Supabase. For complex (chat, collaboration): consider custom with Socket.io + Redis.