A mobile app makes 5–10 sequential HTTP requests to load a single page. On a mobile network, each round trip adds 200–500 ms — totaling up to 2–3 seconds. Typical scenario: /users/{id}, /orders?userId={id}&limit=3, /notifications/unread, /recommendations?userId={id}, /loyalty/points/{id}. The client must wait for all responses and perform transformations. This is not only slow but also consumes excess traffic: loading unnecessary fields (e.g., full address when viewing the cart) increases the volume of transmitted data by 30–50%. We propose introducing an intermediate Backend for Frontend (BFF) layer. Savings on traffic and infrastructure can reach 40% after BFF implementation, with typical savings of $2,000 per month on cloud costs.
BFF is a separate backend service created for a specific client type (web, mobile app, Smart TV). It accepts one request from the client, simultaneously queries the necessary microservices, aggregates data, strips unnecessary fields, and returns the result in a format optimal for that client. The concept is detailed in Martin Fowler's article the original article.
What Problems Does BFF Solve?
N+1 requests and latency. A typical picture: 5–10 sequential calls for one page. BFF reduces this to one call by executing parallel requests to services. Time savings — up to 80% of round trips (4x faster than direct client calls).
Excessive data. A microservice returns fields the client doesn't need (e.g., address when viewing a cart). BFF strips unnecessary data, reducing the volume of transmitted data by 30–50% (e.g., from 150 KB to 80 KB per screen).
Complex authentication. JWT, refresh token, httpOnly cookie — BFF manages sessions centrally without exposing services from the client.
Partial failures. If one service is unavailable, BFF can return a partial response (null for the failed fragment) instead of a 500 error, using retry logic with exponential backoff.
Caching common data. Placing BFF between the client and services allows caching aggregated responses (e.g., recommendations), reducing load on microservices by 40%.
How We Implement BFF: Stack and Examples
In practice, BFF is convenient to build on Node.js with Express or Apollo Server (GraphQL). In our projects we use Node.js, TypeScript, Express or Apollo Server, Redis for caching (ioredis), and axios for HTTP requests.
Example for Mobile App
One endpoint /mobile/dashboard is required, returning profile, recent orders, notifications, and loyalty points.
// mobile-bff/routes/dashboard.ts
router.get('/mobile/dashboard', authenticate, async (req, res) => {
const userId = req.user.id;
const [userResult, ordersResult, notificationsResult, loyaltyResult] =
await Promise.allSettled([
userService.get(`/users/${userId}`),
orderService.get(`/orders?customerId=${userId}&limit=3&fields=id,status,total,createdAt`),
notificationService.get(`/notifications/${userId}/unread-count`),
loyaltyService.get(`/loyalty/${userId}/summary`)
]);
const response = {
user: userResult.status === 'fulfilled' ? {
id: userResult.value.data.id,
name: userResult.value.data.displayName,
avatar: userResult.value.data.avatarUrl
} : null,
recentOrders: ordersResult.status === 'fulfilled'
? ordersResult.value.data.items.map(transformOrderForMobile)
: [],
unreadCount: notificationsResult.status === 'fulfilled'
? notificationsResult.value.data.count
: 0,
loyalty: loyaltyResult.status === 'fulfilled' ? {
points: loyaltyResult.value.data.balance,
tier: loyaltyResult.value.data.tier
} : null
};
res.json(response);
});
Example for Web Client
A web client needs the same data but with a full profile, a larger order list, and analytics.
// web-bff/routes/dashboard.ts
router.get('/web/dashboard', authenticate, async (req, res) => {
const userId = req.user.id;
const [user, orders, stats, notifications] = await Promise.allSettled([
userService.get(`/users/${userId}`),
orderService.get(`/orders?customerId=${userId}&limit=10`),
analyticsService.get(`/analytics/user/${userId}/stats`),
notificationService.get(`/notifications/${userId}?limit=5&unread=true`)
]);
res.json({
user: user.status === 'fulfilled' ? user.value.data : null,
orders: orders.status === 'fulfilled' ? orders.value.data : { items: [], total: 0 },
analytics: stats.status === 'fulfilled' ? stats.value.data : null,
notifications: notifications.status === 'fulfilled' ? notifications.value.data : []
});
});
Expand example for GraphQL BFF
// web-bff/graphql/schema.ts
const typeDefs = gql`
type Query {
dashboard: Dashboard!
order(id: ID!): Order
}
type Dashboard {
user: User!
recentOrders: [Order!]!
stats: UserStats!
}
`;
const resolvers = {
Query: {
dashboard: async (_, __, { userId }) => {
const [user, orders, stats] = await Promise.all([
userService.getUser(userId),
orderService.getRecentOrders(userId),
analyticsService.getUserStats(userId)
]);
return { user, recentOrders: orders, stats };
}
}
};
How to Implement Authorization and Caching in BFF?
BFF is a natural place for centralized authorization and caching. JWT token is verified at the BFF level, refresh token is stored in an httpOnly cookie (for web clients), and Redis cache speeds up responses for rarely changing data.
// authorization middleware
router.post('/auth/refresh', async (req, res) => {
const refreshToken = req.cookies.refresh_token;
if (!refreshToken) return res.status(401).json({ error: 'No token' });
const tokens = await authService.refreshTokens(refreshToken);
res.cookie('refresh_token', tokens.refreshToken, {
httpOnly: true, secure: true, sameSite: 'strict',
maxAge: 30 * 24 * 60 * 60 * 1000
});
res.json({ accessToken: tokens.accessToken });
});
// caching with Redis
import Redis from 'ioredis';
const redis = new Redis(process.env.REDIS_URL);
async function getCachedOrFetch<T>(key: string, ttl: number, fetcher: () => Promise<T>): Promise<T> {
const cached = await redis.get(key);
if (cached) return JSON.parse(cached);
const data = await fetcher();
await redis.setex(key, ttl, JSON.stringify(data));
return data;
}
Choosing Between GraphQL and REST for BFF
If the client is a React app with Apollo Client, BFF can expose a GraphQL schema. This allows the client to request exactly the needed fields without duplicating endpoints. GraphQL BFF is especially useful when data requirements change frequently: the client controls the fetching. However, for simple mobile apps with fixed screens, REST BFF is often more efficient due to lower complexity.
What's Included in the Work
- Audit of the current architecture and identification of frequent round trips.
- Design of a BFF layer for each client (REST or GraphQL).
- Development of APIs with data aggregation and transformation.
- Implementation of authorization (JWT, session-based).
- Caching with Redis or in-memory.
- Error handling and partial failures (Promise.allSettled).
- Documentation (OpenAPI or GraphQL SDL).
- Testing and load testing.
- Deployment (Docker, Nginx, Vercel, AWS Lambda).
Timelines
| BFF Type | Timeline | Cost Range |
|---|---|---|
| REST BFF for 1 client (3–5 endpoints) | 1–2 weeks | $5,000 – $10,000 |
| GraphQL BFF + authorization + caching | 2–3 weeks | $10,000 – $15,000 |
| BFF for 2–3 clients with shared library | 3–4 weeks | $15,000 – $20,000 |
Work Process
- Analysis – study the request pattern and identify bottlenecks.
- Design – define the set of aggregated endpoints and the stack.
- Implementation – write the BFF layer, caching, and authorization.
- Testing – unit, integration, and performance tests.
- Deployment – deploy and set up monitoring.
Typical Mistakes When Implementing BFF
- Duplicating logic – each BFF duplicates transformations. Solution: extract common functions into a shared library.
- Monolithic BFF – one BFF for all clients leads to the same problems as a unified API. Each client should have its own BFF.
-
Ignoring partial failures – if one service fails, BFF should not crash. Use
Promise.allSettledwith circuit breaker pattern. - Lack of caching – without cache, every request hits the services, increasing load and response time.
Why Does BFF Outperform a Unified API?
Without BFF, the client must aggregate data itself, leading to excessive requests and complicated client logic. BFF handles orchestration: one request from client → parallel queries to microservices → aggregation → transformation → response. This speeds up loading (4x faster), reduces traffic (46% less), and simplifies maintenance.
Our Experience
We implemented BFF for a large e-commerce project. Results:
| Metric | Without BFF | With BFF |
|---|---|---|
| Number of requests per screen | 7 | 1 |
| Load time | 3.2 s | 0.8 s |
| Traffic per screen | 150 KB | 80 KB |
| Load on services | 100% | ~60% |
Experience of our engineers: 8+ years in microservice architecture. Order BFF development starting from $5,000 and get guarantees on response time and fault tolerance. Contact us for a free consultation – we'll evaluate your project in 1–2 days. Order BFF development and get optimization tailored to your client.







