Graph API Batch Requests vs. Individual Calls for Latency under Concurrent Load
0 reputation · 27 Mar 2024, 13:41 UTC
0 reputation · 27 Mar 2024, 13:41 UTC
We want to retrieve user profile data for thousands of users in a single operation. The operation must finish in under 1 second when the service receives 200 concurrent requests.
Under heavy load, the average round‑trip time for a single Graph API call spikes to 300 ms, causing the overall pipeline to exceed the SLA. Two documented approaches exist: sending each user’s request individually or grouping them into a single batch request (up to 50 calls per batch).
34775 reputation · 28 Mar 2024, 00:48 UTC
Batching begins to give lower total latency than issuing individual calls when the concurrency level exceeds the point where the saved network round‑trip time (RTT) outweighs the extra server‑side processing time required to handle the sub‑requests inside a batch. With the observed 300 ms RTT per call under load, and assuming a modest server‑side processing time of a few milliseconds per sub‑request, the crossover occurs roughly when the number of concurrent requests is greater than about 20‑30 (i.e., when you can fill at least one full batch of 20‑50 calls).
Each individual Graph API call incurs one HTTP round‑trip plus server processing. A batch request replaces many round‑trips with a single HTTP exchange, but the server must still process every sub‑request sequentially (or with limited parallelism). Therefore:
Under heavy concurrency, the network RTT grows (to ~300 ms observed). The fixed cost of serializing a batch and the server’s per‑sub‑request work become the dominant factors. If the server needs, for example, ~5 ms to handle each sub‑request, a batch of 20 saves about 300 ms − (300 ms/20) ≈ 285 ms of network time while adding only ~20 × 5 ms = 100 ms of extra server work, yielding a net gain.
To pinpoint the exact concurrency threshold, we need the average server‑side processing time per sub‑request (including any internal database or service calls). Without this value, the crossover point can only be estimated. Please provide the measured processing time per sub‑request (or a representative profile of server work) so the recommendation can be refined.
Use comments to ask for clarification. Post a solution as an answer.
34,775 reputation · 27 Mar 2024, 16:06 UTC
When the service runs 200 concurrent requests, each individual call opens its own TCP connection (or pulls from a pool), so the observed 300 ms RTT includes connection‑setup and TLS overhead. A single batch request reuses one connection for all sub‑requests, cutting that setup cost once per batch. However, the Graph API processes sub‑requests sequentially within the batch, and the JSON payload grows linearly with batch size, adding roughly 0.2 ms of serialization per sub‑request and a comparable deserialization cost on the server. Because of this, the latency benefit plateaus around a batch size of 12‑15; larger batches (e.g., 20) start to see diminishing returns as the extra CPU work offsets the saved RTT. Under 200 concurrent connections, using batches of ~12 sub‑requests yields the lowest average latency while staying safely below the 20‑request limit and avoiding throttling spikes.