TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

105 pointsby nikitaalmost 2 years ago

12 comments

KingMobalmost 2 years ago
Cool article, thanks for sharing.<p>You don&#x27;t mention which version of HTTP you were using, which makes some of my comments here conjecture, but if I had to guess, I&#x27;d say you were using HTTP&#x2F;1.1. Is that right?<p>It would really help if you could break down where the time is being spent. I&#x27;d love to know what fraction of the time is spent in processing, transit, querying the db, etc.<p>Did you consider HTTP&#x2F;2 or 3? I would expect them to have lower setup overhead, and be more competitive with Websockets.<p>In particular, if you were using HTTP&#x2F;2+, did you look into CONNECT proxying? It could replace Websockets while having lower connection setup overhead, albeit at the cost of a little payload unwrapping overhead in the proxy. But theoretically, this could offer both the faster startup of HTTP&#x2F;2+, combined with the lower processing overhead for the db of a TCP stream. Comparing the graphs of 10 queries, it _appears_ that processing HTTP imposes a ~15 ms overhead over raw bytes. (Theoretically, the CONNECT proxy has to obey the host and port in the :authority pseudoheader, but in your case, the proxy would just ignore it, and hook up the edge function to whatever compute node it pleased.)
评论 #36683851 未加载
评论 #36683769 未加载
评论 #36683758 未加载
评论 #36683748 未加载
bluefishinitalmost 2 years ago
It seems like if speed was a concern you wouldn&#x27;t make the extra hop from a serverless function to their websocket server, then on to the db. Instead you could serve your api directly off the app server which would then connect to the db without the intermediary step.
评论 #36683066 未加载
评论 #36683874 未加载
评论 #36682875 未加载
dathinabalmost 2 years ago
But why?<p>The edge is in general not the users browser.<p>So you can do a TLS&#x2F;postgres connection instead of adding additional layers.<p>Sure you want to probably run a patched pg client&#x2F;server which has various optimizations to reduce the number of round trips when opening a connection, but that also applies to any HTTP&#x2F;WebSocket wrapper.
评论 #36684121 未加载
rubenfiszelalmost 2 years ago
What I would absolutely love is to have a proxy server that would act as postgres, and use this new driver to connect to a remote postgres. This would avoid us having to rewrite our remote agents (which require a postgres connection to the main Database) to use an http api. Instead, we could just keep them as it is, using rust&#x27;s sqlx queries, point them to the local proxy. Essentially pgBouncer but through http.<p>Postgres &lt;&gt; Neon HTTP Proxy &lt;---HTTP---&gt; Local Fake Postgres Server &lt;--unix socket--&gt; Agents<p>We need it for the open-source project windmill.dev and we will build this if no one else does it.
评论 #36683434 未加载
评论 #36683730 未加载
Camisaalmost 2 years ago
I tried making a realtime multiplayer game network based on HTTP, sending movement data every 100ms and individual world changes on each HTTP requests by that was taking 50ms each on a wifi local network, I thought that was good enough but then I tested websockets and the round-trip for websocket was around 4ms.
l5870uoo9yalmost 2 years ago
Here is the actual package used [1]. I thought it would have been similar to serverless-pg[2] with initiation outside the handler as with the node implementation. Any insights into how they achieve connection caching (similar to pooling?) on the edge?<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;neondatabase&#x2F;serverless">https:&#x2F;&#x2F;github.com&#x2F;neondatabase&#x2F;serverless</a> [2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;MatteoGioioso&#x2F;serverless-pg">https:&#x2F;&#x2F;github.com&#x2F;MatteoGioioso&#x2F;serverless-pg</a>
评论 #36686314 未加载
评论 #36686317 未加载
CuriouslyCalmost 2 years ago
The biggest selling point of websockets over http is that you can stream the results back easily and quickly, which enables stuff like canceling slow queries easily, a transfer progress bar, etc.
redmalmost 2 years ago
@raoufchebri &amp; @nikita, What about comparisons to CloudFlare Workers using Workers Sock API to connect to PG? [1] I know CloudFlare workers support Neon directly through API so how does that compare to the alternative PG implementations?<p>[1] <a href="https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;workers&#x2F;learning&#x2F;integrations&#x2F;databases&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;developers.cloudflare.com&#x2F;workers&#x2F;learning&#x2F;integrati...</a>
评论 #36682785 未加载
Dhruva23almost 2 years ago
<a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33909616">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;item?id=33909616</a> history. Why were sockets used in the first place?<p>Neon is slow and flaky I am thankful you are making changes but strongmanning your technical choice when you are wrong is concerning as a user. I still use Neon due to not being able to move back to heroku. I also you keep making open source more.
raoufchebrialmost 2 years ago
Blog post author here. Let me know if you have any questions!
评论 #36682740 未加载
评论 #36685916 未加载
评论 #36683805 未加载
评论 #36682889 未加载
PaulWaldmanalmost 2 years ago
Is there anything like this to expose Postgres over gRPC?
评论 #36683841 未加载
评论 #36683828 未加载
nikitaalmost 2 years ago
CEO of Neon here. We have done a lot of latency work. Feel free to ask questions.
评论 #36704982 未加载