Parallelizing API Calls in Node.js

… and cake at the end

Paul Heath
2 min readMay 22, 2020
Same user request with results from different API endpoints

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.

Promise me you’ll return quickly

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!

Nigella Lawson’s Ciambella + George Dickel

--

--

Paul Heath

2x CTO Co-Founder from the travel world. Retired but can't help still coding & researching the cool tech.