This section covers the layer between the user interface and backend services: how the frontend gets its data, who shapes that data, and who owns the code in between. These decisions decide how often frontend teams wait on backend teams, how fast pages load, and how easily non-developers can change content.
Calling services directly
The simplest setup: the frontend calls each backend service's API itself. It works well with a few services. As services multiply, a single screen may need five or six calls, and the frontend ends up stitching data together and coping with every backend change.
API Gateway
A single entry point in front of all backend services. It handles shared concerns like authentication, rate limiting and routing, so the frontend talks to one address instead of many. It's usually owned by a platform or backend team, because the same gateway typically serves every client and needs consistent rules.
Backend-for-Frontend (BFF)
A thin backend built for each user interface. For example, the web application and the mobile application each get their own, tailored to what that screen needs. It gathers data from services and shapes it for that UI, reducing browser-side coordination. A BFF ideally contains no domain rules. Services own rules such as pricing and stock checks, and the BFF only combines and shapes their results. In practice, teams often move some rules into it for speed, and the risk is that the same rule ends up duplicated across each BFF, where the copies drift apart. It's usually owned by the frontend team, so they can change what the UI gets without waiting on backend teams. That team then needs capacity to deploy, secure and monitor a server, and still depends on upstream contracts.
GraphQL
GraphQL is a query language and execution model over a typed API schema: callers select the supported fields they need in a single request. It can reduce unused response data and the number of round trips by combining related queries, but does not guarantee one cheap request or eliminate loading and error handling. It needs a GraphQL server, which may act as a BFF or sit behind a gateway, and careful attention to performance and security.
Headless CMS and Jamstack
Content such as marketing pages, blog posts and product copy lives in a content management system (CMS) that exposes content separately from its presentation. The frontend pulls it in, often at build time, though it can also fetch it at request time. Marketing teams can edit and publish without waiting on developers, within the content models and workflows the CMS supports. New layouts or behavior may still need development, and page speed depends on delivery choices.
The blurring line
These are combinable decisions, not exclusive lanes: a screen might use a BFF behind a gateway, query it with GraphQL and include CMS content. Add a layer to solve an observed UI problem, not merely because the service count increased.
Modern frameworks can run code on both the server and the browser. Frontend developers can write server-side logic, such as fetching data or handling form submissions, in the same codebase as the UI. It speeds teams up but blurs ownership, so teams need to agree on who owns what and where business rules live. Usually the frontend team owns that server code, while business rules stay in backend services. Sharing a codebase doesn't make browser code trusted: service secrets and authoritative checks, such as authorization, prices and payments, stay on the server.
Trade-offs
| Approach | What you gain | What it costs | Best fit |
|---|---|---|---|
| Direct calls to services | Simplest; nothing extra to build or run | Many calls per screen; frontend tied to every backend change | Small applications with a few services |
| API gateway | One entry point; shared security and routing; consistent for all clients | Same response for every client, so it doesn't shape data per screen; another component to run; can become a bottleneck team | Many services and clients that need shared controls |
| BFF | Data shaped for each UI; frontend team moves independently | One more service per UI to build, deploy and monitor; depends on upstream services; risk of duplicated logic | Separate web and mobile applications with different needs |
| GraphQL | Frontend gets exactly what it needs in one request; flexible as screens change | New skills and tooling; caching and performance are harder; needs query limits and authorization rules for security | Data-rich applications with many screens and changing requirements |
| Headless CMS | Non-developers publish content; fast, cacheable pages | Licensing cost; content modeling upfront; preview, workflow and delivery setup | Marketing sites, blogs, content-heavy products |
What this means for delivery
The layer between frontend and backend affects how often teams wait on each other. A suitable BFF or GraphQL interface can reduce some coordination, and a CMS can remove routine supported content edits from the development queue. Those gains come with contracts and operational ownership; agreeing on them early reduces release-blocking ambiguity.
Check your understanding
Quiz
Which approach fits this setup?
A company runs 20 backend services. The web application, the mobile application and a partner integration all call them. Security wants one place to enforce authentication and rate limits for every client. Which approach fits?
Review questions and explanations (text alternative)
-
Which approach fits this setup?
A company runs 20 backend services. The web application, the mobile application and a partner integration all call them. Security wants one place to enforce authentication and rate limits for every client. Which approach fits?
- An API gateway, as a single entry point that applies authentication and rate limits for every client.
- Direct calls, with each client adding its own authentication checks before calling each service.
- A BFF for each client, so each UI team enforces authentication in its own backend.
- GraphQL, so each client requests only the fields it needs in a single request.
Suggested answer: An API gateway, as a single entry point that applies authentication and rate limits for every client.
An API gateway gives every client one entry point where shared controls like authentication and rate limiting are applied consistently. Direct calls spread those checks across every client and service. Separate BFFs shape data for each UI, but each would repeat the same security rules, and the copies can drift apart. GraphQL changes how data is requested, not where shared controls are enforced.
-
How should the BFF report unavailable reviews?
The web team owns a BFF that combines price, stock and reviews for a product screen. Price and stock succeed, but the review service fails. The product requirement is to keep the available information usable without implying that the product has no reviews. Which response contract fits?
- Fail the complete screen response and discard the successful upstream results.
- Return price and stock with an explicit unavailable status for the review section.
- Return an empty review list and let the view display its ordinary 'no reviews' message.
- Keep the response pending until reviews recover, with no partial result for the browser.
Suggested answer: Return price and stock with an explicit unavailable status for the review section.
An unavailable status distinguishes a failed review service from a product with no reviews, allowing successful price and stock results to remain usable. Failing everything or waiting indefinitely blocks usable data; an empty list falsely reports no reviews. The BFF shapes the response, not its presentation.
-
Who should decide the accepted discount?
Web and mobile show discount previews. Their BFFs need different response shapes, but both must apply the same eligibility policy when an order is accepted. Who should own that authoritative decision?
- The browser, because it already computed the amount the customer saw.
- Each BFF independently, so each UI team can change eligibility without coordinating policy.
- The shared price-display component, because both clients should show consistent formatting.
- A shared server-side policy owner; each BFF adapts it for display.
Suggested answer: A shared server-side policy owner; each BFF adapts it for display.
Shared server-side policy keeps accepted discounts consistent across clients. Browser previews are untrusted, and independent BFF policies can drift. A price-display component controls formatting, not authoritative discount decisions.
-
What should the team promise editors adopting a headless CMS?
Marketing wants to publish product descriptions without a code release. They also expect occasional new page layouts and interactive pricing tools. The proposed CMS exposes structured content through an API. Which expectation should the team establish?
- Publishing a content entry can introduce any new layout or pricing interaction without development.
- Separating content from presentation requires developers to release code for every description edit.
- Editors can publish supported content; new layouts or behavior may need model and application changes.
- Choosing a headless CMS guarantees fast delivery regardless of fetching, caching or rendering choices.
Suggested answer: Editors can publish supported content; new layouts or behavior may need model and application changes.
A headless CMS lets editors make supported content changes without a code release. That autonomy is limited by content models and publishing workflows; new layouts or interactive tools may still need frontend development. Editing autonomy does not guarantee fast delivery; rendering, fetching and caching choices still determine performance.
-
What changes when this screen uses a BFF?
A product screen calls five backend services directly from the browser: product details, price, stock, reviews and recommendations. On mobile networks, the screen is slow to fill in. The team switches this web screen to a BFF endpoint that aggregates those five services. What changes?
- The browser makes one request, and the BFF calls the five services from the server.
- The five services are no longer called, because the BFF replaces them with one response.
- The screen no longer needs loading or error states, since one complete response arrives.
- The browser still makes five requests, but each one now goes through the BFF's address.
Suggested answer: The browser makes one request, and the BFF calls the five services from the server.
The BFF calls the five services from the server and returns one response shaped for the screen, so the browser makes one request over the slow mobile network. The screen still needs loading and error states, since any service can fail.