Server Method Invocation taking way too long on cold start

I use SMI to make calls from frontend to the backend for a complex operation that involves usage of several node modules.

The overall time it takes for the operation to complete is under 3s.

Marketplace Limits
The Server Methods have a timeout of 20s.
SMI calls from the frontend have a timeout of 5s.

This mismatch causes the frontend to fail, but the action gets completed by the backend.
So, I can’t say for sure in the UI whether or not the action was successful with absolute certainty.

100% of the time, my backend completes in under 3s.

Very first SMI times out after installation
However, after app installation, for the very first time when an SMI is invoked, the backend takes way too long, so the frontend times out after 5s.

I’m guessing this is due to the cold-start of lambda function for the very first time.

My recommendations

  1. Increase the frontend timeout to match the Server Method timeout of 20 seconds.
  2. Account for cold start of lambda and give a more generous timeout to the frontend.
  3. Make the timeout a configurable parameter during SMI call from frontend.