Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Http Performance - Many small requests or one big one

Scenario:

  1. In my site I display books.
  2. The user can add every book to a "Read Later" list.

Behavior:

When the user enters the site, they are presented with a list of books. Some of which are already in their "Read Later" list, some aren't.

The user has an indication next to each book telling them whether the book has been added to the list or not.

My issue

I am debating which option is the ideal for my situation.

Option 1:

  1. For every book, query the server whether it already exists in the user's list.
  2. Update the indicator for each book.

Pro: Very small request to the server, and very easy response (true or false).

Con: In a page with 30 books, I will send 30 separate http requests, which can block sockets, and is rather slow considering the browser and the server have to perform the entire handshake for each transaction.

Option 2:

  1. I query the server once, and get a response with the full list of books in the "Read Later" list as an array.
  2. In the browser, I go over the array, and update the indication for each book based on whether it exists in the array or not.

Pro: I only make one request, and update the indicator for all the books at once.

Con: The "Read Later" list might have hundreds of books, and passing a big array might prove slow and excessive. Especially in scenarios when not 30 books appear on the screen, but only 2-3. (That is, I want to check if a certain book is in the list, and for this I have the server send the client the entire list of books from the list).

So,

Which way would you go to maximize performance: 1 or 2?

Is there any alternative I am missing?

like image 323
Michael Seltenreich Avatar asked Apr 29 '17 04:04

Michael Seltenreich


People also ask

How many API requests is too many?

These plans can vary depending on a particular API or a user's current service plan. But in most cases our servers will reject API requests from a particular application if the request rate exceeds 30 API requests per minute. In this case the client will get an HTTP error with status code 429 “too many requests”.

How fast should a http request take?

Statistical analysis of page load speed data collected using the Navigation Timing API shows that an HTTP request can be reasonably approximated to 0.5 seconds.

Why did your client have to send several HTTP requests?

8.1.A client that supports persistent connections MAY "pipeline" its requests (i.e., send multiple requests without waiting for each response). A server MUST send its responses to those requests in the same order that the requests were received.

How many requests can a REST API handle?

REST API Rate Limits The REST API limits the rate of requests you can make to 15 requests per second. If you are performing certain operations that are resource-intensive, you may adversely affect performance of your system.


1 Answers

I think in 2017, and beyond, the solution is much less about overall performance but about user experience and user expectations.

Nowadays users do not tolerate delays. In that sense sophisticated user interfaces try to be responsive as quickly as possible. Thus: if you can use those small requests to enable the user to do something quickly (instead of waiting 2 seconds for that one big request to return) you should prefer that solution.

To my knowledge, there are many "high fidelity" sites out there where a single page might sends 50, 100 requests. So I would consider that common practice.!

And maybe it is helpful here: se-radio.net podcast episode 277 discusses this topic intensively, in the context of tail latency.

like image 154
GhostCat Avatar answered Sep 20 '22 00:09

GhostCat