I have a question related to the best approach when resources are limited, such as on the Azure Function consumption plan.

I have an IoT device, and the number of IoT devices is likely to increase to several hundreds, then progressing to a few thousand. These IoT devices need to be instructed to switch on and off external devices such as lights or motors at specific times, and their status needs to be monitored and reported while they are on.

Currently, every time an operation is required, my process creates a durable function that performs an operation, goes to sleep for approximately 10 seconds, and then reports the status of the device until it is requested to switch off.

This process means that for every operation or IoT device, an instance of a durable function is required. Therefore, as the number of devices increases, the resources required to run them will also increase. There was one instance where the durable function failed in the middle of the process, which meant that particular IoT device was in an unknown stage in the overall process.

I am thinking that a batch process might be a better approach.

I could have a global process that is triggered every 5-10 seconds, which would be an Azure Function Timer Trigger. Within this process, I would identify all devices that need to be controlled, then have a type of for loop that oversees all necessary devices and saves the previous status or state, so that on the next trigger of the function, it could continue where it left off. The idea behind this is to have a case or state function that saves the previous state of the device operation, either in Azure Table storage, SQL, or cache.

Would this be a good approach? If needed, I can show an example code of my process, but it's really a general state machine/case statement where the IoT device has some operational commands, and then based on the device feedback, the next operation is executed.

Thank You

  • 1
    If you have something that runs every ten seconds, it doesn't seem like a good candidate for serverless computing. You are running continuously and a simple service could do this job without the overhead and limits of spinning up functions.
    – Ewan
    Commented Mar 28, 2023 at 20:24
  • Is there an example of a simple service? Commented Mar 29, 2023 at 8:12


Your Answer

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

Browse other questions tagged or ask your own question.