Concepts of API Gateway
By: Ajay Yadav
Tags: Software Development, Api Gateway, Microservices, Software Architecture

API Gateway

API gateway is a service that provides an entry point to the application from the outside world (outside of the firewall). Similar to the Facade pattern in OOPS.

API Gateway responsibilities

Routing

API composition

Authentication

Monitoring

Rate limiting

Protocol Translation

Request logging

Response caching

Service APIs Clients

Types of the client communicate with service APIs

Web application with the webserver. E.g. NodeJS based applications.

Browser-based clients

Mobile-based clients

Third-party clients

Issues without API gateway

Without an API gateway, clients will communicate directly with the services.

Complex composition logic at the client end and multiple API calls impact the performance.

Clients are tightly coupled with services and updating clients is cumbersome.

Services are forced to use communication protocols that the client supports.

Edge Function

The edge function is a request processing function implemented at the edge of the application.

Following are the common edge functions:

Authentication

Authorization

Rate limiting

Caching

Metrics Collection

Request logging

Following are the options to implement the Edge functions

At each backend service [ Impact: Need to implement edge function in each service]

[ Impact: Need to implement edge function in each service] At edge service which is upstream to the API gateway [ Advantage: It separates the concerns and API gateway is dedicated to routing and composition only. Impact: Increase latency due to extra network hop]

[ Advantage: It separates the concerns and API gateway is dedicated to routing and composition only. Impact: Increase latency due to extra network hop] At API gateway

Benefits and Drawbacks of API Gateway

BENEFIT

It encapsulates the internal structure of the application.

DRAWBACKS

It is another highly available component that demands development, deployment, testing, and management.

API gateway design issues

Following issues should be considered while developing an API gateway

Performance & scalability ( Sync I/O vs Async I/O model)

Writing maintainable code by using reactive programming

Handling partial failure ( Running multiple instances, timeout, circuit breaker, and fallback mechanisms)

Implementing API Gateway

There are a couple of different ways to implement API gateway

Off-the-shelf API gateway product/service

Developing your own API gateway

Off-the-shelf API Gateways

AWS API Gateway

AWS Application load balancer

API gateway product such as Kong or Traefik

Developing own API Gateway

API gateway is a simple application that proxies request to other services. Albeit following design problems need to be considered

Implementing a mechanism to define routing rules in order to minimize the complex coding.

Correctly implement the HTTP proxying behavior

Following are the frameworks for writing the API gateway which significantly reduce the amount of code you need to write.

Netflix Zuul

Spring Cloud Gateway ( built on several frameworks: Spring framework 5, Spring boot 2, Spring Webflux)

GraphQL

Different clients might need slightly different data. One way to solve this is to provide the capability to the client to specify data they need using parameters though a better approach is to use Graph QL