Using GraphQL as BFF Pattern Implementation

Using GraphQL as BFF Pattern Implementation

Introduction

We are in the age of RESTful APIs, I could say these kind of API architectural style are on plateau of productivity. A lot of platforms supports the REST style, also the community and the most developers are familiarized with the concepts and tools.

So, why some part of community are moving on to other architectural style or patterns ? In my opinion, all architectural styles has some drawbacks, there is no free lunch! I believe REST architectural style are organized around business model in order to provide strong reuse. It's seems to be wonderful, but someone needs to pay the lunch!?!

As we can guess, the frond-end layer is even more dynamic and agile in terms of business requirements, the back-end layer where APIs lives are more bureaucratic and process oriented. So who need to be more adaptable ? The front-end off course!

In technical terms, the front-end need to understands the APIs and usually make too many requests and hide or transform fields to delivery an good performance (off course I mean a better user experience). Front-end developers suffers with these scenario, so it is normal to reach for others alternatives. Here is where GraphQL really fits well!

Backend For Front End (BFF) Pattern

And how about BFF ? In order to fix the problem related before the BFF (Backend For Front End) pattern already exists and could be used to fix this situation. In most of cases, the REST architectural style was used extensively. However, it makes sense, if my Enterprise (General-Purpose) APIs are REST, why not my Front End APIs can not be ?

One important thing to consider is the Front End APIs must support other protocols rather than only HTTP. Other asynchronous protocols such as WebSocket or messaging protocols are heavily used in web and mobile applications and GraphQL can be used with those protocols.

But let's back to the definition of BFF pattern, according with Sam Newman and Phil Cal?ado [1], The BFF is tightly coupled to a specific user experience, and will typically be maintained by the same team as the user interface, thereby making it easier to define and adapt the API as the UI requires, while also simplifying process of lining up release of both the client and server components.

Let's see now a graphical representation of this pattern:

As we can see on the picture above, we have iOS API and Android API using the pattern BFF. The Inventory, Wishlist and Catalog are Enterprise (General Purpose) APIs . Note that each front end application has your own APIs to delivery better experience.

GraphQL

GraphQL’s [2] power comes from a simple idea — instead of defining the structure of responses on the server, the flexibility is given to the client. Each request specifies what fields and relationships it wants to get back, and GraphQL will construct a response tailored for this particular request. The benefit: only one round-trip is needed to fetch all the complex data that might otherwise span multiple REST endpoints, and at the same time only return the data that are actually needed and nothing more.

Let's see the representation below:

How we can see, the front end as API client needs to handle the complexity of make several API calls and select which fields to show to the user.

The Proposed Solution

Our proposed solution here is join the existing BFF pattern using GraphQL as main API technology. Let's see how should be a high level architectural big picture:

As we can see on the picture above, the front-end applications consumes the Front-End APIs using GraphQL technology. In order to implement the translation from REST to GraphQL, a GraphQL Engine is used here as key component.

All Enterprise APIs are available in REST architectural style and can be reused to others client applications.

But the main component in this big picture is the API Platform which can be used here to:

  • Manage and Expose the Enterprise APIs (REST)
  • Manage and Expose the Front-End APIs (GraphQL)
  • Implement and Run GraphQL Engine

Conclusion

Our proposed solution here is using GraphQL as Front-End APIs, but why ?

  1. Works on multiple communications protocols such as WebSocket!
  2. Hides complexity to handle RESTful Enterprise APIs

And how about BFF Pattern, why to use ?

  1. Create Experience APIs for each communication channel.
  2. The development team works on front-end and also back-end. The complexity to handle Enterprise APIs can be applied on backend layer and it can also be reused.

But drawbacks always exists! So, what would you consider:

  • GraphQL has issues to handle such as not having built-in cache mechanism. In RESTful APIs, the HTTP protocol handles it natively.
  • When using BFF your codebase might increase exponentially, once you may create custom behavior for each device.

Finally, if you want to use this kind of architecture, we strong recommend to use an API Platform [3] which can help you to handle both GraphQL and REST architectural style.

References and Further Reading

[1] Backend For Front-End Pattern Definition - https://samnewman.io/patterns/architectural/bff/

[2] GraphQL in the Age of REST APIs - https://medium.com/chute-engineering/graphql-in-the-age-of-rest-apis-b10f2bf09bba

[3] Sensedia API Platform - https://sensedia.com/en/api-platform/


Yohan Guisao Baena

Digital Utilities Transformation | Industry 4.0 Solutions | Digital Architecture | Enterprise Architecture | Software Architecture |

1 年

Great article! It makes so much sense for me. Tks for sharing.

回复
Bob James

Associate Director - Digital Experience Projects

1 年

Nice and concise review of these two patterns.

回复
Amlendu Kumar

Architect ? Digital Transformation ? Microservices ? SOA ? Methodologist ? Practitioner

6 年

great insight, good one

Nishant Jain

Independent Tech Consultant | Focused on Software Engineering and DevOps

7 年

Do you implement a GraphQL BFF for every specific kind of client?

要查看或添加评论,请登录

Rafael Rocha的更多文章

  • Tech Leadership, the shift!

    Tech Leadership, the shift!

    I have always been… no! I am a tech guy! I started with this sentence because I used to think that to be a leader, I…

  • AI Agent Integration Architecture: The role of API Gateway and iPaaS

    AI Agent Integration Architecture: The role of API Gateway and iPaaS

    Introduction Modern AI-driven ecosystems require seamless integration between AI agents, client applications, and…

  • How iPaaS can manage API Compositions and API Orchestrations

    How iPaaS can manage API Compositions and API Orchestrations

    In the realm of modern integration architecture, API Composition and API Orchestration are two powerful patterns for…

    3 条评论
  • Desafios e Estratégias para a Moderniza??o de Arquiteturas de TI

    Desafios e Estratégias para a Moderniza??o de Arquiteturas de TI

    A moderniza??o das arquiteturas de TI é uma necessidade inevitável para muitas empresas que buscam se manter…

    3 条评论
  • Exploring the Continued Relevance of GraphQL APIs in 2024: Insights from the Community

    Exploring the Continued Relevance of GraphQL APIs in 2024: Insights from the Community

    In the fast-paced world of technology, staying abreast of the latest trends and advancements is crucial for…

  • Resumo sobre Encontro Anual DREX 2023

    Resumo sobre Encontro Anual DREX 2023

    Palestra: O "Futuro Digital do SFN" A palestra foi proferida pelo Presidente do Banco Central do Brasil, Roberto Campos…

    2 条评论
  • 6 APIs Trends for 2020

    6 APIs Trends for 2020

    2020 is ongoing… and now it’s time to reflect and think about trends and be prepared for innovation and trends about…

    12 条评论
  • The 5 Principles of Integration Modernization

    The 5 Principles of Integration Modernization

    Current Context The rise of digital transformation has led corporations to rethink how they do about everything in the…

    17 条评论
  • Top 7 API Trends 2019

    Top 7 API Trends 2019

    In this article we present the main API Trends for 2019, it all based on our expertise and marketing researches. All…

    1 条评论
  • API Architecture Maturity Model

    API Architecture Maturity Model

    Is your company ready for API Economy in 2019 ? This is the reflection for new years resolutions which architects and…

    47 条评论

社区洞察

其他会员也浏览了