API gateway deployment patterns
Tags: devops, api, microservices, webdev
Published: 2022-12-19 08:46:30

[API](https://en.wikipedia.org/wiki/API)s are changing the way we build applications and changing the way we expose data, both inside and outside our organizations. Also, the success of our APIs depends on their integrity, availability, and performance. With an **API Gateway** such as [Apache APISIX](https://apisix.apache.org/), we can achieve these indicators of success.  

When it comes to the deployment of API Gateways, there are **4 well-known patterns:** _Centralized edge gateway, Two-tier gateway, Microgateway, and Sidecar_. In this post, we will go through these patterns and give you an idea to choose the right API gateway deployment pattern for your business. 

## What is an API gateway?

An [API gateway](https://apisix.apache.org/docs/apisix/terminology/api-gateway/) is a management tool that sits at the edge of a system between a consumer and a collection of backend services and acts as a single point of entry for a defined group of APIs. The consumer can be an end-user application or device, such as a single-page web application or a mobile app, another internal system, or a third-party application or system.

## API gateway deployment components

An API gateway is implemented with two high-level fundamental components: _a control plane and a data plane_. These components can typically be packaged together or deployed separately. The control plane is where operators interact with the gateway and define routes, policies, and required telemetry. The data plane is the location where all of the work specified in the control plane occurs, the network packets are routed, the policies enforced, and telemetry emitted.
For example, APISIX has three different [deployment modes](https://apisix.apache.org/docs/apisix/deployment-modes/) (traditional, decoupled and standalone) for different production use cases. 

## Centralized edge gateway

An API gateway is typically deployed at the edge of a system, but the definition of “system” in this case can be quite flexible. For startups and many small-medium businesses, an API gateway will often be deployed at the edge of the data center or the cloud. In these situations, there may only be a single API gateway (deployed and running via multiple instances for high availability) that acts as the front door for the entire backend estate, and the API gateway will provide all of the edge functionality.

![Centralized edge API gateway](https://static.apiseven.com/2022/12/17/639dd6e84af19.png)

An API gateway provides **cross-cutting requirements** such as _user authentication, authorization, request rate limiting, caching, timeouts/retries, request/response transformation, can provide metrics, logs, and trace data_ in order to support the implementation of observability within the system.

Also, many API gateways provide additional features that enable developers to manage the lifecycle of an API, assist with the onboarding and management of developers using the APIs (such as providing a developer portal and related account administration and access control), and provide enterprise governance.

## Two-tier gateway

For large organizations and enterprises, an API gateway will typically be deployed in multiple locations, often as part of the initial edge stack at the perimeter of a data center, and additional gateways may be deployed as part of each product, line of business, or organizational department. In this context, these gateways would more typically be separate implementations and may offer different functionality depending on geographical location (required governance) or infrastructure capabilities (running on low-powered edge compute resources).

As the below diagram shows how Apache APISIX API gateway often sits between the public internet and the [demilitarized zone](https://en.wikipedia.org/wiki/DMZ_(computing)) (DMZ) of a private network.

![Two-tier API gateway](https://static.apiseven.com/2022/12/17/639dd6e77d1d8.png)

## Microgateway

[Microgateway](https://nordicapis.com/the-differences-between-gateway-microgateway-and-service-mesh/#:~:text=In%20essence%2C%20a%20Microgateway%20is,up%20and%20provide%20communication%20connections.)s are designed entirely for internal communication between microservices. Each individual microgateway may have a different set of policies, and security rules, and require aggregation of monitoring and metrics from multiple services.

![Microgateway](https://static.apiseven.com/2022/12/17/639dd6e768f0c.png)

The concept is to provide the capability (a dedicated gateway) to the individual team managing the microservices to control how they are going to securely expose the services. The same developer team will manage and maintain their microservices and microgateways, so they can fix bugs, provide updates, perform improvements independently, and quickly push the changes to the production with less interaction with other dependencies and without impacting other applications in the deployment.

## Sidecar API gateway

[Sidecar](https://learn.microsoft.com/en-us/azure/architecture/patterns/sidecar) implements an API gateway as a container attached to a service in an independent runtime, such as [Kubernetes](https://kubernetes.io/). Sidecar is a pattern that corresponds to a [sidecar](https://en.wikipedia.org/wiki/Sidecar) attached to a motorcycle, similarly, it is attached to a parent application (a software component called service mesh) and provides supporting features for the application.  The sidecar also shares the same lifecycle as the parent application, is created and retired alongside the parent, and introduces additional features such as monitoring, logging, configuration, and networking services. 

The benefits of adopting this pattern are that each service runtime can configure its own API gateway in the best way. Because the requirement to enable the API gateway functionalities and setups can vary from service to service. At the same time, it separates concerns if an issue occurs in the shared API gateway infrastructure then all services are not impacted. For example, [Amesh](https://github.com/api7/amesh) is another service mesh solution based on [Apache APISIX](https://apisix.apache.org/).

![Sidecar API gateway](https://static.apiseven.com/2022/12/17/639dd6e93ed9b.png)
 
The preceding diagram illustrates an ingress acting as an API load balancer and resource router into each service endpoint. The entry point for the service is not the service endpoint itself but rather a sidecar API gateway. The sidecar can then perform any of the capabilities offered by the API gateway in addition to routing traffic to the service endpoint.

## Conclusion

As we understand, there is no single deployment pattern that is suitable for all conditions. Sometimes you can use one or multiple gateways in your system.  The choice of deployment depends on the complexity and needs of your business. If you need help deciding which deployment pattern would be best for you, you can join our community [Slack channel](https://join.slack.com/t/the-asf/shared_invite/zt-vlfbf7ch-HkbNHiU_uDlcH_RvaHv9gQ) and experts help you make a decision. 

### Related resources

➔ [Apache APISIX deployment models](https://apisix.apache.org/docs/apisix/deployment-modes/).

➔ [What Is an API Gateway, and Why Is It Essential in a Cloud-Native Era?](https://api7.ai/blog/what-is-an-api-gateway).

### Recommended content 💁

➔ Read the blog posts:

- [Why Is Apache APISIX the Best API Gateway?](https://api7.ai/blog/why-is-apache-apisix-the-best-api-gateway)

- [10 most common use cases of an API Gateway](https://apisix.apache.org/blog/2022/10/27/ten-use-cases-api-gateway/).

- [How to choose the right API Gateway](https://iambobur.com/2022/11/22/how-to-choose-the-right-api-gateway/).

### Community⤵️

🙋 [Join the Apache APISIX Community](https://apisix.apache.org/docs/general/join/) 
🐦 [Follow us on Twitter](https://twitter.com/ApacheAPISIX)
📝 [Find us on Slack](https://join.slack.com/t/the-asf/shared_invite/zt-vlfbf7ch-HkbNHiU_uDlcH_RvaHv9gQ)

### About the author

Visit my personal blog: [www.iambobur.com](https://www.iambobur.com/)