An Introduction to API Gateway

Amazon API Gateway is a fully managed service that helps developers to create and deploy scalable APIs on AWS. These APIs act as an entry point for the applications to connect and get access to data, perform business logic or access any other AWS service. There are mainly two types: RESTful and Web-Socket APIs.

API Gateway in Action

\"Introduction
Introduction to Amazon API Gateway

As you can see in the above image, users call an API gateway that can forward their request to any one of the services to process it right. API gateway can integrate with Amazon services like Kinesis and DynamoDb directly or you can write your own code in AWS lambda and connect it with the API gateway. Every request received by the API gateway will be forwarded to lambda and the response returned from it will be returned to the user.

The Problem Statement – Why should I use API Gateway?

Now the question which often comes is why should I use API gateway? And the simple answer is you don\’t have to if you don\’t want to. It is a personal choice, but I feel it is good especially when you are dealing with lots of microservices. Following are some issues with it:

  • Microservices usually provides granular APIs as they are granular also. This makes it hard for a client to connect with multiple services to complete the basic view required to show to the user.
  • The way services are designed and the way they are partitioned changes over time and this should be hidden from the client. Otherwise, we will end up changing our client a lot.
  • Different clients will need different data as per the requirements of the user they are catering to.
  • With aggregating and clients connecting to multiple services, it makes it hard to manage for both client and the services.
\"Issues
Issues with Microservices

How can this be solved using an API gateway?

API gateway act as a single entry point for all clients. It will handle requests either by routing them to the appropriate service or by fanning out to multiple services. Amazon API Gateway can connect with some of the services directly. It can directly save data in DynamoDb, fan out the request using Kinesis or SNS. The following image shows the API gateway in the same scenario.

\"Using

This will help in the following:

  • The clients don\’t have to be aware of the internal partitioning of the microservices.
  • The clients don\’t have to worry about finding out the location of the services.
  • It simplifies the client by calling it API Gateway rather than multiple services.
  • It can translate a standard HTTP request to a different protocol internally and also allows you to fan out the same request to multiple services.

How to get started?

Here are great resources from AWS to start your journey. I will be posting articles related to my experience in future. For now, have a look at the following links.