Supabase Realtime latency spikes under concurrent WebSocket connections
0 reputation · 30 Aug 2022, 22:20 UTC
0 reputation · 30 Aug 2022, 22:20 UTC
Goal: Determine whether the increase in broadcast latency observed in Supabase Realtime is caused by connection‑pool exhaustion, PgBouncer backpressure, or Node.js event‑loop lag when many clients open WebSocket connections simultaneously.
Constraints: The threshold at which latency becomes noticeable is unknown and may differ between free and paid project tiers; network jitter could also contribute. Uncertainty remains about which internal metric best predicts the latency rise and whether the behavior is intrinsic to the managed service or specific to a project’s configuration.
Questions: What concurrent WebSocket connection count begins to produce measurable latency increase? Which metric—PgBouncer wait time, Node.js loop lag, or database replication lag—correlates most strongly with the observed latency? Do latency patterns diverge between free and paid Supabase projects under identical load conditions?
35275 reputation · 30 Aug 2022, 23:17 UTC
During a surge of concurrent WebSocket connections, the most common latency driver in Supabase Realtime is the authentication overhead that occurs on every new handshake. The Realtime engine is written in Elixir/Phoenix and runs on the BEAM VM, which handles concurrency via lightweight processes. Therefore, Node.js event‑loop lag is not a factor, and broadcast messages do not hit PgBouncer or rely on WAL replication, making those mechanisms unlikely culprits for broadcast latency spikes.
Monitoring Database CPU Utilization and Auth Query Latency will usually reveal the root cause of the observed latency.
Free tier projects run on shared resources with lower CPU and memory limits. Consequently, the threshold at which auth queries saturate the database is lower, leading to earlier onset of latency spikes under identical load conditions. Paid tiers provide dedicated resources and higher priority, so the same number of connections will generally produce less latency.
k6 or a similar WebSocket load‑testing tool to increase concurrent connections in increments of 50 or 100, recording the same metrics.To refine the recommendation further, could you share the average payload size of your broadcast messages? Larger messages may shift the bottleneck toward network bandwidth on the Realtime instance rather than CPU.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.