# BFF (Backend For Frontend)

# What I know:

  • When frontend requires to reformat some data in order for UI to display
  • After BFF built, which allows developer to make batch calls instead of making multiple API requests, which is better performance considerations [Aggregate API calls]
  • We are able to have multiple BFFs, such as browser BFF, mobile BFF and etc
  • BFF is like a bridge, which calls backend APIs and format the data like frontend required and send those format data to frontend to use [data abstraction]

# Why we need BFF?

  1. Easier to maintain and modify APIs
  2. Easier to separate the ownership of services (less conflicts/overlaps)
  3. Better error handling for frontend, more user friendly
  4. Better Security, like token can be hidden (not exposed to browser), also some sensitive data would be able to be omitted if not needed

# When to use BFF?

When backend is using micro-services architecture. BFF is not very good idea for monolith architecture

# Example demo

BFF E-commerce App Demo

# Another small trick:

  • When we use token based authentication? When the frontend domain and backend domain are different
  • When we use session based authentication? When the frontend domain and backend domain are same

Reference One

Reference Two