Lambda taking inconsistently longer than 10 secs to finish


I have a lambda to create a user account on Stripe (define a product, a plan, create a customer) . Half the time, this process takes over 10secs to get a response, and returns a 500.

Has anyone else come across this issue ? What’s the best practice in this case ? Is there a way to automatically resend the server request until it returns the 200 I am expecting (i.e. until it takes less than 10 secs) ?

Thanks for your support

UPDATE : So I modified my lambda. Rather than coding the whole Stripe’s user profile in one lambda, I split it into 4 lambdas. One to create a customer (first step), one to create a product, etc…

I understood that it’s best practice that a serverless function does only one thing.

In my customer creation lambda, that’s basically all I do :
const customer = await stripe.customers.create({ email: });
And the only library I import is the Stripe Sdk.
I cannot do less than that.

Now, I sometimes get a response within about 2 secs, sometimes within 10 to 12 secs, and a 500 as a result. If I understood correctly, it has to do with cold start and warm start of the lambda.

What can I do from here ? Is there a way to automatically trigger retries ? Is it good practice to send multiple server requests until it takes less than 10 secs to get a reply ?

Hi @harvey56,

You can retry from your clientside if you are making the request from there. It’s possible the issue is with cold starts, but that would be odd, I typically don’t have an issue there. Have you tried adding logging and/or error tracking to your function?