advanced
BFF pattern
Use a backend-for-frontend to shape APIs around client workflows while controlling duplication, caching, auth, and ownership boundaries.
Backend-for-Frontend (BFF) tailors APIs to specific client workflows—mobile, web, partner—aggregating downstream services, shaping payloads, and handling client-specific auth or caching. It reduces over-fetching and chatty clients but risks duplication if every screen gets its own BFF endpoint without governance.
On interviews: justify BFF versus generic API gateway or GraphQL. Explain ownership—frontend team, platform team, or shared—and caching boundaries.
Common pitfalls: BFF becoming a second monolith; business rules duplicated from core services; no contract tests between BFF and clients.
The trade-off is flexibility versus complexity—know when the simpler path is enough.
Checklist:
- BFF optimized for one client experience.
- Domain rules stay in core services.
- Aggregation with timeouts and partial failure strategy.
- Versioned contracts tested with consumer fixtures.