A backend-for-frontend (BFF) built on GraphQL is great for product teams: one query, exactly the fields the page needs. It also makes one thing easy to miss. Nothing reaches the browser until the slowest resolver on the critical path finishes. On one high-traffic page flow, that showed up as a high TTFB.
Measure per resolver, not per request
The overall request time tells you that it’s slow, not where. I added timing around resolvers and upstream calls. Apollo-style tracing, OpenTelemetry spans or a simple Server-Timing header all work. Then I read the trace as a waterfall. The pattern to look for is steps that run one after another but don’t depend on each other.
The classic: accidental sequential awaits
// Before: total time = a + b + c
const listing = await getListing(id);
const pricing = await getPricing(id);
const dealer = await getDealer(id);
// After: total time ≈ max(a, b, c)
const [listing, pricing, dealer] = await Promise.all([
getListing(id), getPricing(id), getDealer(id),
]);
Two related issues show up just as often:
- N+1 upstream calls when a list field resolves each item on its own. Batch them with a DataLoader per request.
- Non-critical data on the critical path. If a field isn’t needed for the first render, move it to a separate query, or
@deferit if your stack supports that.
Keep it fixed with a regression test
Performance fixes quietly regress when someone adds “just one more call”. I test the shape of the work, not the milliseconds:
it('resolves the page without serial upstream calls', async () => {
const calls = trackUpstreamCalls();
await execute(PAGE_QUERY, { id: 'abc' });
expect(calls.maxConcurrentDepth()).toBeLessThanOrEqual(2);
expect(calls.count('getDealer')).toBe(1);
});
Wall-clock assertions are flaky in CI. How many calls, and in how many sequential rounds is stable, and it’s what actually drives TTFB.
Takeaways
- TTFB in a BFF equals the critical path of your resolvers. Draw it.
- Parallelise independent calls, batch list lookups, and push optional data off the first response.
- Guard the fix with a test on the call pattern, not on timing.