Gowthaman
Gowthaman

Reputation: 59

Is it safe to use a C# static class as a means of sharing data from one azure function to another?

I have two functions under a Azure function plan. Also included in there is a static class with a public static string. Can I use this static string as a means of transferring data from one function to the other?

The main concern I have is regarding instances. If each trigger creates a new copy of the static class and its string content then I believe this shouldn't be a problem. So does each trigger of the first function that calls the static class create a new copy for itself of it or is it shared among different simultaneous function clients?

Should I look for an alternative approach like Redis cache or something similar?

Upvotes: 0

Views: 533

Answers (3)

Pankaj Rawat
Pankaj Rawat

Reputation: 4583

Azure function is serverless. If you are running under a consumption plan multiple function instance will start executing and when instance is idle, it will release instances.

Maintaining state outside function is best approach.

I used Redis for same and seen lot of performance improvement in my application. If you have frequent read/write Redis is best option and you have to pay a dedicated amount for Redis instance.

If function request is not very frequent or budge is constant, you can use "Azure Storage Table" as well. you don't need to pay a dedicated amount.

Upvotes: 2

Carlos Alves Jorge
Carlos Alves Jorge

Reputation: 1995

The best way to achieve what you are trying to do is to use queues with payloads.

Basically one functions puts the data you want to transfer in a queue. The other function has a Queuetrigger that once a message shows will run (being able to access the data)

Upvotes: 0

DixitArora-MSFT
DixitArora-MSFT

Reputation: 1811

Azure Functions offers an alternative for creating stateful functions called Durable Functions. Durable Functions is an extension to the Azure Functions runtime that enables the definition of stateful workflows in code.

For more information follow the below docs.

https://learn.microsoft.com/en-us/dotnet/standard/serverless-architecture/durable-azure-functions https://learn.microsoft.com/en-us/azure/azure-functions/durable/durable-functions-overview

Upvotes: 0

Related Questions