Concepts of Cosmos DB: Throughput
Tags: azure, cosmosdb, database
Published: 2024-02-12 09:31:47

In Azure Cosmos DB, **throughput** is an important concept that defines the capacity and performance of your database operations. It helps you mange the RUs and, essentially, it determines how much data can be read from or written to your Cosmos DB account within a given unit of time, typically measured in requests per second (RUs).
Before continuing reading this article, I suggest revisiting [Concepts of Cosmos DB: Request Unit](https://dev.to/mariustechie/concepts-of-cosmos-db-request-unit-545l)

Cosmos DB offers different models for managing throughput.

## Provisioned throughput
###Standard
You can set a certain amount of RU and it can be configured at the database or container level but you can combine the two models. 
Provisioned throughput is great for databases that receive **sustained traffic**. For example, if you decide to configure the database at 5000 RU/s, it is guaranteed that this amount will be available,  but once the RU's are consumed, future requests will be rate limited because by default, it is required a manual scaling to acquire more RU's. 
###Autoscale
This is when **autoscaling** can be used. You can specify a maximum RU throughout amount and Cosmos DB will ensure that the data will be available. The minimum throughout will be calculated as 10% of the maximum. So, following the above example, if you set the maximum to 5000 RU/s, Azure Cosmos DB will automatically scale your provisioned throughput up and down to accommodate the requirements of the application within this range (at least 500 RU/s - maximum 5000 RU/s). This applies best when the application have **unpredictable traffic** patterns.

Next, we will see how can we accommodate to a type of workload that have times when it will be not used at all (unused capacity).

## Serverless throughput
When choosing serverless we will pay only for the RU's that are consumed and the used storage.
This can be view as a pure consumption model. It applies to development/testing activities or if you just want to get starting with Azure Cosmos DB. Taking into the consideration that the cost become less predictable you can monitor the consumption via a chart.

Despite these options, in some situations, it may be unclear whether provisioned throughput or serverless should be chosen for a given workload. In this case, Microsoft recommends us to estimate the overall expected consumption, or the total number of RUs we may consume over a month.

By effectively managing throughput in Cosmos DB, you can ensure that your applications meet performance requirements while also optimizing costs based on actual usage patterns.

Photo by <a href="https://unsplash.com/@shubzweb3?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Shubham's Web3</a> on <a href="https://unsplash.com/photos/a-group-of-purple-cubes-hanging-from-a-metal-bar-lY0-Y3kX5ps?utm_content=creditCopyText&utm_medium=referral&utm_source=unsplash">Unsplash</a>

P.S.

I would love hearing from our tech-savvy community! Have insights, tips, or burning questions? Don't keep them to yourself! Drop your thoughts in the comments below. Let's spark a conversation and learn from each other's experiences in the dynamic world of Azure migration