Serverless variables/server-side data in a serverless environment | DigitalOcean


Serverless variables/server-side data in a serverless environment | DigitalOcean

I am using DitigalOcean Functions to make a serverless API. The server has an integer variable, “countâ€. The function processes a post request, and depending on the data in the request, it will increment the count variable, decrement the count variable, reset the count variable to 0, or return the value of the count variable.

From my testing, the API works exactly as intended but I’m wondering if it would be better to connect the function to a database and store the value of the variable there.

If I compare the serverless function to a traditional program, the value of the count variable will be lost when the process representing the program stops executing. In a serverless environment, is it possible that some requests will be handled by a different processes and therefore return different results for the value of the server-side variable? When traffic to the API changes, and more resources need to be allocated or de-allocated to the function, will the process terminate and be restarted, therefore resetting the count variable?

To put my question another way: If I need to store a small amount of data (a single integer variable) how can I ensure that this data will be persistent in a serverless environment?

Previous articleNext article

POPULAR CATEGORY

corporate

12813

tech

11464

entertainment

15995

research

7394

misc

16829

wellness

12912

athletics

16929