Introduction to API Gateway

Author: neptune | 14th-Nov-2022
#API #Microservice

In this article we will cover :

  • What is API?

  • API Gateway - The Moderator

  • API Gateway Vs API Proxy

  • API Gateway Vs API Manager

  • Benefits & Restraints of API Gateway


Recap on Microservices


  • Microservices architecture allows you to build an application as a collection of loosely coupled services that implement business capabilities.

  • Continuous delivery/deployment of large, complex applications is possible using microservice.

  • This is more advantageous than a monolithic application built with a database, client, and server application as a single unit.

  • Microservice can handle single service failure well compared to a monolithic application where the whole application goes down.


What is an API?

Application Programming Interface (API) is a business capability delivered to internal or external consumers over the internet.

Let's understand more about API

1. A Web API is a software interface presented over the HTTP protocol that helps in facilitating the development of mobile, Web, and cloud applications.

2. In simple terms, you can imagine API as a messenger that takes your request and tells the system what you want to do, and returns the response back to you.

3. It is available with standard web protocol with a well-defined interface and is accessible by third parties.

API Gateway - The Moderator

1. An API gateway is considered a single interface that takes care of various requests to internal servers.

2. It offers security, governance, integration, and acceleration for API.

3. It is a complete platform to manage, deliver, and secure Web APIs.

4. An API call will be received by the gateway and will route it to the appropriate microservice.


API Gateway vs API Proxy

1. An API Proxy will simply add Transport Security and Monitoring capabilities to an existing API.

2. It does not add anything new, just re-exposes the existing API with some additional capabilities.

3. A gateway has more functionality on top of the API proxy, including content mediation and transformation, rate-limiting, caching, etc.

4. Even though API Proxy is lightweight and offers the same functionality as Gateway, a well-built gateway will offer a lightweight proxy with more capabilities.


API Gateway vs API Manager

1. An API Gateway helps in managing the endpoints.

2. An API Manager can include an API Gateway as part of its features but will include other things like OAuth, caching, role checking, etc.

3. You might get confused with both as some API Gateways try to act as API Managers these days.

4. An API Gateway is just one tool amongst many in an API Managers package.

Let's create a Scenario:-

Let us meet John, who is planning a road trip. For his road trip, John needs a car with services like Insurance, Speed throttler, and Navigator. He can purchase all that separately, but he is looking for a simple solution.

Now let us relate this with our Microservice. 

An application needs a lot of information to run. Each piece of information is taken care of by a separate microservice.

Now the question is how a client would fetch the information from all the services.

A client device can be a desktop or a mobile device. In theory, a client can send a request to all the services individually. Let us see the drawbacks of such a design.


If There is No Gateway?

1. An application might use an 'n' number of services, and a single client making that many calls are quite tricky.

2. Each service might use a different protocol which might need to be more web-friendly.

3. Ideally, an application should use HTTP and WebSocket protocols.

4. It is hard to merge or split services in this design.

5. How to overcome these issues? Yes, you guessed it right. Use an API Gateway.

Using API Gateway

1. An API Gateway is a server that is the single entry point into the system for all clients.

2. It can route the request to one or many services based on the request.

3. It is capable of exposing a client to different APIs based on the devices.

4. It also helps in implementing security


Benefits of API Gateway

1. Gateway is like the tip of the iceberg that Encapsulates the internal structure of the application.

2. Insulates the clients from Location determination of service instances.

3. Provides specific API to each client, reducing the number of round-trips between the client and application.

4. Simplifies the client by moving the logic for calling multiple services from the client to the API gateway.

Restraints of API Gateway

1. Developers need to update the gateway to expose the microservice endpoint which might result in a risk of development bottleneck.

2. Need to develop, deploy and maintain an additional highly available component.

3. Due to the additional network hop through the API gateway, there is an increased response time.


Bonus: Variation of Backend & Frontend

1. In practice, our mobile devices will make fewer calls and will display different (and probably less) data than desktop devices.

2. The general-purpose API backend does a lot of work, and hence a separate team will be required to maintain that.

3. To overcome all these, the before-mentioned pattern can be modified to have a separate gateway for each type of client device.

4. Each gateway has access to all the microservices.

Conclusion

Application Programming Interface (API) is a business capability delivered over the internet, to internal or external consumers. API gateway is considered a single interface that takes care of various requests to internal servers. API Proxy will simply add Transport Security and Monitoring capabilities to an existing API.



anonymous | Nov. 13, 2022, 10:57 p.m.

Awesome!



Related Blogs
Architecture of API Gateway
Author: neptune | 15th-Nov-2022
#API #Microservice
Creating an API starts with the publisher, where it will be designed, and it will be published to the store for the consumer to explore and subscribe...

How to send POST request using Rest Assured framework in Java ?
Author: neptune | 26th-Mar-2023
#Selenium #API
Rest Assured is a popular Java-based framework that is used for testing RESTful web services. It provides a simple and intuitive API for sending HTTP requests and validating the responses...

View More