Let one API call fan out to several backend services and combine their results, so the client makes one round trip instead of several.
A product page might need data from a catalog service, a pricing service, a reviews service, and an inventory service. If the mobile app calls all four directly, that's four round trips over a possibly slow or high-latency connection, each with its own failure mode to handle client-side.
The client makes a single call to a gateway. The gateway calls the necessary backend services — in parallel where possible — and combines their responses into one payload shaped for that client, before returning it in a single response.
The client issues one call to `getProductPage`; the gateway handles calling three services concurrently and assembles one combined result.
const catalogService = async (id) => ({ id, name: "Wireless Mouse" });
const pricingService = async (id) => ({ id, price: 29.99 });
const reviewsService = async (id) => ({ id, rating: 4.5, count: 128 });
async function getProductPage(id) {
const [catalog, pricing, reviews] = await Promise.all([
catalogService(id),
pricingService(id),
reviewsService(id),
]);
return {
id,
name: catalog.name,
price: pricing.price,
rating: reviews.rating,
reviewCount: reviews.count,
};
}
// The client makes exactly one call and gets back one combined shape.
const page = await getProductPage("sku-101");
console.log(page);