One backend serving web, iOS and Android ends up bloated — how do you tailor backend responses for each front end without duplicating logic?
Per Wikipedia: “The Backend for Frontend pattern provides a separate backend service per front-end type that aggregates and shapes data for that UI.”
Like a concierge for each hotel wing — web concierge and mobile concierge both call the same kitchens but pack the tray differently.
- Identify front ends needing different shapes
- Create BFF service per front end
- BFF calls downstream microservices
- BFF aggregates and trims payload
- Front end calls only its BFF
- Reduces over-fetching for mobile
- Lets each UI evolve independently
- Adds operational overhead of extra service
- Should not contain business logic
# BFF aggregates
def get_home(user_id):
profile = users_svc.get(user_id)
feed = feed_svc.get(user_id)
return {'profile': profile, 'feed': feed[:10]}- Built from: Client-Server Model — BFF is a specialized server
- Related: Back End — BFF is a back-end kind
- Related: Front End — BFF serves a specific front end
- Builds into: Scalability — avoids chatty mobile calls
- BFF per pixel — creating BFF per screen not per platform
- Leaking domain logic into BFF — becomes monolith