BFF (Backend For Frontend) concept page: per-client backend layer (web BFF, mobile BFF, GraphQL gateway alternative, partner public API) sitting between clients and domain microservices. Three scenarios: web BFF aggregates 5 microservice calls into single typed response with edge cache; mobile BFF returns lighter payload (3KB vs 12KB); GraphQL gateway alternative with DataLoader. Plus anti-patterns scenario for timeouts/circuit breakers. Includes ADR comparing BFF per-client vs single GraphQL gateway vs API Gateway.
BFF — backend component aligned with one frontend experience. Он может агрегировать вызовы, адаптировать payload и в browser architecture держать OAuth tokens вне JavaScript, но остаётся дополнительным deployable hop с собственными SLO и attack surface.
BFF не должен становиться общим доменным монолитом: бизнес-инварианты и object-level authorization остаются у authoritative services. Разделение имеет смысл, когда web и mobile действительно имеют разные change cadence, payload или security needs.
| Компонент | Роль в модели |
|---|---|
| Web Browser | secure session request |
| Mobile Client | mobile API request |
| Web BFF and Session | secure session request; confidential OAuth client; authorized read; authorized read; fan-out spans |
| Mobile BFF | mobile API request; compact read; mobile command; fan-out spans |
| Authorization Server | confidential OAuth client |
| Catalog Service | authorized read; compact read |
| Orders Service | authorized read; mobile command |
| Deadline and Fan-out Telemetry | fan-out spans; fan-out spans |
The web BFF authenticates the session and starts independent catalog and order reads in parallel with child deadlines shorter than the client deadline.
Проверяемый исход: The response contract identifies complete, partial and unavailable sections; optional failure never masquerades as an empty business result.
The mobile BFF asks for only fields and page size needed by the mobile experience, without changing domain rules in downstream services.
Проверяемый исход: The payload and release cadence are client-specific while order authorization and invariants remain authoritative downstream.
The web BFF acts as the confidential OAuth client. It completes the authorization code flow, stores tokens server-side and binds them to a Secure, HttpOnly cookie session.
Проверяемый исход: Browser JavaScript receives neither access nor refresh token; cookie requests still pass CSRF and session-binding controls.
Orders exceeds its child deadline while catalog succeeds. The BFF cancels remaining work, follows the documented degraded contract and preserves enough telemetry to diagnose the dependency.
Проверяемый исход: The client sees explicit partial availability, retry policy does not amplify the timeout, and the BFF thread/connection pool remains bounded.
downstream_rps_i = frontend_rps × mean_calls_i_per_request; total backend work is the sum across dependencies even when calls run in parallel.response_latency ≈ ingress + max(parallel_dependency_paths) + composition + egress; sequential prerequisites remain additive.Π p_i; correlation makes that product optimistic and must be measured.attempt_rps = logical_rps × mean_attempts_per_call, bounded by retry budget and concurrency limits.Числа и bounds выше действуют только при названных units, population и assumptions. Ни паттерн, ни browser API сами по себе не задают SLA, capacity или correctness.
Диаграмма показывает full browser BFF и отдельный mobile BFF. Она не утверждает, что GraphQL всегда устраняет BFF, что cookie session автоматически безопасна или что каждый экран требует отдельного сервиса.
Введите числа или выберите пресет