API Fundamentals Course
API Fundamentals
/
Advanced

Request Batching

Definition

An optimization technique where multiple separate API requests are combined into a single, comprehensive request to reduce network latency and overhead.

Explain Like I'm New

If you need milk, eggs, and bread, you don't drive to the store 3 separate times. You write a grocery list, drive once, and buy all 3. Batching allows an app to ask the API for Users, Posts, and Comments in one single HTTP request.

Real World Example

GraphQL natively supports batching. If 5 different React components on a screen all try to fetch data at the exact same millisecond, Apollo Client intercepts all 5, combines them into one massive GraphQL query, and sends only 1 network request.

Common Use Cases

  • Reducing HTTP overhead
  • Mobile battery optimization
  • GraphQL ecosystems

Interactive Example

Loading...
Console output will appear here...

Interview Questions

basic

  • What is the primary performance bottleneck that Request Batching aims to solve?

intermediate

  • How does the 'N+1 Problem' in REST architectures relate to Request Batching?

Flash Cards

Question

Primary bottleneck?

Click to reveal answer
Answer

Network Latency. Establishing a new HTTP/TCP connection takes time. Making 50 small requests takes significantly longer than making 1 large request, simply because of the travel time of the signals.

Question

N+1 Problem?

Click to reveal answer
Answer

In REST, to show a list of 10 authors and their books, you might make 1 request to get the authors, and then 10 separate requests to get the books for each author (1 + 10 = 11 requests). Batching allows the client or an intermediate layer (like Facebook's DataLoader) to combine those 10 requests into a single query.