Concepts of API Gateway

Ajay Yadav
2 min readJan 24, 2022

Book Reference: Microservice in Action

API Gateway

API Gateway is a special service that hides the internal architecture of the application. It ensures a single entry to the application world from outside.

API Gateway responsibilities

Responsibilities of the API gateway are as follow

  • Routing
  • Authorization and Authentication
  • Monitoring
  • Protocol Translation
  • Request logging
  • Response caching
  • API composition
  • Rate limiting

Service APIs Clients

Types of the client communicate with service APIs

  • Webservers
  • Clients: Browser
  • Clients: Mobile Based
  • Third-party clients

Issues without API gateway

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

  • Clients have to handle the complex composition logic and multiple API calls to the server results in the performance impact as well.
  • It’s challenging to update clients as they are tightly coupled with the services.
  • Services are bound to utilize the communication protocols that can be consumed by the clients.

Edge Function

Edge functions are the functions that are implemented at the boundary of the application to process the requests and responses.

Following are the common edge functions:

  • Authentication
  • Authorization
  • Rate limiting
  • Caching
  • Metrics Collection
  • Request logging

Following are the prospects to enforce the Edge functions

  • At each backend service [ Impact: Need to implement edge function in each service]
  • At edge service which is upstream to the API gateway [ Advantage: Separation of concern. Impact: Add latency due to extra network hop]
  • At API gateway

Benefits and Drawbacks of API Gateway

BENEFIT

  • It hides the architecture of the application.

DRAWBACKS

  • Extra management efforts for the lifecycle of the API gateway component e.g. deployment, development, testing and management

API gateway design issues

Common problems for API gateway implementations

  • Impact on Scalability and Performance of the application with sync vs async IO operations
  • Reactive programming
  • Handling of the partial failures (Multiple instances of the API gateway, Timeout of the requests, Circuit breaker, Fault tolerance)

API Gateway Implementation

Numerous ways to implement the API gateway.

At abstract level:

  • Use an existent API gateway product/service
  • Devising your own API gateway

Use an existent API gateway product/service

  • API Gateway (AWS)
  • ALB (AWS)
  • Open Source API Gateway: Kong or Traefik

DIY API Gateway

API gateway is a straightforward service that proxies the request to other services.

Albeit we need to address the following implementation problems

  • Simplified the mechanism for routing rules
  • Accurate proxying behavior for HTTP requests

Standard frameworks for building the API gateway that can greatly decrease the amount of code you need to write.

  • Netflix Zuul
  • Spring Cloud Gateway

--

--