Parallelizing API Calls in Node.js
… and cake at the end
Scenario
You want to pull similar data from multiple 3rd party sources, inspect the results, and return most relevant content to the user.
Issue
Calling each API endpoint sequentially takes too long.
Approach
Using Promises, make the call to each API endpoint simultaneously — all of the work, and waiting, happens in parallel.
Above technique was used in the development of https://app.staycay.io — a travel destination assistant.
For example, when user requests ‘cooking classes’ for a given destination, the AWS Lambda Node.js function simultaneously requests this info from Viator (Activities Provider) AND Yelp (Local Business) API’s, and determines which to return.
User enters:
cooking classes in shanghai
cooking classes in seattle
User receives best content for a given destination, and generally only waits a few 100 milliseconds for all of that to resolve. #winning
The Cake
As promised, here is my implementation of Nigella Lawson’s Ciambella (ring cake) — I also drank and baked in parallel. Shoutout to George Dickel for being such an able assistant!