Search code examples
architecturemicroservicesgatewayspring-cloud-gateway

Microservices BFF pattern


We are working on application having micro-service based architecture with following components as shown in below image and not sure how BFF layer should be structured. We are currently considering two options for our design however not sure which should be recommended approach.

Option 1 : Gateway as BFF

Option 2 : Dedicated Microservice as BFF

enter image description here


Solution

  • The Gateway and BFF (Backend For Frontend) are not quite the same thing:

    • Gateway / API Gateway is part of the platform infrastructure. It exposes API endpoints to clients and mediates the traffic, i.e. authentication, rate limiting and so on.
    • BFF (specifically the API & supporting API's and/or services) is part of the software which you write. The API portion will sit on a gateway (as per your option 1).

    What the API actually calls is up to you. The goals of BFF basically imply that something needs to pull together the data that the client needs, in a way that is convenient for the client - i.e. orchestration, maybe even some caching.

    Options:

    1. For simplistic scenarios you might be able to do that on the gateway itself using an API end-point on the gateway coupled with whatever capabilities the gateway has.
    2. For other cases you'll probably need to implement something a bit more substantial - such as a dedicated service that handles the orchestration which.

    Keep in mind that "API" is a loaded term, which depends on the context:

    • Sometimes it means just an end-point on a gateway (option 1).
    • Sometimes it means an end-point on a gateway plus whatever service implements the logic the "API" delivers (option 2).

    In your cases I'm sayin the BFF could be implemented either way.

    You might also be interested in "Experience API" which is a similar idea (if not the same) as BFF.