Discussion: batching GraphQL queries with Apollo vs HTTP/2
In our shared Apollo client, we currently use apollo-link-batch-http. This batches GraphQL queries together if they are executed within a given batchInterval (by default, it's 10ms), with a maximum batch size of 10 queries.
Sometimes this is undesirable. For example, if the batch results in the cost of the server-side query execution increasing dramatically (see #220138 (closed) for an example of a batched query that takes ~18s). In these cases, our guidance is to bypass the batching middleware using query context object with isSingleRequest: true (More information in our docs)
A discussion was started in #f_graphql about whether this was necessary given HTTP2:
@engwan: It's for saving on HTTP requests? Which probably isn't needed with HTTP2
@fguibert: I was curious to understand why we do it by default. It seems to cause complexity issues and can slow down some responses
@engwan: Not sure if HTTP2 is on by default for Omnibus, but I think it's worth a discussion if we should continue doing this. With HTTP2, the expensive part of opening connections is removed and it's actually beneficial to make separate requests so that we get the responses as they are generated from the backend.
@tomquirk: I think there are good reasons for batching by default (mostly the "less requests/connections" part), but agree @heinrich it would be interesting to compare this to HTTP2. It could be the case that, from a client-side perspective, Apollo performs better when dealing with a batched query.
Given the potential upside of having a "one-size-suits-all" approach with HTTP2, we should investigate the performance (with both server-side metrics and user-centric metrics) of using apollo-link-batch-http vs HTTP2.