← Back to blog

How to estimate requests in serverless hosting

Published at Dec 7, 2024

#serverless#hosting

How to estimate requests in serverless hosting

When you host a serverless application, you pay for the resources you use.
One of the most common resources you pay for is the number of requests your application receives.
But what is considered a request in serverless hosting?

What is a request in serverless hosting?

If your page checks a serverless function for authentication data.
Then makes a request to another function to get the user’s data.
Then makes a request to a third function to get the user’s profile picture.
Then makes a request to a fourth function to get the user’s friends list.

Then that is 5 requests. The initial request to the page, and 4 requests to functions.

And without caching, every time a user visits your page, these requests will be made.

API endpoints are also functions

Remember that API routes are also just functions, and if the endpoint calls many functions you have to count them aswell.

Caching

If your hosting provider provides caching for your pages, or even better for functions, then these will not be counted as requests.

You can also set cache headers for functions to cache the response for a certain amount of time.

Memory allocation

Remember that the memory you allocate to a function also affects the cost. If you allocate more memory, the function will run faster, but it will also cost more.

Function runtime

The longer a function runs, the more it costs. If you have a function that runs for 1 second, it will cost more than a function that runs for 50 milliseconds.