Migrating between Standard and Autoscale Throughput using PowerShell or Azure CLI is an important skill for anyone preparing to tackle the DP-420 exam, focusing on designing and implementing native applications using Microsoft Azure Cosmos DB. Messing up database throughput allocation can result in cost overruns or application performance issues. By using either PowerShell or Azure CLI, you can seamlessly migrate between standard (manual) and autoscale throughput to tune your cosmos DB database.
Understanding Standard and Autoscale Throughput
Standard Throughput (also called Manual Throughput), is specified in Request Units per Second (RUs/sec). You must set it according to peak traffic requirements. Exceeding your set RUs/sec rate might result in rate-limits and subsequently throttled operations.
Autoscale Throughput dynamically adjusts between 10% and 100% of the maximum RUs/sec that you set, making it cost-effective for workloads with variable traffic patterns.
Autoscale Throughput | Standard (Manual) Throughput | |
---|---|---|
Cost | Based on highest RU/s used | Based on provisioned RU/s |
Ideal for | Variable traffic | Predictable or constant traffic |
Rate limiting/throttling | Less likely | More likely for peak traffic |
Migrating using PowerShell
Before migrating using PowerShell, ensure you’ve installed and signed in to the Azure PowerShell.
Migrate from Standard to Autoscale Throughput
Replace `databaseName`, `containerName`, `resourceGroupName`, and `accountName` with the appropriate values.
$throughput = New-CosmosThroughputSettingsObject -AutoscaleMaxThroughput 4000
Update-CosmosDbThroughput -ResourceGroupName "resourceGroupName" -AccountName "accountName" -DatabaseName "databaseName" -ContainerName "containerName" -ThroughputSettingsObject $throughput
This script creates a new CosmosDB autoscale throughput settings object with a maximum throughput of 4000 RU/s and applies these settings to the Cosmos DB container.
Migrate from Autoscale to Standard Throughput
Replace `databaseName`, `containerName`, `resourceGroupName`, and `accountName` with the appropriate values.
$throughput = New-CosmosThroughputSettingsObject -Throughput 400
Update-CosmosDbThroughput -ResourceGroupName "resourceGroupName" -AccountName "accountName" -DatabaseName "databaseName" -ContainerName "containerName" -ThroughputSettingsObject $throughput
This script creates a new CosmosDB manual throughput settings object with a throughput of 400 RU/s and applies these settings to the Cosmos DB container.
Migrating using Azure CLI
Before using Azure CLI commands, make sure you’ve installed and logged in to Azure CLI.
Migrate from Standard to Autoscale Throughput
Replace `resource-group`, `account-name`, `database-name`, and `container-name` with the appropriate values.
az cosmosdb sql container throughput update --resource-group="resource-group" --account-name="account-name" --database-name="database-name" --name="container-name" --throughput-type "autoscale" --max-throughput 4000
This command updates the throughput settings of a Cosmos DB SQL container to autoscale with a maximum throughput of 4000 RU/s.
Migrate from Autoscale to Standard Throughput
Replace `resource-group`, `account-name`, `database-name`, and `container-name` with the appropriate values.
az cosmosdb sql container throughput update --resource-group="resource-group" --account-name="account-name" --database-name="database-name" --name="container-name" --throughput-type "manual" --throughput 400
This command updates the throughput settings of a Cosmos DB SQL container to manual with a throughput of 400 RU/s.
Conclusion
Whether to use standard or autoscale throughput would depend on your application’s requirements, expected traffic, and cost considerations. Thanks to Azure PowerShell or Azure CLI, migrating the throughput model is a task that can easily be accomplished. These commands are really useful when preparing for the DP-420 exam. By understanding these commands and when to use them, you’ll be better equipped to design and implement native applications that efficiently leverage Microsoft Azure Cosmos DB.
Practice Test
True/False: Autopilot in Azure Cosmos DB is not used to handle the changing workloads.
- True
- False
Answer: False
Explanation: The Autopilot in Azure Cosmos DB is designed to handle changing workloads by automatically scaling the throughput as needed.
True/False: Using Azure PowerShell to manage Azure resources is generally faster than using the Azure portal.
- True
- False
Answer: True
Explanation: PowerShell provides a command-line interface for executing commands, which tends to be faster than navigating the GUI of the Azure portal.
You can use Azure CLI to migrate between standard and autoscale throughput in Azure Cosmos DB. Which of the following commands is correct to set up autoscale throughput?
- A. az cosmosdb update –name MyCosmosDBAccount –resource-group MyResourceGroup –max-throughput 4000
- B. az cosmosdb create –name MyCosmosDBAccount –resource-group MyResourceGroup –max-throughput 4000
- C. az cosmosdb throughput update –name MyCosmosDBAccount –resource-group MyResourceGroup –type database –max-throughput 4000
- D. None of the above
Answer: C
Explanation: The ‘az cosmosdb throughput update’ command is used to update throughput settings for Azure Cosmos DB.
True/False: Autoscale throughput cannot be enabled for existing databases and containers in Azure Cosmos DB.
- True
- False
Answer: False
Explanation: Autoscale throughput can be enabled for existing databases and containers by using Azure CLI or PowerShell.
What should be the minimum azure cosmos db throughput while using autoscale?
- A. 4000 RU/s
- B. 5000 RU/s
- C. 1000 RU/s
- D. 2000 RU/s
Answer: A
Explanation: The minimum throughput with autoscale in Azure Cosmos DB is 4000 RU/s.
True/False: PowerShell and Azure CLI are functionally identical and can be used interchangeably to manage Azure Cosmos DB.
- True
- False
Answer: False
Explanation: While both PowerShell and Azure CLI can be used to manage Azure resources, they have different syntax and may offer different functionalities.
Which of these are valid commands to migrate between standard and autoscale throughput using Azure CLI?
- A. az cosmosdb throughput create
- B. az cosmosdb throughput update
- C. az cosmosdb sql container throughput migrate
- D. Both A and B
Answer: D
Explanation: The commands to manage throughput in Azure Cosmos DB using Azure CLI are ‘az cosmosdb throughput create’ and ‘az cosmosdb throughput update’.
True/False: You can enable autoscale throughput when creating a new database or container in Azure Cosmos DB.
- True
- False
Answer: True
Explanation: Autoscale throughput can be enabled upon creation of a new database or container through Azure CLI or PowerShell.
In Azure Cosmos DB, when should you consider using autoscale throughput?
- A. When your workload is predictable
- B. When your workload is ever-changing
- C. When you always need high throughput
- D. None of the above
Answer: B
Explanation: In Azure Cosmos DB, you should consider using autoscale throughput if your workload changes frequently, as it dynamically adjusts to match your workload requirements.
True/False: Migration from standard to autoscale throughput can result in increased cost if not managed properly.
- True
- False
Answer: True
Explanation: Autoscale throughput provides high performance when needed, but it can also incur more cost than standard throughput if used continuously and not managed appropriately.
Interview Questions
What is the command to create a Cosmos DB account with standard provisioned throughput using Azure CLI?
The command is:
az cosmosdb create --name MyCosmosDBAccount --resource-group MyResourceGroup --kind GlobalDocumentDB --default-consistency-level "Session"
.
How can you use PowerShell to change the throughput of a Cosmos DB container from standard throughput to autoscale throughput?
To do this, use the "Update-AzCosmosDBSqlContainerThroughput" command with the "-AutoscaleMaxThroughput" parameter to set the maximum autoscale throughput.
What is the Azure CLI command to update a cosmos DB account to autoscale?
The command to update a Cosmos DB account to autoscale using Azure CLI is:
az cosmosdb update --name$accountName --resource-group $resourceGroupName --enable-automatic-failover true
.
What command is used in PowerShell to migrate from autoscale to standard throughput?
The PowerShell command is:
Update-AzCosmosDBSqlContainerThroughput -ResourceGroupName "MyResourceGroup" -DatabaseAccountName "MyCosmosDBAccount" -DatabaseName "MyDatabase" -Name "MyContainer" -Throughput 400
.
Can you migrate from standard throughput to autoscale throughput directly via PowerShell or Azure CLI?
Yes, both PowerShell and Azure CLI can be used to migrate from standard throughput to autoscale throughput directly.
How to check the current throughput configuration of a Cosmos DB container using Azure CLI?
Use the command
az cosmosdb sql container show --name MyContainer --db-name MyDatabase --account-name MyCosmosDBAccount --resource-group MyResourceGroup --query resource.throughput
.
How to monitor and control the resources of your Cosmos DB account using PowerShell commands?
The "Get-AzCosmosDBSqlContainerThroughput" command can be used to monitor, and the "Update-AzCosmosDBSqlContainerThroughput" command to control the resources.
What is the maximum throughput you can set for autoscale in Cosmos DB using Azure CLI?
The maximum autoscale throughput you can set in Cosmos DB using Azure CLI is 100000 RU/s.
Can autoscale throughput be disabled using Azure CLI?
Yes, you can disable autoscale throughput by updating the throughput settings back to manual throughput with Azure CLI.
How can we enable autoscale in an existing Cosmos DB container using PowerShell?
To enable autoscale in an existing container, you can use the Update-AzCosmosDBSqlContainerThroughput command with the -AutoscaleMaxThroughput parameter.
Is there any additional cost when migrating to and from autoscale throughput?
No, there is no additional cost for migrating to and from autoscale throughput.
What is the command to delete a Cosmos DB database using PowerShell?
Remove-AzCosmosDBSqlDatabase -ResourceGroupName "MyResourceGroup" -DatabaseAccountName "MyCosmosDBAccount" -Name "MyDatabase"
is the command to remove a Cosmos DB database.
Can the 'provisioned throughput' setting of a Cosmos DB collection be altered after it has been initially set using Azure CLI?
Yes, the provisioned throughput of a Cosmos DB collection can be altered after setting it initially using the "az cosmosdb collection update" command.
How can you preview changes before migrating to autoscale throughput using PowerShell or Azure CLI?
There is no built-in function in PowerShell or Azure CLI that enables you to preview changes before migrating to autoscale throughput.
What is the role of Azure CLI or PowerShell while working with Cosmos DB throughput?
Azure CLI and PowerShell provide commands to manage throughput settings for a Cosmos DB account, including creation, update, and deletion of throughput settings, as well as migrating between standard and autoscale throughput.