Cosmos db high RUs for writes - azure-cosmosdb

In cosmos Db hope are RUs increased for writes? To my understanding, the replicas are only for reads but only one node is used for writes. What is the model for writes distribution in cosmos db when the load is high?

In Cosmos DB, data is stored by it's partition key. In high write volume scenarios a key to success is ensuring your partition key has high enough cardinality to give you enough throughput to meet your performance needs for a given amount of RU/s.
Beyond scalability in a single geographic region though, using multi-master is what provides geographic scale for writes or lower latency.

Related

Does the concept of "hot partition" in Cosmos DB only applies to provisioned throughput?

We all know that if the workload running on a logical partition consumes more than the throughput that was allocated to the underlying physical partition, it's possible that operations become rate-limited. This occurs when the workload is not evenly distributed on the several (logical) partitions, that is usually when a wrong partition key is selected for the document/container at creation time.
This performance problem is referred to as "hot partition".
But what if we provision the database as 'serverless', which is the mode where throughput is dynamically allocated, (not provisioned).
Does the issue still persist? If yes, why?
Serverless isn't terribly helpful here and in workloads with sustained requests would be prohibitively expensive.
If you have persistent hot partitions, you may want to look into this feature here which is in preview. https://learn.microsoft.com/azure/cosmos-db/nosql/distribute-throughput-across-partitions

CosmosDB Throughput Database Level vs Container Level

We are using com.azure.cosmos.spark:azure-cosmos-spark library from Databricks to bulk write into CosmosDB Containers.
Currently throughput's are set on container (5 containers) level (ex: 10000 RUs). Sometime couple of write operations on a given container throttle's as RUs consumed are 100%, but after re-tries does finish. Load into the containers are in Parallel.
What if we change throughput to database level (ex: 50000 RUs - equally distributed among the containers) and execute write process in sequence. Will container into which data is being written will have access to 50000 RUs or 10000 RUs?
Azure Cosmos containers that are configured in autopilot mode have the following benefits:
Simple – There is no need to invest time in manually scaling throughput or writing code to automatically scale throughput
Reliable – Autopilot scaling is fully managed by Microsoft. There is no disruption to client connections, applications, or impact to SLA’s.
No rate-limiting of operations – Rate limiting (throttled requests) will not happen if throughput consumed is within the max throughput chosen for autopilot mode.
By default, the distribution will be done according to the RU's when we are using Container level throughput.
If we need to manually provide assignment, it can be done to handle total 50K RU's, but it is not cost-effective and also not a great approach to follow.
Autopilot mode pricing:
- Single-region write accounts- Cost for provisioned RU’s is 50% higher
- Multi-region write accounts- Cost for provisioned RU’s is identical to cost of manually provisioned throughput RU’s

Cosmos DB replication cost

I want to set up a Cosmos DB account with a single write region and multiple read regions. I also want to use autoscaling RU provisioning, so I only pay for what I use (above the floor).
Now if there is zero load I expect the RU cost to be 400 RU multiplied by region count (since 400 RU is the cost floor for autoscaling).
If I perform a write charged at a specific RU cost that I can see in the response, is that only counted once (against the write region), and then the replication only incurs extra costs for egress and storage? Or will the RU cost be multiplied by the region count behind the scenes?
Similarly for reads, is that RU cost only counted once (against the read region), or is it multiplied by the region count?
Under Metrics (Classic), I see that Avg Throughput/s (RU/s) only changes in the write region when writing, but I'm not sure if this reflects the actual charge.
I felt that this was not answered clearly in: In Cosmos DB, how does geo-replication impact RU consumption of writes?
The throughput that you have configured for various Azure Cosmos
databases and containers will be reserved in each of the Azure regions
associated with your Azure Cosmos database account. If the sum of
provisioned throughput (RU/sec) configured across all the databases
and containers within your Azure Cosmos database account (provisioned
per hour) is T and the number of Azure regions associated with your
database account is N, then the total provisioned throughput for a
given hour, for your Azure Cosmos database account is equal to T x N
RU/sec.
Provisioned throughput (single write region) costs $0.008/hour per 100 RU/sec and provisioned throughput with multiple writable regions (multi-region writes config) costs $0.016/per hour per 100 RU/sec.
Source: Understand your Azure Cosmos DB bill

Why does Cosmos DB return 429 for a portion of requests despite not exceeding my manual set throughput

My Cosmos DB is using Shared Throughput across several containers. I have manually scaled up my Cosmos DB to 70,000 RU/s and I am currently running a large number of requests.
Looking in azure I can see that a portion of my requests are being throttled (returning 429).
To give an idea of numbers around 25k requests return 200 and around 5k requests return 429.
When I follow the warning in the azure portal that says my collection is exceeding provisioned throughput it shows the average throughput is 6.78k RU/s.
I don't understand why when I have 70,000 RU/s that my requests are being throttled when the average throughput is supposedly only 6,780 RU/s.
No other containers are being read or written to, all these requests are made against just one container.
As all these requests are to run a stored procedure they all have a Partition key supplied.
The most likely reason is you have a hot partition that is reaching its allocated throughput before the other partitions are.
For a horizontally scalable database, throughput is allocated across physical partitions (computers) and data is partitioned using a partition key that basically acts as an address to route it to a specific computer to be stored.
Assume I have a collection with three partitions 1, 2, 3 and 30K RU/s. Each one of those will get 10K RU/s allocated to it. If I then run an operation that does a ton of operations on partition 2 and consumes all of it's 10K I'm going to get rate limited (429) even I don't touch partition 1 or 3.
To avoid this you need to pick a partition key that BOTH distributes data as evenly as possible during writes and ideally can also be used to answer queries within one or a small number (bounded) number of partitions, trying to avoid "fan out" queries where queries have to hit every partition.
Now for small collections that only reside on a single physical partition none of this matters because your data is all on a single physical partition. However, as the collection grows larger this causes issues which will prevent the database from scaling fully.
You can learn more here

How DynamoDB provisions throughput of reads independently of writes

Amazon DynamoDB allows the customer to provision the throughput of reads and writes independently. I have read the Amazon Dynamo paper about the system that preceded DynamoDB and read about how Cassandra and Riak implemented these ideas.
I understand how it is possible to increase the throughput of these systems by adding nodes to the cluster which then divides the hash keyspace of tables across more nodes, thereby allowing greater throughput as long as access is relatively random across hash keys. But in systems like Cassandra and Riak this adds throughput to both reads and writes at the same time.
How is DynamoDB architected differently that they are able to scale reads and write independently? Or are they not and Amazon is just charging for them independently even though they essentially have to allocate enough nodes to cover the greater of the two?
You are correct that adding nodes to a cluster should increase the amount of available throughput but that would be on a cluster basis, not a table basis. The DynamoDB cluster is a shared resource across many tables across many accounts. It's like an EC2 node: you are paying for a virtual machine but that virtual machine is hosted on a real machine that is shared among several EC2 virtual machines and depending on the instance type, you get a certain amount of memory, CPU, network IO, etc.
What you are paying for when you pay for throughput is IO and they can be throttled independently. Paying for more throughput does not cause Amazon to partition your table on more nodes. The only thing that cause a table to be partitioned more is if the size of your table grows to the point where more partitions are needed to store the data for your table. The maximum size of the partition, from what I have gathered talking to DynamoDB engineers, is based on the size of the SSDs of the nodes in the cluster.
The trick with provisioned throughput is that it is divided among the partitions. So if you have a hot partition, you could get throttling and ProvisionedThroughputExceededExceptions even if your total requests aren't exceeding the total read or write throughput. This is contrary to what your question ask. You would expect that if your table is divided among more partitions/nodes, you'd get more throughput but in reality it is the opposite unless you scale your throughput with the size of your table.

Resources