Backend-for-Frontend Pattern for Web and Mobile

How I use BFF layers for web/mobile aggregation while keeping domain services client-neutral, including fan-out, caching, timeouts, authentication and avoiding business-logic leakage.

Romharshan Singh
Romharshan SinghSenior Solution Architect • AI & Cloud Mentor
1 September 20262 min read0 viewsUpdated 1 Sept 2026
Backend-for-Frontend Pattern for Web and Mobile

Backend-for-Frontend Pattern for Web and Mobile

Why I use BFF

A mobile application and desktop web application can use the same business capabilities but need different payloads.

Without BFF:

plaintext
mobile -> 8 microservice calls
web    -> 12 microservice calls

The browser becomes the integration layer.

A BFF can provide:

plaintext
Mobile -> Mobile BFF --\
                        -> Domain Services
Web    -> Web BFF -----/

NestJS composition

typescript
@Get('/home')
async home(
  @Req() request: AuthenticatedRequest,
) {
  const userId = request.user.id;

  const [
    profile,
    upcomingBookings,
    offers,
  ] = await Promise.all([
    this.customer.profile(userId),
    this.booking.upcoming(userId),
    this.offers.forUser(userId),
  ]);

  return {
    profile: {
      name: profile.displayName,
    },
    bookings:
      mapMobileBookings(
        upcomingBookings,
      ),
    offers:
      offers.slice(0, 5),
  };
}

The BFF shapes data.

It should not decide:

plaintext
whether booking can be cancelled
how refund is calculated
whether supplier can bid

Those are domain rules.

Next.js as BFF

For a Next.js site, server-side routes/actions can perform BFF responsibilities:

typescript
export async function GET() {
  const [profile, articles] =
    await Promise.all([
      api.get('/profile/me'),
      api.get('/articles/latest'),
    ]);

  return Response.json({
    profile: profile.data,
    articles: articles.data,
  });
}

I still separate that composition from reusable backend domain services.

Authentication

The BFF can hold a secure server-side session/token and call internal APIs.

This can reduce sensitive token exposure in browser JavaScript.

But authorization still belongs downstream.

Caching

BFF caching is useful for:

plaintext
navigation metadata
public reference data
CMS content

I avoid caching per-user sensitive responses unless keys and invalidation are very carefully scoped.

Failure scenarios

One downstream call fails

Define partial response or fail complete request depending on user journey.

Fan-out becomes large

Move expensive aggregates to a read model.

BFF duplicates business rules

Refactor those rules back into owning services.

Web and mobile BFFs diverge excessively

Share contracts/utilities where useful without forcing the clients to return identical shapes.

Production checklist

  • Keep domain rules out.
  • Bound dependency timeouts.
  • Trace fan-out.
  • Avoid N+1.
  • Cache only intentionally.
  • Protect server-side credentials.
  • Keep response client-focused.
  • Monitor BFF latency and downstream contribution.
  • Move complex aggregates to projections.

FAQ

BFF vs API Gateway?

Gateway owns traffic policy; BFF owns client-specific composition.

One BFF per screen?

No.

Can Next.js be a BFF?

Yes, especially for web-specific server composition.

- [Microservices Design Patterns I Have Used in Real Enterprise Projects](/articles/microservices-design-patterns-real-enterprise-projects) - [API Gateway Pattern](/articles/api-gateway-pattern-kong-aws-azure-spring-nestjs)
  • API Composition

  • Frontend Architecture

    Architect's final take

    A BFF is valuable when it protects the client from backend topology without stealing business ownership from domain services.

Was this article useful?

Your feedback helps prioritize deeper technical content.

Romharshan Singh
ABOUT THE AUTHOR

Romharshan Singh

Senior Solution Architect and Full Stack Technology Leader with 20+ years of enterprise engineering experience across AI, cloud, distributed systems, Java, Node.js, React, Angular, Kafka and Kubernetes.