HTTP vs. WebSockets: Which one is the fastest for Postgres queries at the Edge

Introducing SQL-over-HTTP with WebSockets to our driver has led to faster query execution. The Neon driver connects from the Edge Function to our proxy via WebSocket, allowing for a real Postgres connection. However, WebSockets have a challenge in minimizing network round-trips. After optimizing the WebSockets driver, we reduced the number of round-trips from nine to four. Comparing WebSockets and SQL-over-HTTP drivers, we found that WebSockets are faster for second queries and above, while SQL-over-HTTP outperforms for single-shot queries. We also discovered that the runtime environment plays a significant role in latency. Developers should consider query type, user location, database location, and API when optimizing for lower latency queries.

https://neon.tech/blog/http-vs-websockets-for-postgres-queries-at-the-edge

To top