Filipe Crespo flag Denunciar. However, you can end up with an undifferentiated product that is considered an inferior offering in the market of APIs. Your product your API needs to be credible, relevant, and differentiated. This pattern gives you a buffer or virtual layer between the interface on top and the API implementation on the bottom. Making a clean design in the facade allows you to decompose one really hard problem into a few simpler problems.

Author:Yozshuzuru Tasar
Country:Antigua & Barbuda
Language:English (Spanish)
Published (Last):6 May 2018
PDF File Size:14.58 Mb
ePub File Size:16.86 Mb
Price:Free* [*Free Regsitration Required]

In a microservices architecture, each microservice exposes a set of typically fine-grained endpoints. This fact can impact the client-to-microservice communication, as explained in this section.

A possible approach is to use a direct client-to-microservice communication architecture. In this approach, a client app can make requests directly to some of the microservices, as shown in Figure In this approach, each microservice has a public endpoint, sometimes with a different TCP port for each microservice.

In a production environment based on a cluster, that URL would map to the load balancer used in the cluster, which in turn distributes the requests across the microservices. This acts as a transparent tier that not only performs load balancing, but secures your services by offering SSL termination.

In any case, a load balancer and ADC are transparent from a logical application architecture point of view. A direct client-to-microservice communication architecture could be good enough for a small microservice-based application, especially if the client app is a server-side web application like an ASP.

However, when you build large and complex microservice-based applications for example, when handling dozens of microservice types , and especially when the client apps are remote mobile apps or SPA web applications, that approach faces a few issues. Interacting with multiple microservices to build a single UI screen increases the number of round trips across the Internet. This increases latency and complexity on the UI side.

Ideally, responses should be efficiently aggregated in the server side. This reduces latency, since multiple pieces of data come back in parallel and some UI can show data as soon as it's ready. Implementing security and cross-cutting concerns like security and authorization on every microservice can require significant development effort. A possible approach is to have those services within the Docker host or internal cluster to restrict direct access to them from the outside, and to implement those cross-cutting concerns in a centralized place, like an API Gateway.

Protocols used on the server side like AMQP or binary protocols are usually not supported in client apps. A man-in-the-middle approach can help in this situation. The API of multiple microservices might not be well designed for the needs of different client applications. For instance, the needs of a mobile app might be different than the needs of a web app. For mobile apps, you might need to optimize even further so that data responses can be more efficient.

You might do this by aggregating data from multiple microservices and returning a single set of data, and sometimes eliminating any data in the response that isn't needed by the mobile app. And, of course, you might compress that data. Again, a facade or API in between the mobile app and the microservices can be convenient for this scenario.

In a microservices architecture, the client apps usually need to consume functionality from more than one microservice. If that consumption is performed directly, the client needs to handle multiple calls to microservice endpoints. What happens when the application evolves and new microservices are introduced or existing microservices are updated?

If your application has many microservices, handling so many endpoints from the client apps can be a nightmare. Since the client app would be coupled to those internal endpoints, evolving the microservices in the future can cause high impact for the client apps. Therefore, having an intermediate level or tier of indirection Gateway can be very convenient for microservice-based applications.

If you don't have API Gateways, the client apps must send requests directly to the microservices and that raises problems, such as the following issues:. Coupling : Without the API Gateway pattern, the client apps are coupled to the internal microservices. The client apps need to know how the multiple areas of the application are decomposed in microservices. When evolving and refactoring the internal microservices, those actions impact maintenance because they cause breaking changes to the client apps due to the direct reference to the internal microservices from the client apps.

Client apps need to be updated frequently, making the solution harder to evolve. That can result in multiple network round trips between the client and the server, adding significant latency. Aggregation handled in an intermediate level could improve the performance and user experience for the client app.

Security issues : Without a gateway, all the microservices must be exposed to the "external world", making the attack surface larger than if you hide internal microservices that aren't directly used by the client apps. The smaller the attack surface is, the more secure your application can be. Cross-cutting concerns : Each publicly published microservice must handle concerns such as authorization and SSL. In many situations, those concerns could be handled in a single tier so the internal microservices are simplified.

When you design and build large or complex microservice-based applications with multiple client apps, a good approach to consider can be an API Gateway. This is a service that provides a single-entry point for certain groups of microservices.

It's similar to the Facade pattern from object-oriented design, but in this case, it's part of a distributed system. The API Gateway pattern is also sometimes known as the "backend for frontend" BFF because you build it while thinking about the needs of the client app.

Therefore, the API gateway sits between the client apps and the microservices. It acts as a reverse proxy, routing requests from clients to services. It can also provide additional cross-cutting features such as authentication, SSL termination, and cache. Figure shows how a custom API Gateway can fit into a simplified microservice-based architecture with just a few microservices. Apps connect to a single endpoint, the API Gateway, that's configured to forward requests to individual microservices.

It's important to highlight that in that diagram, you would be using a single custom API Gateway service facing multiple and different client apps. That fact can be an important risk because your API Gateway service will be growing and evolving based on many different requirements from the client apps.

Eventually, it will be bloated because of those different needs and effectively it could be similar to a monolithic application or monolithic service. That's why it's very much recommended to split the API Gateway in multiple services or multiple smaller API Gateways, one per client app form-factor type, for instance. You need to be careful when implementing the API Gateway pattern.

Usually it isn't a good idea to have a single API Gateway aggregating all the internal microservices of your application. If it does, it acts as a monolithic aggregator or orchestrator and violates microservice autonomy by coupling all the microservices.

Therefore, the API Gateways should be segregated based on business boundaries and the client apps and not act as a single aggregator for all the internal microservices. When splitting the API Gateway tier into multiple API Gateways, if your application has multiple client apps, that can be a primary pivot when identifying the multiple API Gateways types, so that you can have a different facade for the needs of each client app.

This case is a pattern named "Backend for Frontend" BFF where each API Gateway can provide a different API tailored for each client app type, possibly even based on the client form factor by implementing specific adapter code which underneath calls multiple internal microservices, as shown in the following image:. Figure The example depicts a simplified architecture with multiple fine-grained API Gateways.

But in larger applications you should also go further and create additional API Gateways based on business boundaries as a second design pivot. An API Gateway can offer multiple features. Depending on the product it might offer richer or simpler features, however, the most important and foundational features for any API Gateway are the following design patterns:. Reverse proxy or gateway routing. The API Gateway offers a reverse proxy to redirect or route requests layer 7 routing, usually HTTP requests to the endpoints of the internal microservices.

The gateway provides a single endpoint or URL for the client apps and then internally maps the requests to a group of internal microservices. This routing feature helps to decouple the client apps from the microservices but it's also convenient when modernizing a monolithic API by sitting the API Gateway in between the monolithic API and the client apps, then you can add new APIs as new microservices while still using the legacy monolithic API until it's split into many microservices in the future.

For more information, see Gateway routing pattern. Requests aggregation. As part of the gateway pattern you can aggregate multiple client requests usually HTTP requests targeting multiple internal microservices into a single client request.

With this approach, the client app sends a single request to the API Gateway that dispatches several requests to the internal microservices and then aggregates the results and sends everything back to the client app. The main benefit and goal of this design pattern is to reduce chattiness between the client apps and the backend API, which is especially important for remote apps out of the datacenter where the microservices live, like mobile apps or requests coming from SPA apps that come from JavaScript in client remote browsers.

For regular web apps performing the requests in the server environment like an ASP. NET Core MVC web app , this pattern is not so important as the latency is very much smaller than for remote client apps. Depending on the API Gateway product you use, it might be able to perform this aggregation. However, in many cases it's more flexible to create aggregation microservices under the scope of the API Gateway, so you define the aggregation in code that is, C code :.

For more information, see Gateway aggregation pattern. Cross-cutting concerns or gateway offloading. Depending on the features offered by each API Gateway product, you can offload functionality from individual microservices to the gateway, which simplifies the implementation of each microservice by consolidating cross-cutting concerns into one tier.

This is especially convenient for specialized features that can be complex to implement properly in every internal microservice, such as the following functionality:.

For more information, see Gateway offloading pattern. There can be many more cross-cutting concerns offered by the API Gateways products depending on each implementation. We'll explore here:. In this case, when using a product like Azure API Management, the fact that you might have a single API Gateway is not so risky because these kinds of API Gateways are "thinner", meaning that you don't implement custom C code that could evolve towards a monolithic component.

The API Gateway products usually act like a reverse proxy for ingress communication, where you can also filter the APIs from the internal microservices plus apply authorization to the published APIs in this single tier.

The insights available from an API Management system help you get an understanding of how your APIs are being used and how they are performing.

They do this by letting you view near real-time analytics reports and identifying trends that might impact your business. Plus, you can have logs about request and response activity for further online and offline analysis.

These features let you enforce flexible and fine-grained quotas and rate limits, modify the shape and behavior of your APIs using policies, and improve performance with response caching. In this guide and the reference sample application eShopOnContainers , the architecture is limited to a simpler and custom-made containerized architecture in order to focus on plain containers without using PaaS products like Azure API Management. Ocelot is a lightweight API Gateway, recommended for simpler approaches.

Ocelot is an Open Source. It's lightweight, fast, and scalable and provides routing and authentication among many other features. The main reason to choose Ocelot for the eShopOnContainers reference application is because Ocelot is a.

And since it's based on. The previous diagrams showing custom API Gateways running in containers are precisely how you can also run Ocelot in a container and microservice-based application. After the initial architecture and patterns explanation sections, the next sections explain how to implement API Gateways with Ocelot.


The API gateway pattern versus the Direct client-to-microservice communication

As a result, any application web, mobile, desktop, whatever can connect to a REST API as long as both the client and the server are connected to the internet. This way, REST decouples the application architecture, allowing each endpoint function or module to evolve independently. This reduces the application complexity, and the maintenance overhead. This simplifies the APIs significantly, leaving the responsibility of keeping the application state to the API clients. This means that the queries to the API do not need to contain any information about the state or previous queries, which makes RESTful messages self-descriptive. A server response will contain all the information a client will need to decode and process it, including the MIME type and, in some cases, meta-links the client can follow to get related information. This greatly simplifies the server logic, allowing each client to decide how to react to a particular situation or state.


Pattern: API Gateway / Backends for Frontends

APIs are driving force behind many applications big and small. Whether your publishing a public API or building a new integrations marketplace, APIs are becoming the way business is done. They are a type of proxy server that sits in front of your API and performs functionality such as authentication, rate limiting, routing publicly accessible endpoints to the appropriate microservice, load balancing across multiple internal services, among other things. Historically, the need for API gateways rose from integration challenges. API Gateways can provide a unified interface and link multiple legacy applications together. These type of transformations are usually not automatic.

Related Articles