Concepts 🚀 Project 🧮 Labs
📚 Learn / Web & FastAPI / WebSockets

WebSockets

Bidirectional, persistent connection. Used for live leaderboard updates.

Code example

@app.websocket('/ws/leaderboard')
async def ws_leaderboard(websocket: WebSocket):
    await websocket.accept()
    while True:
        data = await websocket.receive_json()
        if data.get('type') == 'ping':
            await websocket.send_json({'type': 'pong'})

How it works

A WebSocket is a persistent bidirectional connection — unlike HTTP, where the client asks and the server answers, with WebSockets either side can send at any time. This is essential for real-time features: when a benchmark finishes, the server pushes the result to every connected browser instantly. The ConnectionManager class in main.py tracks active connections so the broadcast can fan out to all of them.

🔍 Where this is used in OpenBenchML app/main.py — three WS endpoints (benchmark, leaderboard, notifications). app/routes/notebook.py — one WS for the terminal.