Member-only story
Microservice Pattern — API Gateway Pagination
This article is all about how to handle large response in API gateway without switching to asynchronous mode.
Let me talk about the challenge and reason that triggered me to get into this pattern.
Challenge
One of our API endpoint which was initially designed with a micro-service pattern in mind started to hit the API limits.
- API Gateway time out (30 sec)
- API response size (6 MB)
The response which happens to be larger than 6 MB limit due to the volume of the transactions this endpoint has to handle causing failures and in certain scenario we were unable to respond back to API gateway before 30 sec.
In another pattern involving Dynamodb, we had similar issue as we need to scan through all the data in Dynamodb within the 30 sec time limit.
In short, as an API provider the challenge is to display data to the user (or) process large number of items without overwhelming clients (or) hitting API timeouts and messing up with response size limit.
Divide & Conquer
The solution is to use the divide & conquer strategy by breaking the large response datasets into manageable and easy to transmit chunks. It adds one more onus on the consumer end to iteratively loop through the pages (chunks) to process the large datasets.