Modifying the throughput of the Azure Cosmos DB container through the Java SDK

When using Azure Cosmosdb, when you enable a new collection, table, or graphic, you specify the number of requests per second (RU) that you want to keep.Azure Cosmos DB allocates physical partitions according to the throughput of the allocation, and splits/balances the growing data in the partition.

Because the user needs to pay according to the reserved throughput, no matter how much throughput is actually used.As the application’s load, data, and usage patterns change, the actual throughput may vary, so many users want to be able to modify the throughput.The current Azure portal offers modified options, as well as programmatic (. NET), please refer to the official documentation for details.

But there are still many customers who are consulting about how to use the Java SDK to modify throughput, and since the official documentation does not mention this part, we will show you how to implement it through the Java SDK in this article.


  1. A valid Azure subscription
  2. A valid Azure Cosmosdb account
  3. Java IDE (optional)


 <groupId> </groupId>
 <artifactId> Azure-documentdb </artifactId>
 <version> 1.15.0 </version>

code example

public static void Main ([] args) {
 int newthroughput = 2000; Here is the throughput to modify
 String databaseName = "dbtest";//The database name
 String CollectionName = "Colltest";
 String Dblink = String.Format ("/dbs/%s", databaseName);
 String endpoint = "";//Service Endpoint
 String key = "6YqefBkV ... nqba== ";//cosmosdb key
 Documentclient client = new Documentclient (endpoint, key, New Connectionpolicy (), consistencylevel.session);
 if (client!=null) {
 try {
  String query = String.Format ("SELECT * from ROOT r WHERE = '%s '", CollectionName);
  List <DocumentCollection> DCS = client.querycollections (dblink, query, NULL). Getqueryiterable (). ToList ();
  Get the Selflink of the corresponding container
  String collectionlink = dcs.get (0). Getselflink ();
  Offer v1offer = null;
  List <Offer> offers = Client.readoffers (null). Getqueryiterable (). ToList ();

  Get the original offer
  for (offer O:offers) {
   if (O.getresourcelink (). Equals (Collectionlink)) {
   V1offer = O;
  Set new throughput
  OfferV2 V2offer = new OfferV2 (v1offer);
  V2offer.setofferthroughput (Newthroughput);
  Client.replaceoffer (V2offer);
  } catch (Exception e) {
   E.printstacktrace ();
  }finally {
   Client.close ();

The following screenshot shows the throughput after the successful modification:


This article demonstrates how to use the Azure Java SDK to modify the throughput of the Azure Cosmosdb container.If you have any questions, please contact us by

Leave a Reply

Your email address will not be published. Required fields are marked *