Programmatic IoT Hub Scaling
Start course

This course will focus on the skills needed to integrate Azure Monitor and its corresponding features within IoT solutions. Each service within a given IoT solution has the ability to produce metrics, logging, and alerting data. How are you going to gather all of that information and make it available to users that are managing and maintaining your solutions? This course will provide the answers to that question!

Learning Objectives

  • Understand the different metrics and diagnostics that can be retrieved from the Azure IoT Hub
  • Learn how to configure the IoT Hub for scaling programmatically
  • Learn how to query and visualize the data that is stored in Azure Monitor
  • Define specific Azure policies for your IoT Hub so that the hub meets your requirements
  • Learn how to gather metrics and diagnostics from IoT Edge

Intended Audience

  • Developers
  • Operational engineers
  • Cloud architects
  • Anyone responsible for deploying IoT solutions on Azure


To get the most out of this course, you should have a strong understanding of the available IoT services that Microsoft provides, as well as a strong understanding of Azure Monitor and the different types of data that can be retrieved through all of its features and services.


Hi there. Welcome back. In this video we're gonna be talking about how to take your IoT Hub and scale it whenever necessary. Now there's a number of ways that you can do it automatically, but then there are also many ways that you need to understand when you need to do it manually. Now, why exactly would you ever want to scale your IoT Hub? IoT Hubs by design can handle huge amounts of throughput or huge numbers of messages. The first reason is to increase that message throughput and that can be done via setting the number of units that are available inside of your IoT Hub to be able to handle a specific number of messages that are being processed. The second is to provide more operations because Iot Hub, according to each tier size, throttles the number of operations for things like Device-to-cloud sends, new device connections or job operations, and there's a big, long list in the Azure documentation. The link for information about this is at the end of the slide deck.

So, you might wanna try and scale the number of units to help with message throughput or you might wanna actually upsize your IoT Hub, or even downsize in some circumstances your IoT Hub to handle more operations. When scaling, as I mentioned, there are the two different spots. The first is the SKU. This is the size. At the beginning of the creation process, you define whether you wanna Basic or Standard, and whether you want it to be size one through three.

If you are Basic one, maybe you need to upscale it to Basic two or maybe you learn later on that you need to provide more functionality and upsize, which would mean you would go to a Standard two. If you're going to be increasing the message throughput, then you're going to be scaling the number of units, and at the Basic tier, you can do a maximum of 200 units, for sizes one and two, same thing with Standard.

For the three size, you're gonna get a maximum of 10 for each one, and the reasoning for that is because at the three size your default message throughput per unit is already tremendously higher, and Microsoft can only support a certain number of units. Now please keep in mind, many of these both sizing and unit maximums are soft, meaning that you can potentially reach out to Microsoft Support and request higher numbers.

Now in order to actually do your scaling, there are a number of different methods with different language support. So what I wanted to do is provide you with some code samples based on the available command line tools that Azure provides: the Azure CLI and Azure PowerShell. And as you can see here, the Azure CLI actually requires you to use two different commands, one for the unit, one for the SKU, whereas Azure PowerShell allows you to do both of them at one time.

Now both of these commands are fairly simple. They require your resource group name, the name of your IoT Hub, and then the values that you wanna change your sizing to, depending upon units or SKU. So this would be what your code would look like. Let's go ahead and do a quick demo of that, and in order to do that I will be grabbing this PowerShell command here that you're seeing and taking advantage of that particular command.

Okay, here we are back in the Azure Portal and as you can see, I've got up at the top the IoT Hub that we've been using throughout the course, course IoT Hub in the IoT Monitoring resource group. And if you look on the right-hand side, we currently have provisioned a Basic one size IoT Hub with one unit currently provisioned. What we're gonna do is to upsize this to a Basic two sized IoT Hub and have two units provisioned and we're gonna do that all via the one command from Azure PowerShell.

Now in Azure Shell, you are only allowed to do a right click paste, the Control V does not work. So here we are, we've got our command and the first thing we're gonna do is change out the resource group name. Next, we'll change out the Hub name. And then last, we'll change the size in units. Okay, that looks right. We are setting our Azure IoT Hub with ResourceGroupName, IoTMonitoring, IoT Hub name, course-iot-hub. We're gonna change the size to be two and give it two units. And there is our success message letting us know that course-iot-hub has been changed and everything is successful.

Now to validate this, all we need to do is do a quick refresh up here in the portal and there we go. Pricing and scale tier, B2, number of IoT hub units, two. It's that simple to do a manual scaling. Now you might be going, but Brian, I need to do this in an automated fashion. Two things. Number one, I have provided you at the end of the slide deck a URL to a GitHub repository where a Microsoft-created solution is available for you to do automated scaling of your IoT Hub based on specific parameters that you define in the code. It is built on Azure Functions, does do some metric scanning to determine things or message throughput scanning to determine when that scaling should occur.

You can also use these commands inside of Azure Monitor Alerts to also automate the process of up scaling or changing the scaling of your particular IoT Hub. So when an alert fires, you set up an alert based on Azure Metrics, and say when XYZ number is found, you then trigger an Azure Function, or you trigger a Azure Automation Runbook which can be based on Azure PowerShell and it can do that automated scaling for you. You would probably, of course, want to find things like what is the existing numbers before you set up this scaling up, but you can set that up via Azure Alerts as well. In the next video, we'll take a look at how to visualize data that has been produced by Azure Monitor, such as the metrics that we looked at and the diagnostics that we looked at earlier, and how to visualize that data inside of Azure.

About the Author

Brian has been working in the Cloud space for more than a decade as both a Cloud Architect and Cloud Engineer. He has experience building Application Development, Infrastructure, and AI-based architectures using many different OSS and Non-OSS based technologies. In addition to his work at Cloud Academy, he is always trying to educate customers about how to get started in the cloud with his many blogs and videos. He is currently working as a Lead Azure Engineer in the Public Sector space.