Designing HTTP APIs · mid
Backend for Frontend (BFF)
A Backend for Frontend is a small server owned by the frontend team that sits between one client (web or mobile) and the backend services, combining and shaping their data for that client and keeping secrets and tokens on the server.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe notes
What you must know
- Why: one screen needs data from 4 services; the BFF calls them in parallel close to the data centre and returns one payload shaped for the screen.
- One BFF per client type (web, mobile) when their needs differ; mobile wants smaller payloads and fewer round trips.
- Security: the BFF can hold OAuth tokens server-side and give the browser only an HttpOnly session cookie, so tokens never reach JavaScript (OWASP recommends this pattern).
- It can translate errors, add caching, and hide internal service changes from the app.
- Next.js route handlers or server functions often act as the BFF for a Next app; a separate Node/Express or GraphQL service is common for mobile.
- Costs: another service to run and monitor; risk of business logic leaking into it. Keep it thin: composition and shaping, not core rules.
- API gateway vs BFF: a gateway handles cross-cutting concerns for everyone (routing, auth checks, rate limits); a BFF is client-specific composition.
The red pen
Common traps: mistake → fix
Mistake: A BFF is just a proxy
Fix: it composes and shapes data for one client and can own the session.
Mistake: Put business rules in the BFF because it is easy
Fix: they get duplicated across BFFs; keep rules in the domain services.
Easy to hard
Questions interviewers ask, easy to hard
- What is a BFF and why would a frontend team want one?
- How does a BFF improve security for a SPA?
- BFF vs API gateway?
- Would you put the BFF in Next.js or a separate service? Why?
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.