Azure Cosmos DB is a multi-model, globally distributed database service designed to enable developers to build scalable, high-performance applications. One of its key features is the ability to scale throughput based on specific needs. You can configure the provisioned throughput on an Azure Cosmos container or database by using Azure portal. By provisioning the throughput at different scopes, you can optimize your rate to application requirements, performance, and cost.
Understanding Throughput
Azure Cosmos DB charges for storage and for the throughput your app consumes. Throughput is measured in Request Units (RU) per second. Cosmos DB guarantees the throughput you provision on a single-digit millisecond latency at the 99th percentile.
There are two types of throughput provisioning modes:
- Manual Throughput Provisioning: You choose the specific amount of throughput provisioned at a given time.
- Autoscale Throughput Provisioning: Azure Cosmos DB can automatically scale the maximum RU/s (Request Units per second) based on the usage within the set time period.
You can configure both manual and autoscale throughput on the Azure portal.
Manual Throughput Provisioning
To configure manual throughput provisioning using the Azure portal:
- Navigate to your Azure Cosmos DB account on the Azure portal.
- In the left-hand menu, select ‘Data Explorer’.
- Choose a database and a container, then select ‘Scale & Settings’.
- In the ‘Scale & Settings’ blade, under ‘Provisioned throughput’, choose ‘Manual’.
- Specify the amount of RU/s you wish to set based on your application requirements.
Manual provisioning is typically recommended when there is a predictable workload and a set amount of throughput is needed continually.
Autoscale Throughput Provisioning
To configure autoscale throughput provisioning using the Azure portal:
- Go to your Azure Cosmos DB account on the Azure portal.
- In the left-hand menu, select ‘Data Explorer’.
- Choose a database and a container, then select ‘Scale & Settings’.
- In the ‘Scale & Settings’ blade, under ‘Provisioned throughput’, choose ‘Autoscale’.
- Set the ‘Max RU/s’ field to the desired maximum amount of throughput that can be provisioned.
Autoscale provisioning is highly recommended when usage patterns are unpredictable or when usage changes significantly during peak and off-peak hours. With autoscale, Azure Cosmos DB can automatically scale the throughput in response to incoming traffic, while ensuring you only pay for the throughput you use.
To sum up, configuring throughput in Azure Cosmos DB involves determining the right provisioned throughput mode – manual or autoscale – based on the specific needs of your application. Doing so effectively can significantly optimize the cost-effectiveness and performance of your Azure Cosmos DB operations.
Practice Test
[True/False] Azure Cosmos DB provides two models for throughput provision, which are manual and autoscale.
- Answer: True
Explanation: Azure Cosmos DB offers two types of throughput models, Manual and Autoscale. Manual throughput allows you to manually set your RU/s and Autoscale throughput automatically scales RU/s based on the workload.
[Single Select] Which of the following is NOT a step in configuring throughput for Azure Cosmos DB through Azure portal?
- A. Choosing a throughput model
- B. Setting up the partition key
- C. Specifying the throughput value
- D. Understanding request units
- Answer: B. Setting up the partition key
Explanation: The partition key is used for distributing the data, not for configuring the throughput. Steps in configuring throughput in Azure Cosmos DB include choosing the throughput model, specifying the value, and understanding request units.
[True/False] Azure Cosmos DB guarantees low latency at the 99th percentile to any scale.
- Answer: True
Explanation: Azure Cosmos DB provides a latency guarantee at the 99th percentile regardless of the scale. It guarantees less than 10-ms latencies on read operations and less than 15-ms latencies on write operations.
[Single Select] What unit is throughput in Azure Cosmos DB measured in?
- A. Gigabytes
- B. Terabytes
- C. Request Units per second (RU/s)
- D. Petabytes
- Answer: C. Request Units per second (RU/s)
Explanation: In Azure Cosmos DB, throughput is measured in Request Units per second (RU/s). RU/s is a rate-based currency which abstracts the system resources such as CPU, IOPS, and memory that are required to perform the database operations.
[Multiple Select] Which are the two types of operations that Azure Cosmos DB offers to perform throughput provisioning?
- A. Read
- B. Write
- C. Delete
- D. Update
- Answer: B. Write, D. Update
Explanation: Azure Cosmos DB offers two types of operations to perform throughput provisioning: Write and Update. Read and Delete operations do not directly affect the provisioning of throughput.
[True/False] One can monitor the throughput utilization of Azure Cosmos DB using Azure Monitor.
- Answer: True
Explanation: Azure Monitor allows you to monitor the throughput utilization of Azure Cosmos DB. You can set alerts based on specific metrics or log search queries.
[Single Select] What factor determines the total throughput that a partition in Azure Cosmos DB can serve?
- A. Partition key
- B. RU/s assigned to the container
- C. Data stored in the partition
- D. None of the above
- Answer: B. RU/s assigned to the container
Explanation: The total throughput that a partition can serve is determined by the number of RU/s assigned to the container. An individual partition can serve up to the total throughput that’s been provisioned to the container.
[Multiple Select] Which of the following does Azure Cosmos DB require to calculate request unit charge?
- A. CPU
- B. Memory
- C. IOPS
- D. Network
- Answer: A. CPU, B. Memory, C. IOPS, D. Network
Explanation: Azure Cosmos DB uses all of these resources (CPU, Memory, IOPS, and Network) to calculate the request unit charge for an operation.
[True/False] Azure Cosmos DB allows you to increase the provisioned throughput of a container at any time without any downtime.
- Answer: True
Explanation: You can increase the provisioned throughput of a container in Azure Cosmos DB at any time without downtime. However, decreasing the throughput might require scheduling.
[Single Select] Which of the following settings allows Azure Cosmos DB to scale the throughput automatically?
- A. Manual Throughput
- B. Partition Key
- C. Autoscale Throughput
- D. Fixed Throughput
- Answer: C. Autoscale Throughput
Explanation: Autoscale throughput setting of Azure Cosmos DB allows the throughput to scale automatically based on the usage patterns and actual resource demand. This can help in maintaining high utilization and performance while reducing costs.
Interview Questions
What is the primary purpose of configuring throughput in Azure Cosmos DB?
Configuring throughput in Azure Cosmos DB helps manage the amount of data that can be processed or handled by it in a specific period. It ensures that the database can handle usage spikes and heavy loads without any performance lag, enabling better application responsiveness and user experience.
How is throughput measured in Azure Cosmos DB?
Throughput in Azure Cosmos DB is measured in Request Units (RU/s), which represents the cost of both read and write operations.
What are the two types of throughput that can be configured in Azure Cosmos DB?
The two types of throughput that can be configured in Azure Cosmos DB are Dedicated throughput and Shared throughput.
What is Dedicated throughput in Azure Cosmos DB?
Dedicated throughput is a type of throughput that is specifically associated with a single Azure Cosmos container or a database. It reserves the set amount of RUs at all times solely for this entity.
What is Shared throughput in Azure Cosmos DB?
Shared throughput is a type of throughput that is allocated at the database level and shared across all the containers in that database.
How do you configure Dedicated throughput in Azure Cosmos DB using the Azure portal?
Dedicated throughput can be configured using Azure portal by following these steps: Go to the Azure portal -> Navigate to Azure Cosmos DB account -> Click on ‘New Container’ -> In the ‘Throughput’ section, add the number of RUs you want to be reserved for this container.
How do you configure Shared throughput in Azure Cosmos DB using the Azure portal?
Shared throughput can be configured by following these steps: Go to the Azure portal -> Navigate to your Cosmos DB account -> Click on ‘New Database’ -> In the ‘Database id’ section, enter the name -> In the ‘Throughput’ section, enter the number of RUs you want to allocate.
What is Autoscale throughput in Azure Cosmos DB?
Autoscale throughput is a feature of Azure Cosmos DB that automatically scales the throughput of your database depending on your usage up to a maximum limit that you specify.
How is Autoscale throughput configured in the Azure portal?
Autoscale throughput can be set by choosing the ‘Autoscale’ option in the ‘throughput’ section when creating a new Azure Cosmos container or database.
How can you modify dedicated throughput for an existing container in Azure Cosmos DB via Azure portal?
To modify dedicated throughput for an existing container, navigate to your Azure Cosmos DB account -> Click on ‘Data Explorer’ -> Under ‘Data Explorer’, click on the container you want to modify -> Click on ‘Scale & Settings’ -> Under the ‘Scale’ tab, update the throughput.
How does Azure Cosmos DB charge for throughput?
Azure Cosmos DB charges for throughput based on the number of RU/s reserved or consumed. The charges depend on whether you’re using manual or autoscale throughput, and how long the throughput is provisioned.
What is the minimum provisioned throughput for an Azure Cosmos DB container?
The minimum provisioned throughput for an Azure Cosmos DB container is 400 RU/s.
What could be a potential impact of not properly setting the throughput in Azure Cosmos DB?
If the throughput is not set properly, the application may experience throttling, which will lead to higher latencies and could affect the performance and user experience of the application.
Can you change the throughput setting in Azure Cosmos DB once it is set?
Yes, the throughput setting in Azure Cosmos DB can be increased or decreased at any time based on the need via the Azure portal.
Is there a maximum limit to the throughput that can be set for a container in Azure Cosmos DB?
Yes, the maximum limit for manual throughput for a container in Azure Cosmos DB is 100,000 RU/s. For autoscale throughput, it’s 400,000 RU/s.