Hacker News new | ask | show | jobs
by emilsedgh 3241 days ago
I'm really interested to know how server side API's internally handle overreaching problems and performance.

Client side developers in my current workplace always ask for huge nested objects. We're having a tough time regarding performance as responses are sometimes 6-7 levels of nested objects.

That means a ton of database queries. How does everybody else manage this?

3 comments

you need to denormalize your database so you can just query for those particular objects without a bunch of joins. Put a limit on nesting, but honestly 6-7 levels doesn't sound that bad.
`jsonb` functions in Postgresql can build nested objects in a single select statement. Combine that with proper joins and functional indices and there shouldn't be a problem.
Why is it more than 7 queries?
If its a collection of 100 items it would be 700 queries.
Wouldn't it only be 7?

First query gets the first 100 items, the second query gets the nested associations for those 100 (assuming you couldn't batch it into the first query), the third gets the nested associations for the second's, and so forth. One query for each entity category?