Heinrich Ulbricht
Heinrich Ulbricht

Reputation: 10372

How to persist state in Azure Function (the cheap way)?

How can I persist a small amount of data between Azure Function executions? Like in a global variable? The function runs on a Timer Trigger.

I need to store the result of one Azure Function execution and use this as input of the next execution of the same function. What is the cheapest (not necessarily simplest) way of storing data between function executions?

(Currently I'm using the free amount of Azure Functions that everyone gets and now I'd like to save state in a similar free or cheap way.)

Upvotes: 19

Views: 22622

Answers (3)

Lance
Lance

Reputation: 632

Durable entities are available to handle persistence of state.

Upvotes: 8

Krishana Kumar
Krishana Kumar

Reputation: 151

This is old thread but worth sharing the new way to handle state in Azure function.

Now we have the durable function approach from Microsoft itself where we can maintain the function state very easily and effectively. Please refer the below documentation from MS.

https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview

Upvotes: 8

Matt Mason
Matt Mason

Reputation: 2724

There are a couple options - I'd recommend that you store your state in a blob.

You could use a blob input binding to read global state for every execution, and a blob output binding to update that state.

You could also remove the timer trigger and use queues, with the state stored in the queue message and a visibility timeout on the message to set the schedule (i.e next execution time).

Finally, you could use a file on the file system, as it is shared across the function app.

If you can accept the possibility of data loss and only care at the instance level, you can:

  • maintain a static data structure
  • write to instance local storage

Upvotes: 13

Related Questions