Re:The Performance Cost of Node.js and GraphQL
by tango12 on Monday October 09, 2023 @12:13PM
(#37821900)
I think there are 2 subtleties here on where you optimize perf:
1. Frontend makes n+1 requests to the api. Either use GraphQL or build a custom endpoint that shapes a perfect response.
2. Build an api server that fetches data from the db efficiently without n+1 hitting the DB.
The whole tension introduced with resolver/data-loader ways of building GraphQL, is that while it makes 1 easy, it makes 2 harder. Compared to bespoke REST-ish endpoints.
Re:The Performance Cost of Node.js and GraphQL
by DanielHB on Tuesday October 10, 2023 @03:34AM
(#37829442)
true, but ORMs also make 2. harder
Re:The Performance Cost of Node.js and GraphQL
by bastawhiz on Monday October 09, 2023 @01:48PM
(#37823132)
I'd normally agree, but this is dangerous advice. Why? Because by the time you notice, it's not slow, it's down. N+1 queries don't scale badly as a function of users, it scales badly as a function of cumulative user behavior. One unexpectedly active user can make you self-DoS your database. Even a DB proxy like pgbouncer won't really help because parameterized queries are likely implemented with stored procedures, which require an exclusive DB connection, layering bottlenecks on bottlenecks.
Re:The Performance Cost of Node.js and GraphQL
by SkyPuncher on Monday October 09, 2023 @02:34PM
(#37823620)
In my experience, you typically don’t just improve past slwo with n+1s.
Sure, if you introduce an n+1 to a large, existing table it will slow down. However, most endpoints are going to start at zero.
GraphQL batching together what would be multiple waterfall REST requests is such a perf boost for most cases that N+1 is really only an issue if your DB is bottlenecked.