Write Stateless and Idempotent Functions
    • Dark
      Light
    • PDF

    Write Stateless and Idempotent Functions

    • Dark
      Light
    • PDF

    Article Summary

    #ServerlessTips - Azure Functions
    Author: Steef-Jan Wiggers Azure MVP

    Azure Functions have an event-driven programming model, and functions can run stateless and stateful.

    When you design a serverless architecture then you should write your functions stateless and idempotent. Any state that belongs to the data that a function receives – the function itself should remain stateless while processing that data.

    For instance, when orders are picked up from a service bus, the function handles it and pushes it to a Cosmos DB collection. The processing can be a simple transformation of the DateTime data element to another format or change of currency. The state of the order (data) will be inserted into Cosmos DB.

    Tip 5 - Write stateless and idempotent functions - Picture 1.png

    Another example with regards to idempotency could be a function with an automated task using the timer trigger. The function must run once a day; therefore you need to write so it can run any time during the day with the same results. Furthermore, the function could exit if there’s no work or if a run fails the function picks where the previous left off.

    Tip 5 - Write stateless and idempotent functions - Picture 2.png

    In a serverless architecture, your functions should “do one thing”, be stateless and idempotent, and finish as quickly as possible.

    Finally, in case you do need state you can use Durable Functions.


    Was this article helpful?