Introduction to Amazon API Gateway
Amazon API Gateway is a fully managed service which 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
As you can see in the above image, users call an API gateway which can forward there 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 reuest 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 dont want to. It is a personal choice, but i feel it is good specially 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.
How can this be solved using API gateway?
API gateway act as a single entry point for all clients. It will handle requests either by routing it to the appropriate service or by fanning out to multiple services. Amazon API gateway can comnect with some of the services directly. It can directly save data in DynamoDb, fan out the request using Kinesis or SNS. Following image shows API gateway in the same scenario.
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 fanout 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 folowwing links.I would love to hear what you think about this article and if there anything you would like me to cover in future. Drop me a line on @awsmag.