Backend for Frontend Pattern

Play
The write-up below meant to be a companion to the video above. Please watch the above video to build a better understanding.

In a traditional monolithic architecture, a single monolith serves all APIs via a web server. This setup follows a standard three-tier architecture, where users engage with the monolith, which manages database queries and delivers responses.

As applications scale to accommodate mobile platforms, they face increased complexity. A single API endpoint providing identical data across various clients can lead to inefficiencies, particularly due to the limited screen space on mobile devices. Sending irrelevant data not only hampers performance but can also result in a suboptimal user experience.

Clients possess distinct requirements that must be addressed appropriately. For instance, a mobile app may not necessitate reviews or FAQs in its initial product detail responses. Therefore, when supporting a range of clients, it is essential to tailor communications, providing only the information each client requires. This strategy enhances both performance and user experience.

The BFF (Backend for Frontend) pattern is designed to customize responses for various clients by filtering information tailored to each client type. This approach allows developers to maintain the integrity of the underlying monolith while providing dedicated BFFs for each client type. These intermediaries manage response formatting, ensuring that each client receives relevant data without altering the core system.

The BFF (Backend for Frontend) architecture offers several advantages, like, the creation of isolated interfaces that simplify client-specific modifications. This architecture promotes faster changes tailored to individual client needs while safeguarding sensitive information. Moreover, it enables the selection of optimal communication protocols, ensuring efficient interactions. Additionally, the BFF layer maintains generic backend processes that are cache-friendly, enhancing overall system performance.

While the Backend for Frontend (BFF) model offers several benefits, it is not without its drawbacks. Key disadvantages include potential network bloat arising from numerous service calls, code duplication that may occur across different BFFs, increased infrastructure complexity, and the likelihood of heightened latency due to the extra network hop involved in processing requests.

BFF, or Backend for Frontend, is ideal for scenarios where interfaces vary greatly between clients, where multiple response formats are necessary, or when legacy systems demand specialized data management. It enhances communication by serving as a filter and transformer, ensuring streamlined interaction between clients and back-end services.


Arpit's Newsletter read by 100,000 engineers

Weekly essays on real-world system design, distributed systems, or a deep dive into some super-clever algorithm.