Why not polling?

Polling wastes requests and still feels slow. WebSockets keep one connection open and push events instantly.

The approach

  1. Authenticate the socket with the first message.
  2. Publish events only after the transaction commits.
  3. Fan out across workers with Postgres LISTEN/NOTIFY.
await conn.execute("SELECT pg_notify($1, $2)", channel, payload)

The result: notifications arrive in milliseconds.