Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Aborting external long running api request inside a Vercel serverless function

I have a request in a Vercel serverless function to an external API using node fetch inside a serverless function. I do not want this to be long running so my plan is to abort the external request if it takes longer than a second.

Is this a good strategy?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Yes, this is a valid approach.

Serverless functions in the Vercel Hobby plan already have a built-in timeout of 10s, so maybe you don’t even need to worry about doing this yourself.

If you choose to do this, I would recommend increasing the timeout duration. It is common for an API request to take longer than a second ("depends", of course). But maybe a timeout of 3s or 5s is good enough.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading