07.04

Connection managers and broadcasting

skillmaxingPython with AIConnection managers and broadcasting
Visual lesson

Connection managers and broadcasting

Included with Pro · 4:30
Lessons · 1,056 words

A WebSocket handler knows about one socket: its own. The moment something outside that handler needs to send to it, whether a background worker that finished an escalation, a support agent joining the conversation, or an admin broadcast, you need a place where open sockets are kept and looked up. That place is a connection manager, and it is a small class: a dictionary from a key to a set of sockets, with connect, disconnect, and send_to methods.

Two workers, one conversation
Figure 1Two workers, one conversationA socket lives in exactly one process. Process A cannot reach the socket in B.

The second problem arrives when you run two replicas. A socket lives in exactly one process, so a manager in process A cannot send to a socket held by process B. Redis pub/sub is the fix: every process subscribes to a channel, a send becomes a publish, and each process forwards the message to whichever sockets it holds.

Pro

Continue reading

Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online