Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

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?
nicoazrak
Roger Henman
Roger Henman
Prince7hakur
georgetsertsvadze97
Daniel van Flymen
notorioushanz
c16c6e04b96844b5965bbf8d0cc35e
52f42ab1fed54774a499079755cbc3
Eleanor