AZ Lamps #15 — Target-Based Scaling
Finally, I can write about horizontal Scaling because Azure Functions (Consumption and Premium) got a brand new feature these days — Target-Based Scaling.
Remember that “scaling horizontally” means creating new copies of the program to handle the increased load. This option has always been in Azure for Functions, App Services, Virtual Machines (Scale Sets), and other cloud services. A cloud developer simply needs to create a scaling rule, e.g., “If there are 1000 messages in the queue, spin-off four new functions”.
Note that we hardcoded the “increase by” parameter above — 4. But what if 1200, 1600, or 2000 messages are in the queue? Should we create a new rule for each case? Target-Based Scaling solves the problem as estimating of “increase by” parameter occurs automatically. The dynamic formula is below:
The number of functions needed = current queue length / amount of messages a sole function can process.
In the example above, we run five functions (1+4) for 1000 messages. That said, we expect one function instance to handle 200 messages. This number is the formula denominator and must be set in Azure to let Target-Based Scaling work.
Worth mentioning that a new feature is compatible only with message queues: Service Bus, Storage Queue, Event Hub, and CosmosDb extensions. But this is an excellent start to creating a flexible scaling strategy that suits your interests.