Micro service: API gateway — Example

Debasis Das
3 min readSep 12, 2023

--

What is micro services :

A microservices architecture is one type of distributed system, since it decomposes an application into separate components or services.

For example, a microservice architecture may have services that correspond to business features (payments, price, inventory etc.) where each corresponding component handles the business logic for that responsibility.

What is API gateway :

API gateways are middleware or software components that sit between client applications and back-end services. API gateways provide a more straightforward, secure, and reliable API interface for complex subsystems by working as a proxy between the API system and its consumers.

The primary function of an API gateway is to route and transmit client requests to the appropriate back-end services.

They also provide other capabilities, such as security, rate limit, caching, request/response transformation, monetization, and load balancing.

Why need API gateway :

  1. Security — When you need to make sure your APIs are protecting the sensitive data in a reliable manner
  2. Scalability — When you need to power up your API’s performance by implementing performance features, such as, traffic management, caching data, etc.
  3. Interoperability — When you are spending too much time with the mediation and data transformation needs for incoming and outgoing requests to support different data formats and requirements
  4. Monitoring and logging — When you need a central cockpit for aggregated logging, auditing, and monitoring your APIs to maintain them all
  5. Monetization — When you need an easy way to package, price, promote, and monitor your APIs throughout their lifecycle

API gateway vs API proxy :

Like an API gateway, an API proxy acts as an interface between API consumers and back-end services. An API proxy exposes URL endpoints for existing APIs so users can access them via these proxy endpoints. Requests coming through these proxy URLs are routed to the configured API endpoint, which processes the requests and sends them to the proxy, then returning them to the caller.

However, API proxies are limited in their capabilities in comparison to API gateways. API gateways provide much richer functionality and customization than API proxies, such as rate limiting, API monitoring, caching, end-to-end security, load balancing, authentication, authorization — among others.

API Gateway — Kong :

Kong Gateway is a lightweight, fast, and flexible API gateway. An API gateway is a reverse proxy that lets you manage, configure, and route requests to your APIs.

Kong Gateway runs in front of any RESTful API and can be extended through modules and plugins.

3 Steps to Getting Started — Service, Route, Plugins

  1. Add a service : This is the ID that kong gateway uses to refer to the upstream APIs and microservice it manages.
  2. Add route to the service : Routes specify how (and if) requests are sent to their Services after they reach the API gateway. A single Service can have many Routes
  3. Add plugins: which provide a modular system for modifying and controlling Kong’s capabilities. Plugins provide a wide array of functionality, including access control, caching, rate limiting, logging and more

Summary : That’s it! In this post, we understand about micro service API gateway and handling microservices requests and basic about kong.

Thank you for reading my blogs ……..

--

--

Debasis Das

Senior software developer | Typescript | Node.js | Micro-service | Large scale distributed system | LLD | HLD | Reactjs