Concepts 🚀 Project 🧮 Labs
📚 Learn / Real-time & WebSockets / Polling vs WebSockets

Polling vs WebSockets

Polling: client asks 'any update?' every 5s. WebSocket: server pushes the instant it happens.

Code example

# polling (bad — 5s lag, wasted requests)
setInterval(() => fetch('/api/leaderboard'), 5000)

# websocket (good — instant, no wasted requests)
const ws = new WebSocket('wss://app/ws/leaderboard')
ws.onmessage = (e) => updateLeaderboard(JSON.parse(e.data))

How it works

Real-time updates have two architectures. Polling: the client asks the server 'anything new?' every N seconds. Simple but laggy (5s average delay) and wasteful (99% of polls return nothing). WebSocket: a persistent bidirectional connection. The server pushes the instant an event happens — sub-100ms latency, zero wasted requests. OpenBenchML uses WebSocket for leaderboard updates, benchmark progress, and notifications. The notebook terminal uses WebSocket to pipe PTY bytes back and forth.

🔍 Where this is used in OpenBenchML app/main.py — three WS endpoints. app/routes/notebook.py — one WS for the terminal.