*warning — please drink coffee for better experience*
API Gateway series list
- API Gateway Part 1 (You’re here)
- API Gateway Part 2
Imagine you are building an online store. Your application feature:
- Product Detail
- List of Product
Based on all of feature above you have these service:
- Product Service
- Order Service
- Pricing Service
- Account Service
- Customer Review Service
- Inventory Service
Since your application use microservice architecture and the data is spread accross multiple service. Let’s say you open the home page and search for bug spray. The UI of your application need list of product data, customer review data, inventory data, and maybe account data just to display the product list page (picture below).
Consequently, the code that display the product list needs to fetch information from Product Service, Account Service, Customer Review Service, and Inventory Service.
In this design, the client application is playing the role of API composer. It invokes multiple services and combine the results.
So, what’s the problem????
Although the approach seems reasonable, it has some serious problems.
Poor User Experience Due To The Client Making Multiple Requests
The client must make multiple requests to retrieve the data and the client need to execute requests sequentially. It requires the client developer to write potentially complex API composition code.
Lack Of Encapsulation
The developer of a service sometimes add new services and might even change the API. But if knowledge about the service is composed in the client side, it can be difficult to change the service’s API and maybe can breaks existing client.
Unfriendly Protocol for The Client
Some of service might use gRPC, or maybe AMQP messaging protocol. These kind protocol work well internally, but might not be easily consume by mobile client. Or maybe the mechanism of some protocol might be hard to adapt in some client platform.
How to design and create an API gateway?
I will discuss it in the part 2
Again I would say thanks to all my readers and I hope I will comeback with more interesting topic.