Concept
Request Aggregation
When rendering a dashboard, a client might need:
- User Profile (
GET /users/me) - Notification Count (
GET /notifications/unread) - Project List (
GET /projects)
Executing these sequentially from a mobile browser over cellular networks adds multiple high-latency connection roundtrips.
In a BFF architecture, the client fires a single consolidated request to the BFF gateway. The BFF then executes the downstream requests concurrently over local networks, aggregates the payloads, and returns a single merged response:
// Client requests dashboard data from BFF:GET https://api.app.com/bff/dashboard
To prevent mobile/web clients from making multiple slow API roundtrips over high-latency cellular networks, the client sends a single consolidated request to the BFF gateway.
Concurrent Fetching in Node.js
To avoid blocking execution, always execute downstream requests concurrently using Promise.all() (or Promise.allSettled()) rather than executing them sequentially:
// ❌ WRONG: Sequential requests block execution
const user = await fetchUser(); // Takes 100ms
const orders = await fetchOrders(); // Takes 100ms (Total: 200ms)