What is API Gateway
API Gateway can be considered a backplane to connect and other public or private websites. It provides RESTful application programming interfaces (APIs) for mobile and web applications to access its services. Its a one-stop shop for the client, anything client wants API Gateway will get it for him.
How do the clients of a Microservices-based application access the individual services?
- The number of service instances and their locations changes dynamically
- Services might use a diverse set of protocols, some of which might not be web friendly
- Different clients need different data. For example, the desktop browser version of a product details page desktop is typically more elaborate than the mobile version.
- Partitioning into services can change over time and should be hidden from clients
Implement an API gateway that is the single entry point for all clients. The API gateway handles requests in one of two ways. Some requests are simply proxied/routed to the appropriate service. It handles other requests by fanning out to multiple services.
Rather than provide a one-size-fits-all style API, the API gateway can expose a different API for each client. For example, the Netflix API gateway runs client-specific adapter code that provides each client with an API that’s best suited to its requirements.
The API gateway might also implement security, e.g. verify that the client is authorized to perform the request, IP whitelisting, Domain whitelisting, rate limiting all these can be part of API Gateway so that your individual micro-services focuses on the more important tasks at hand which they are ought to do.
Here is a flow of Microservices with API Gateway
Using an API gateway has the following benefits:
- Insulates the clients from how the application is partitioned into microservices
- Insulates the clients from the problem of determining the locations of service instances
- Provides the optimal API for each client
- Translates from a “standard” public web-friendly API protocol to whatever protocols are used internally
- Simplifies the client by moving logic for calling multiple services from the client to API gateway
- Your microservices can just focus on the task at hand rather than focusing on layers like Authentication, Authorisation, Rate limiting, Whitelisting which other microservices also have to implement.
- Increased complexity – the API gateway is yet another moving part that must be developed, deployed and managed
- Increased response time due to the additional network hop through the API gateway – however, for most applications the cost of an extra roundtrip is insignificant.
Real life examples
Thanks for dropping by !! If you feel you like this article please drop a comment to this post or you can send an email at email@example.com.