SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
  • Service Discovery
  • API Gateway Pattern
  • Backend for Frontend (BFF)
  • Sidecar Pattern
  • Circuit Breaker
  • Bulkhead
  • Strangler Fig
  • Service Mesh
  • Database per Service
  • Timeouts and Deadlines
  • API Composition
  • Anti-Corruption Layer
  • Ambassador Pattern
  • Idempotent Consumer and Inbox Pattern
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Architecture/Microservices Patterns

Backend for Frontend (BFF)

A separate backend shaped for each kind of client, such as web and mobile.

โฑ 12 min readIntermediateHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Backend for Frontend (BFF) means building a separate backend for each type of client (phone app, website, smart TV), instead of one general API for all of them.

  • Each BFF is made for one frontend, and usually owned by the same team that builds that frontend.
  • It calls the internal services, combines and trims the data, and returns exactly what its screen needs.
  • Phones get small, fast answers. Websites get rich ones. Neither pays for the other's needs.

02Concept: What is it?

Different clients want different things. A phone on a slow network needs small images and short lists. A desktop website can show full specs, big photos and reviews. A TV app needs huge banners and simple navigation, controlled by a remote.

If one general API tries to serve all of them, it either sends too much data (wasting bandwidth on the phone) or forces clients to make many calls and glue the data together. And every time one client needs a change, the shared API becomes a place where the teams argue and wait for each other.

The BFF pattern (introduced by Sam Newman and used by SoundCloud, among others) gives each client its own small backend layer. The phone team owns the Mobile BFF, the web team owns the Web BFF. Each one speaks the language of its own screen and talks to the shared microservices behind it.

One BFF per client
๐Ÿ“ฑPhone app
๐Ÿ’ปWeb site
๐Ÿ“บSmart TV
โ†’โ†“
โ†’โ†“
โ†’โ†“
๐ŸงฉMobile BFFsmall, fast
๐ŸงฉWeb BFFrich pages
๐ŸงฉTV BFFbig banners
โ†’โ†“calls
Shared services
๐Ÿ‘คUsers
๐Ÿ“ฆProducts
๐Ÿ›’Orders
The BFFs are thin. The real business logic stays in the shared services.
๐Ÿง BFF is a type of API gateway, with a different goal
A general API gateway is one door for everyone and focuses on shared rules (auth, limits). A BFF focuses on the needs of one client. Many systems have both: a gateway at the edge, then a BFF per client behind it.

03Real-Life Example

๐ŸตThe Waiter for Each Kind of Guest
A restaurant kitchen makes many dishes. A single waiter for everyone would carry the full menu to each table. Instead the restaurant has one waiter for the kids' table who brings small plates and crayons, one for the business lunch who is fast and quiet, and one for the family banquet who brings big platters. All waiters use the same kitchen. Each one knows its own guests well, and can change the way of serving without asking the other waiters.
Restaurant
Backend for Frontend
The kitchen
Shared microservices with business logic
A waiter for one type of guest
A BFF for one type of client
Small plates for the kidsโ€™ table
Small payloads for mobile
The waiter knows what that guest likes
The BFF knows the screenโ€™s exact data needs
Waiter changes style without asking others
Each team ships its BFF independently
Every waiter writes the same notes
Duplicate code between BFFs (a cost)
One waiter calls in sick
That client is affected, but the others still work
One product page, three answers
๐Ÿ“ฑPhonename, price, small photo
๐Ÿ’ปWebphotos, specs, reviews, recs
๐Ÿ“บTVbig banner, recs

04Why Do We Need It?

๐Ÿ“‰Less wasted data
Each client downloads only the fields it shows. This matters on weak mobile networks and for battery life.
โฑ๏ธFewer calls
The BFF talks to many services on the fast internal network and returns one answer.
๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘Team ownership
The frontend team owns its backend layer and can change it without waiting for others.
๐ŸงผCleaner services
Core services stay free of โ€œif mobile, then...โ€ rules and screen-specific code.
๐ŸงฏSmaller blast radius
A bug or overload in the TV BFF does not take down the phone app.
๐ŸŽฏFits each platform
Match each clientโ€™s needs for auth flow, formats, caching and update speed.
Different screens have different needs. Give each its own thin backend, so none of them pays for what the others need.

05Where Do We Use It?

๐Ÿ“ฑMobile and web together
The most common case: a phone app and a website with different data and speed needs.
๐Ÿ“บMany device types
TV, watch, car, kiosks and partner apps, each with special limits.
๐ŸงฉMicroservices
When one screen needs data from many services, the BFF is the place to combine it.
๐Ÿ‘ฅSeparate frontend teams
Teams that ship on different schedules and want their own backend layer.
๐Ÿ”ŒGraphQL layers
A GraphQL server is often used as a BFF, so each client asks for exactly the fields it needs.
๐Ÿง“Legacy systems
Hide an old, messy backend behind a clean API made for the new frontend.

06Types / Parts / How It Works

How a BFF handles a request

Fan-out, shape and return
๐Ÿ“ฑPhoneGET /home
โ†’โ†“1 call
๐ŸงฉMobile BFFfan out, trim, merge
โ†’โ†“3 calls
๐Ÿ‘คUsers
๐Ÿ“ฆOrders
๐Ÿท๏ธOffers
Client BFF Core services
The BFF does the chatty work next to the services, and sends back one tidy answer.

What a BFF usually does

JobExample
AggregateCall Users, Orders and Offers, and return one /home response
Trim and reshapeDrop unused fields, rename them to match the UI, use smaller images
TranslateTurn internal gRPC or old SOAP into simple JSON for the client
Client-specific auth flowSession cookies for the web, tokens in secure storage for mobile
Client-specific cachingCache for short times for the TV, long for static web assets
Handle partial failureIf Recommendations is down, still return the page without them

Ways to organise BFFs

LayoutHow it worksGood for
One BFF per client typeMobile BFF, Web BFF, TV BFF, each its own deployableClients that differ a lot, with separate teams
One BFF per experienceOne BFF per product area, such as checkout or searchLarge products with many teams
GraphQL as the BFFOne GraphQL schema, clients pick fieldsMany clients with similar data but different field sets
Shared BFF libraryCommon code in a library, thin BFFs on topReducing duplicated logic between BFFs
VisualizerSame product page, three screens, three backend stylesPick a screen, then switch between one general API, many small APIs, and a BFF. Lower the network speed to see how wasted data hurts the phone, then raise the round trip time to see how many calls hurt.
Which screen is asking?
How is the backend built?
Product page data. Green = used and sent, red = sent but not used by this screen, dark = not sent.
Name
1 KB
Price
1 KB
Stock
1 KB
Small photo
8 KB
Large photo
120 KB
not needed here
TV banner
220 KB
not needed here
Full specs
15 KB
not needed here
Reviews
30 KB
not needed here
Recommendations
25 KB
not needed here
A single /product endpoint returns the same JSON to every client.
Calls
1
1 round trip waiting
Data received
421 KB
11 KB is useful
Wasted
410 KB
of 421 KB total
Load time
774 ms
estimate
Backends to run
1
one for all
One general API sends the same big answer to everyone. The phone app only needs 11 KB, but receives 421 KB, so 410 KB (97%) is wasted. It only takes one call, but the transfer is slow on a weak network.

A simplified model. Load time = waiting rounds x round trip + data size / network speed. It ignores server work and caching. Sizes are made-up round numbers to show the idea.

07How to Use It / Steps / Implementation

Adding a BFF

  1. 1
    Find the pain
    Look for clients that download unused data, make many calls per screen, or wait for the shared API team.
  2. 2
    Start with one BFF
    Begin with the client that hurts most, usually mobile. Do not create five BFFs on day one.
  3. 3
    Give it to the frontend team
    The team that builds the screen owns and deploys its BFF. This is the main benefit.
  4. 4
    Keep it thin
    Fetch, combine, trim and translate. Business rules stay in the core services.
  5. 5
    Call services in parallel
    Independent calls should run at the same time, with timeouts, so the slowest one sets the speed.
  6. 6
    Plan for partial failure
    Decide what the screen can show if one service is down. Return what you have, with a clear marker for what is missing.
  7. 7
    Share code carefully
    Put common clients and helpers in a library, not in a shared BFF that everyone must change together.
  8. 8
    Put a gateway in front if needed
    Rate limits, TLS and WAF can stay at an edge gateway, while BFFs focus on shaping data.
๐Ÿ’กOne BFF per team, not per screen
A BFF per page leads to dozens of tiny services. A BFF per client or per team gives the benefit (ownership and shape) with far less to run.
โš ๏ธDo not let rules leak in
If the Mobile BFF contains the discount rules, the Web BFF will soon contain a slightly different copy. Keep rules in one core service.

08Key Terms to Know

TermMeaning in easy words
BFFBackend for Frontend: a backend layer made for one type of client
Frontend / clientThe user-facing app: website, phone app, TV app
AggregationCalling several services and merging the answers into one response
Over-fetchingReceiving more data than the screen uses
Under-fetchingReceiving too little, so the client must make more calls
Chatty clientA client that makes many small calls to build one screen
PayloadThe data sent in a request or response
Fan-outOne incoming request causing several outgoing calls
Experience APIAnother name for an API shaped around a user experience, like a BFF
Partial failureSome of the services fail while others work
GraphQLA query language where the client asks for the exact fields it wants

09Pros, Cons and Trade-offs

โœ… Pros
  • Each client gets exactly the data and calls it needs
  • Frontend teams move fast and own their backend
  • Core services stay clean and general
  • A failure or overload stays inside one client's path
  • Easy to try new features on one platform
โš ๏ธ Cons
  • More services to build, deploy and monitor
  • Code and rules can be duplicated between BFFs
  • Risk of business logic leaking into BFFs
  • Extra network hop between client and core services
  • Needs clear ownership, or BFFs get neglected

Trade-offs

ChoiceWe gainWe lose
One general APIOne thing to run, no duplicationOver-fetching, many calls, and a shared bottleneck between teams
A BFF per clientBest fit and team freedomMore services and some duplicated code
Shared library across BFFsLess duplicationTeams must upgrade together, and coupling grows
GraphQL as a single BFFClients choose their fieldsComplex server, query cost control and caching are harder
BFF owned by frontend teamFast changeFrontend developers must run backend services
BFF owned by a platform teamConsistent practicesSlow requests, the same bottleneck as before

10Common Problems and Mistakes

Common mistakes

  1. Business logic in the BFF. Rules end up copied and slightly different in each client backend.
  2. A BFF per screen. Too many tiny services. Group by client or by team.
  3. A shared BFF for all clients. That is just a general API again, with the same problems.
  4. No owner. Nobody maintains it, and it slowly falls behind.
  5. Serial calls. Calling services one by one when they could run in parallel makes the BFF the slow part.
  6. No timeouts or fallbacks. One slow service makes the whole screen hang.
  7. Creating BFFs too early. With one client and few services, a BFF is just extra work.

Things to watch

โ™ŠDuplication drift
Two BFFs implement the same thing differently. Move shared rules to a core service.
๐ŸงฎToo many BFFs
Cost and on-call load grow with each one. Add another only if the needs really differ.
๐ŸขSlowest service wins
A combined call is as slow as its slowest part. Use timeouts and optional sections.
๐Ÿ”Security
BFFs still need auth checks and must not expose internal data just because it is convenient.

11Real-World Examples

๐ŸŽตSoundCloud
Early public example of the pattern, using it to serve different clients from a service-based backend.
๐ŸŽฌNetflix
Devices vary a lot, so Netflix has used per-device API adapters at the edge, and later used GraphQL-style layers.
๐Ÿ›๏ธLarge retailers
Separate backends for the website, the app and in-store kiosks.
๐Ÿ”ŒGraphQL gateways
Companies often put a GraphQL layer in front of many services, with one schema for all clients.
๐ŸฆBanks
A mobile BFF handles biometric login flows and short sessions, while web banking uses cookies.
๐Ÿš—Connected devices
Cars and watches have tiny data budgets and need very small responses.
๐Ÿ“Note
Companies change their architectures often. Treat these as examples of the idea, and check recent talks if you need current details.
Mini case: gateway plus BFFs
๐ŸŒClients
โ†’โ†“
๐ŸšชAPI gatewayTLS, limits
โ†’โ†“
๐ŸงฉMobile BFF
๐ŸงฉWeb BFF
โ†’โ†“
๐ŸงฑCore services
A common layout: shared edge rules first, then client-specific shaping.

12Related Topics to Read Next

API Gateway Patternโ†’

The shared front door that often sits before the BFFs.

Microservicesโ†’

The services a BFF calls and combines.

REST, GraphQL, gRPCโ†’

GraphQL is a popular way to build a BFF.

Data Formatsโ†’

Smaller payloads and better formats help on weak networks.

Latency vs Throughput vs Bandwidthโ†’

Why fewer calls and smaller answers feel faster.

Circuit Breakerโ†’

Protects a BFF when one of the services it calls keeps failing.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”What: a separate thin backend for each client type (phone, web, TV).
  • โœ”Why: clients need different data and calls. One general API over-fetches or is too chatty.
  • โœ”Does: aggregate, trim, reshape, translate, client-specific auth and caching, fallbacks.
  • โœ”Does not: hold business rules. Those stay in the core services.
  • โœ”Owner: the frontend team that uses it, so changes ship fast.
  • โœ”With a gateway: gateway at the edge for shared rules, then a BFF per client.
  • โœ”Costs: more services, duplicated code, an extra hop. Do not make one per screen.
  • โœ”One line: โ€œOne tailor-made backend per kind of client, so each gets exactly what it needs.โ€
โ† Previous
API Gateway Pattern
Next โ†’
Sidecar Pattern