advanced

BFF pattern

Shape UI-specific server endpoints that aggregate services while preserving ownership and security boundaries.

A Backend-for-Frontend layer shapes APIs for a specific UI: aggregate multiple services, hide internal URLs, enforce session auth, and return view models instead of raw domain entities.

In Next.js, route handlers or server actions often play BFF when the team owns both UI and aggregation logic.

					Browser → Next route handler → internal services A + B → UI-shaped JSON
				

On interviews: explain why one-to-one endpoint duplication is weak and what belongs in the BFF versus core services.

Common pitfalls: business rules duplicated in BFF and services, god handlers that own domain logic, and leaking service errors verbatim.

The trade-off is delivery speed for one client versus maintaining another service tier.

Checklist:

  • Aggregate for UI needs, not vanity wrapping.
  • Keep domain invariants in core services.
  • Stable error shapes for the UI.
  • Auth at the BFF boundary.