I know that cloud functions charge money based on execution time and network costs.
I am writing a cloud function that calls 2 external APIs to authenticate a user. Both external APIs just return a single boolean and therefore don't send much info.
Which technique is better overall?
Make both external API calls using fetch() at the same time knowing that 1 may be useless half the time.
Make the external API call one after the other, and not make the second one if not needed.
I'm thinking doing #1 will shorten the "wall time" of my cloud function and therefore may be cheaper? But I make more external calls which may be expensive?
But doing #2 will make the cloud function stay in memory for longer and therefore more "wall time".
Method 1 results in more complex code as you will need to wait for both fetches to complete unless you like container crashes to debug.
Method 2 is simpler to implement and debug but could result in longer wall clock time.
You will need to decide which method is better when you factor development time, debugging time, analyzing errors in logfiles, and execution time.