❔ Performance of many small requests vs less but bigger requests
I have 2 projects: an API hosted on aws and a desktop application. Currently, I'm fetching around 4k records from an API(let's call these "ParentObjects"), each of them with a list of objects("ChildObjects") containing 50~ records on average. I'm fetching 10 ParentObjects at a time in a for loop, so in total, I'm hitting the API endpoint for around 400 times to display the full data. Would it be better to increase the number of fetched records per http request?
8 Replies
It depends on various factors such as the size of each ParentObject and ChildObject, the network speed, and the processing capacity of both the client and server-side. However, increasing the number of records fetched in each request can reduce the number of HTTP requests and improve the overall performance of your application. But, it could also lead to increased latency and bandwidth usage, especially if the size of each ParentObject and ChildObject is large.
You should probably go as big as possible as long as there is no notable delay
Smaller is faster and therefore better user experience, but remember it all has to travel over the web
Going big means it's rendered later, but generally it will be faster in total since the travel over the web back and forth will be way less
So it really depends on what you're doing and if you can accept bigger requests
The responses are aggregated and returned to the user after the fetching is completely done, as in, User doesn't see a thing unless ALL 400 requests have been made
Then you should send them all at once
Also, the average size of response body is around 80 Kilobytes
IMO if you can start rendering once requests come in, you should probably do that, and update the display as you go
But if you have to wait, a big request is better
I assume since this an API, the user keeps requesting the next batch, right? This isn't some websocket we talk about
Because this user request has to go to the API, and the api has to return a response. So you see how this is already an extra step over just sending one big request
So the size change wont matter. It's the fact it has to go back and forth 400 times which will probably cause a huge delay
Yeah, I'll change it to 1 big requests. I didn't pay any attention to the number of requests at first but seeing them rapid firing in fiddler made me reconsider haha, thanks for the help guys!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.