George Kosmidis

Microsoft MVP | Speaks of Azure & .NET | Founder of Munich .NET
Building tomorrow @
slalom
slalom

Azure Scale Set vs Azure Availability Set

by George Kosmidis / Published 1 month ago
Azure Scale Set vs Azure Availability Set

In this blog post, we will be comparing two important features in Azure: Scale Sets and Availability Sets. Both of these features are designed to help you manage and scale your applications, but they work in different ways and are suitable for different use cases. Understanding the differences between these two features is important if you are planning to use Azure to host your applications.

Scale Sets

An Azure Scale Set is a group of identical virtual machines (VMs) in Microsoft Azure that can be configured to automatically increase or decrease the number of VMs in the set based on demand. Scale sets provide a way to deploy and manage a large number of VMs in a consistent, predictable manner. They are designed to support workloads that are scalable and require a high level of availability.

Scale sets are particularly useful for running stateless applications, such as web servers, that can be easily scaled up or down based on the needs of the workload. They can also be used to run stateful applications, such as databases, by using managed disks to persist data across multiple VMs.

In addition to automatically scaling the number of VMs in the set, Azure Scale Sets also provide features such as automatic health monitoring, load balancing, and rolling upgrades, which make it easier to deploy and manage large-scale applications in Azure.

One of the key capabilities of Scale Sets is autoscaling, which allows you to automatically increase or decrease the number of VMs based on demand.
Here is an example of how you could use Bicep to deploy an Azure Scale Set:

  // Define the Scale Set resource
  resource scaleSet 'Microsoft.Compute/virtualMachineScaleSets@2019-03-01' = {
    name: 'myScaleSet'
    location: 'westus2'
    sku: {
      name: 'Standard_DS2_v2'
      capacity: 2
    }
    properties: {
      upgradePolicy: 'Manual'
      virtualMachineProfile: {
        osProfile: {
          computerNamePrefix: 'vm'
          adminUsername: 'admin'
          adminPassword: 'P@ssw0rd'
        }
        storageProfile: {
          imageReference: {
            publisher: 'MicrosoftWindowsServer'
            offer: 'WindowsServer'
            sku: '2019-datacenter'
            version: 'latest'
          }
        }
        networkProfile: {
          networkInterfaceConfigurations: [{
            name: 'nic'
            properties: {
              primary: true
              ipConfigurations: [{
                name: 'ip'
                properties: {
                  subnet: {
                    id: '/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet'
                  }
                }
              }]
            }
          }]
        }
      }
    }
  }
  
  // Define the Outputs
  output scaleSetId {
    value: resourceId(scaleSet)
  }
  
And here is the same with Terraform:

  # Define the Scale Set resource
  resource "azurerm_virtual_machine_scale_set" "my_scale_set" {
    name                = "myScaleSet"
    location            = "westus2"
    resource_group_name = "myResourceGroup"
    sku {
      name     = "Standard_DS2_v2"
      capacity = 2
    }
    upgrade_policy {
      mode = "Manual"
    }
    virtual_machine_profile {
      os_profile {
        computer_name_prefix = "vm"
        admin_username       = "admin"
        admin_password       = "P@ssw0rd"
      }
      storage_profile_image_reference {
        publisher = "MicrosoftWindowsServer"
        offer     = "WindowsServer"
        sku       = "2019-datacenter"
        version   = "latest"
      }
      network_profile {
        network_interface {
          name    = "nic"
          primary = true
          ip_configuration {
            name      = "ip"
            subnet_id = "/subscriptions/{subscriptionId}/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"
          }
        }
      }
    }
  }
  
  # Define the Outputs
  output "scale_set_id" {
    value = azurerm_virtual_machine_scale_set.my_scale_set.id
  }
  
Both samples will create an Azure Scale Set with 2 VMs, using the Standard_DS2_v2 VM size and the latest version of the Windows Server 2019 Datacenter image. The Scale Set will be placed in the 'westus2' region and will have a manual upgrade policy. The VMs in the Scale Set will have a computer name prefix of 'vm', an admin username of 'admin', and an admin password of 'P@ssw0rd'. The output of both will be the ID of the Scale Set resource. (The samples assume a virtual network and subnet that you will need to create in advance)

Availability Sets

An Azure Availability Set is a group of VMs within a single Azure region that are designed to be highly available. The VMs in an availability set are placed in different fault domains and update domains, which helps to ensure that the VMs remain available even if there is a hardware or software failure or if Azure performs maintenance on the host infrastructure.

By placing VMs in an availability set, you can ensure that your workloads are distributed across multiple physical servers, network switches, and storage units. This helps to protect your applications from a single point of failure and improve the overall resiliency of your Azure environment.

To use an availability set, you simply create the VMs you want to include in the set and then specify the availability set when you create the VMs. Azure will automatically distribute the VMs across different fault domains and update domains to ensure that they are highly available.

Availability Sets take the virtual machine and configures multiple copies of it. Each copy is isolated within a separate physical server, compute rack, storage units and network switches within a single datacenter within an Azure Region.

  // Define the Availability Set resource
  resource availabilitySet 'Microsoft.Compute/availabilitySets@2019-03-01' = {
    name: 'myAvailabilitySet'
    location: 'westus2'
    properties: {
      platformFaultDomainCount: 2
      platformUpdateDomainCount: 2
    }
  }
  
  // Define the Outputs
  output availabilitySetId {
    value: resourceId(availabilitySet)
  }

This code will create an Azure Availability Set with 2 fault domains and 2 update domains again in the 'westus2' region. The output of this code will be the ID of the Availability Set resource.

To attach a VM to this Availability Set, you will need to specify the ID of the Availability Set as the 'availabilitySetId' property when creating the VM resource.


  // Define the VM resource
  resource vm 'Microsoft.Compute/virtualMachines@2019-03-01' = {
    name: 'myVM'
    location: 'westus2'
    properties: {
      availabilitySet: {
        id: resourceId(availabilitySet)
      }
      ...other properties
    }
  }

This will attach the VM to the Availability Set, ensuring that it is placed in a different fault and update domain from the other VMs in the set.

In a similar fashion the following samples will create an availability set with Terraform


  # Define the Availability Set resource
  resource "azurerm_availability_set" "my_availability_set" {
    name                = "myAvailabilitySet"
    location            = "westus2"
    resource_group_name = "myResourceGroup"
    platform_fault_domain_count = 2
    platform_update_domain_count = 2
  }
  
  # Define the Outputs
  output "availability_set_id" {
    value = azurerm_availability_set.my_availability_set.id
  }

And to attach a VM:


  # Define the VM resource
  resource "azurerm_virtual_machine" "my_vm" {
    name                  = "myVM"
    location              = "westus2"
    resource_group_name   = "myResourceGroup"
    availability_set_id   = azurerm_availability_set.my_availability_set.id

    ...other properties
  }

Use Cases

In terms of use cases, Scale Sets are best suited for applications that can scale out horizontally, such as web servers and batch processing systems. They are not designed to ensure the availability of an application in the event of a hardware failure or maintenance event. On the other hand, Availability Sets are designed specifically to ensure the availability of an application by placing VMs in different fault and update domains. They are not designed for horizontal scaling like Scale Sets.

Fault domains refer to the physical infrastructure within a data center, such as racks and power supplies. By placing VMs in different fault domains, you can ensure that your application remains available even if there is a hardware failure or maintenance event that affects one of the fault domains. For example, if you have an Availability Set with 3 fault domains and you deploy 2 VMs in each fault domain, then at least 2 VMs will be available even if one fault domain goes offline.
Update domains refer to the groups of VMs that can be taken down for maintenance at the same time. By placing VMs in different update domains, you can ensure that your application remains available even if there is a planned maintenance event that affects one of the update domains. For example, if you have an Availability Set with 3 update domains and you deploy 2 VMs in each update domain, then at least 2 VMs will be available even if one update domain goes offline for maintenance.

Conclusion

In summary, Azure Scale Sets and Availability Sets are both useful features that can help you manage and scale your applications in the Azure cloud. However, they work in different ways and are suitable for different use cases. Scale Sets are best suited for applications that can scale out horizontally, while Availability Sets are best suited for ensuring the availability of an application. It is important to understand the capabilities, use cases, and limitations of these two features in order to decide which one is best suited for your needs.

This page is open source. Noticed a typo? Or something unclear?
Edit Page Create Issue Discuss
Microsoft MVP - George Kosmidis

My next events!

Online
Online event
Azure Architecture Icons - SVGs, PNGs and draw.io libraries