An introduction to the API Gateway Pattern for the Microservice application architecture

Tram Ho


Imagine you are building a sales website, using microservice architecture and you need to implement the details page for the product. You need to develop multiple interface versions:

  • UI for desktop, mobile browser
  • Native mobile app

Furthermore, the website needs to build APIs about the product, used by 3rd parties. The detailed product interface needs to display a lot of information about the product:

  • Basic information like title, origin, price, …
  • Product sales history
  • The remaining amount
  • Payment methods
  • Related products
  • Buyer Reviews
  • ….

So you choose the microservice architecture to break down the components of the product detail page into many small services:

  • Service provides product information
  • Service price handling
  • Order processing service
  • Warehouse handling service
  • The service processes user reviews

So how can your website’s clients access individual services?


The solution to this problem is to implement an API Gateway, creating an entrypoint for all incoming requests. The API Gateway will handle all incoming requests, directing them to the exact service the user wants.

By using API Gateway, your application can provide external APIs for use by third parties. Furthermore, we can guarantee the security of the application by authenticating the user making the incoming request.

The main function of API Gateway

  • Routing: Using an API Gateway is like packing an application into a block, separating the client and the application, every request from the client will go through a single point.
  • Offloading: The API Gateway can take care of functions such as Authentication, authorization, rate limiting, load balancing, logging, tracing, IP Whitelisting, … and removing them from the logic of the application.

Famous API Gateway

Netflix API Gateway: Zuul

Netflix is ​​a streaming service on many different platforms such as televisions, smartphones, gaming devices, tablets, … The number of requests during peak hours that they have to process per second is up to 50,000. Netflix has found limitations in using the OSFA (one-size-fits-all) mechanism, so it has switched to using the APT Gateway to tailor requests to different devices.

Zuul 2 will direct all requests to the cloud of Netflix, it greatly improves the infrastructure and functionality, allows the gateway to process requests, navigate and protect the cloud infrastructure of Netflix, providing a good experience. for more than 125 million users.

Amazon API Gateway

AWS provides management services for creating, maintaining, monitoring, and securing REST APIs, HTTP, Websocket systems, etc. developers can create APIs that interact with AWS, web services or data. Data is stored on the AWS cloud

Kong API Gateway

Kong Gateway is an open source, a small and lightweight API Gateway optimized for applications using the microservice architecture, providing performance, scalability, and no downtime. This API Gateway is suitable for basic applications, it can be scaled horizontally simply by adding nodes. It’s simple, but it handles large workloads and low latency.

Other API Gateway

In addition to the famous API Gateway mentioned above, there are many other API Gateway systems to choose from such as:

Choosing the right API Gateway for your application should be based on criteria such as simplicity to use, whether it is open-source or close-source, scalability, flexibility, security, etc. Other advanced features, … in addition should also consider the management, monitoring, application deployment or the cost of service providers.

Share the news now

Source : Viblo