0

I'm creating an Azure Function that will run in consumption mode and will get triggered by messages in a queue.

The function will typically need to make a database call when it gets triggered. I "assume" the function gets launched and loaded to memory when it gets triggered and when it's idle, it gets terminated because it's running in consumption mode.

Based on this assumption, I don't think I can load up a singleton instance of my back-end client which includes the logic for making database calls.

Is then new'ing up my back-end client the right approach every time I need to perform some back-end operations?

1 Answer 1

2

This is a wrong assumption. Your function will be loaded during the first call, and will be unloaded only after an idle timeout (5 or 10 minutes).

You will not pay for idling, but you will pay for the whole time that your function was running, including the wait time during the database calls (or other IO).

Singletons and statics work just fine; and you should reuse instances like HttpClient between the calls.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.