Abílio Azevedo.

BFF - Backend For Frontend

Cover Image for BFF - Backend For Frontend
Abílio Azevedo
Abílio Azevedo

Implementing a Backend for Frontend Pattern

The backend for frontend (BFF) pattern has become popular in recent years as a way to build scalable and maintainable web applications. A BFF provides a tailored API layer that sits between the frontend and backend services.

What is a Backend for Frontend?

A backend for frontend is a layer that sits between the frontend and backend services. It is designed to handle requests from specific frontend frameworks or platforms. The BFF abstracts away the general-purpose backend APIs to provide an API tailored for each frontend client.

Some key benefits of using a BFF include:

  • Customization - The BFF can transform backend responses into a format optimized for each frontend. This avoids cluttering up the frontend code (Over fetching and Over requesting)

  • Security - The BFF acts as a security layer, protecting the backend from unwanted requests. It can implement authentication, authorization and rate limiting.

  • Performance - The BFF can cache requests and undertake request collapsing to optimize performance for the frontend.

  • Separation of concerns - The backend services focus on business logic while the BFF focuses on interfacing with frontends. This separation makes both the backends and frontends easier to understand and maintain.

  • Independent evolution - The backend services and frontend clients can evolve independently without affecting each other by making changes in the BFF layer.

Implementing a BFF

There are several approaches for implementing a BFF:

  • Serverless functions - Functions as a Service like AWS Lambda can handle requests and run custom logic for each frontend.

  • API gateway - An API gateway sits in front of backend services and can transform, secure and optimize requests.

  • Dedicated BFF server - Build a dedicated BFF application, often using Node and Express, to handle frontend requests.

  • Microservices - Each BFF can be deployed as an independent microservice to handle one or more frontends.

The implementation should focus on:

  • Authentication and authorization
  • Customizing responses for the frontend
  • Caching and request collapsing
  • Rate limiting policies
  • Logging, monitoring and analytics

Proper testing is key to ensure the BFF reliably interfaces with both the frontend clients and backend services as they independently change.

Without BFF With BFF
Admin website BFFs

Conclusion

The backend for frontend pattern is useful for modern web and mobile applications with diverse frontends. Implementing a well-designed BFF provides performance, security, and maintainability benefits. However, it does introduce additional complexity that should be carefully managed.

References

https://samnewman.io/patterns/architectural/bff/#

https://www.sensedia.com.br/post/utilizacao-de-graphql-como-implementacao-do-padrao-bffundefined


More posts

Cover Image for Factory Health Monitor

Factory Health Monitor

The application is a tool for evaluating the health of various machines in an automobile manufacturing plant. This plant features a range of machines, each with specific data points that you will use to assess the condition of the production process.

Abílio Azevedo
Abílio Azevedo
Cover Image for Upload to AWS S3 using Django, Boto3 and S3Direct

Upload to AWS S3 using Django, Boto3 and S3Direct

Uploading videos via a React Native mobile app to a bucket on the AWS S3 service using S3 Direct and Boto3 with a pre-signed URL.

Abílio Azevedo
Abílio Azevedo

NewsLetter

I will send the content posted here. No Spam =)

Experienced Software Engineer with degree in Electrical Engineering with over 8 years of hands-on expertise in building robust and scalable mobile, web and backend applications across various projects mainly in the fintech sector. Mobile (React Native), Web (React and Next.JS) and Backend (Node.JS, PHP and DJANGO). My goal is to create products that add value to people. - © 2024, Abílio Azevedo