All skills
microsoft avatar

/azure-resource-manager-cosmosdb-dotnet

@073741f
by microsoftmicrosoft/skills3.1k stars
351

Azure Resource Manager SDK for Cosmos DB in .NET. Use for MANAGEMENT PLANE operations: creating/managing Cosmos DB accounts, databases, containers, throughput settings, and RBAC via Azure Resource Manager. NOT for data plane operations (CRUD on documents) - use Microsoft.Azure.Cosmos for that. Triggers: "Cosmos DB account", "create Cosmos account", "manage Cosmos resources", "ARM Cosmos", "CosmosDBAccountResource", "provision Cosmos DB".

Use this Skill: https://skilld.dev/gh/microsoft/skills/azure-resource-manager-cosmosdb-dotnet

This session only. Nothing lands on disk.

referencesthroughput.md

≈2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Throughput Configuration

Patterns for configuring and managing throughput (RU/s) for Cosmos DB resources.

Throughput Concepts

Type Description Min RU/s Use Case
Manual Fixed provisioned throughput 400 Predictable workloads
Autoscale Scales between 10% and max 1000 (max) Variable workloads
Serverless Pay per request N/A Dev/test, sporadic traffic

Database-Level Throughput (Shared)

Throughput shared across all containers in the database.

Set Manual Throughput

using Azure.ResourceManager.CosmosDB;
using Azure.ResourceManager.CosmosDB.Models;

// Create database with shared throughput
var databaseData = new CosmosDBSqlDatabaseCreateOrUpdateContent(
    new CosmosDBSqlDatabaseResourceInfo("my-database"))
{
    Options = new CosmosDBCreateUpdateConfig
    {
        Throughput = 400
    }
};

await databaseCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-database",
    databaseData);

Set Autoscale Throughput

var databaseData = new CosmosDBSqlDatabaseCreateOrUpdateContent(
    new CosmosDBSqlDatabaseResourceInfo("my-database"))
{
    Options = new CosmosDBCreateUpdateConfig
    {
        AutoscaleSettings = new AutoscaleSettings
        {
            MaxThroughput = 4000  // Scales between 400-4000 RU/s
        }
    }
};

Update Database Throughput

var database = await account.GetCosmosDBSqlDatabaseAsync("my-database");

// Update to manual throughput
var throughputData = new ThroughputSettingsUpdateData(
    new ThroughputSettingsResourceInfo
    {
        Throughput = 800
    });

await database.Value.CreateOrUpdateCosmosDBSqlDatabaseThroughputAsync(
    WaitUntil.Completed,
    throughputData);

Get Database Throughput

var database = await account.GetCosmosDBSqlDatabaseAsync("my-database");
var throughput = await database.Value.GetCosmosDBSqlDatabaseThroughputAsync();

Console.WriteLine($"Throughput: {throughput.Value.Data.Resource.Throughput}");
Console.WriteLine($"Min Throughput: {throughput.Value.Data.Resource.MinimumThroughput}");

if (throughput.Value.Data.Resource.AutoscaleSettings != null)
{
    Console.WriteLine($"Autoscale Max: {throughput.Value.Data.Resource.AutoscaleSettings.MaxThroughput}");
}

Container-Level Throughput (Dedicated)

Throughput dedicated to a single container.

Set Manual Throughput

var containerData = new CosmosDBSqlContainerCreateOrUpdateContent(
    new CosmosDBSqlContainerResourceInfo("my-container")
    {
        PartitionKey = new CosmosDBContainerPartitionKey
        {
            Paths = { "/partitionKey" },
            Kind = CosmosDBPartitionKind.Hash
        }
    })
{
    Options = new CosmosDBCreateUpdateConfig
    {
        Throughput = 1000
    }
};

await containerCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-container",
    containerData);

Set Autoscale Throughput

var containerData = new CosmosDBSqlContainerCreateOrUpdateContent(
    new CosmosDBSqlContainerResourceInfo("my-container")
    {
        PartitionKey = new CosmosDBContainerPartitionKey
        {
            Paths = { "/partitionKey" },
            Kind = CosmosDBPartitionKind.Hash
        }
    })
{
    Options = new CosmosDBCreateUpdateConfig
    {
        AutoscaleSettings = new AutoscaleSettings
        {
            MaxThroughput = 10000  // Scales between 1000-10000 RU/s
        }
    }
};

Update Container Throughput

var container = await database.GetCosmosDBSqlContainerAsync("my-container");

// Update to new throughput
var throughputData = new ThroughputSettingsUpdateData(
    new ThroughputSettingsResourceInfo
    {
        Throughput = 2000
    });

await container.Value.CreateOrUpdateCosmosDBSqlContainerThroughputAsync(
    WaitUntil.Completed,
    throughputData);

Get Container Throughput

var container = await database.GetCosmosDBSqlContainerAsync("my-container");
var throughput = await container.Value.GetCosmosDBSqlContainerThroughputAsync();

Console.WriteLine($"Throughput: {throughput.Value.Data.Resource.Throughput}");

Migrate Between Throughput Modes

Manual to Autoscale

var container = await database.GetCosmosDBSqlContainerAsync("my-container");

// Migrate to autoscale
await container.Value.MigrateCosmosDBSqlContainerToAutoscaleAsync(WaitUntil.Completed);

Autoscale to Manual

var container = await database.GetCosmosDBSqlContainerAsync("my-container");

// Migrate to manual (uses current autoscale throughput as manual value)
await container.Value.MigrateCosmosDBSqlContainerToManualThroughputAsync(WaitUntil.Completed);

Database-Level Migration

var database = await account.GetCosmosDBSqlDatabaseAsync("my-database");

// To autoscale
await database.Value.MigrateCosmosDBSqlDatabaseToAutoscaleAsync(WaitUntil.Completed);

// To manual
await database.Value.MigrateCosmosDBSqlDatabaseToManualThroughputAsync(WaitUntil.Completed);

Throughput Calculation Guidelines

Estimating RU/s

Operation Approximate RU Cost
Point read (1KB doc by ID + partition key) 1 RU
Write (1KB doc) 5-10 RU
Query (simple, single partition) 2-5 RU
Query (complex, cross-partition) 10-100+ RU

Sizing Formula

Required RU/s = (Reads/sec × RU per read) + (Writes/sec × RU per write) + (Queries/sec × RU per query)

Autoscale Tiers

Max Throughput Min Throughput (10%) Monthly Cost Estimate
1,000 RU/s 100 RU/s ~$58
4,000 RU/s 400 RU/s ~$233
10,000 RU/s 1,000 RU/s ~$584
100,000 RU/s 10,000 RU/s ~$5,840

Best Practices

  1. Start with autoscale for new workloads until you understand traffic patterns
  2. Use database-level throughput when containers have similar access patterns
  3. Use container-level throughput for containers with distinct performance needs
  4. Monitor RU consumption via Azure Monitor to right-size throughput
  5. Set alerts for 429 (rate limiting) errors
  6. Consider serverless for dev/test or sporadic workloads

Error Handling

try
{
    await container.Value.CreateOrUpdateCosmosDBSqlContainerThroughputAsync(
        WaitUntil.Completed,
        throughputData);
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
    // Common: throughput below minimum or invalid autoscale settings
    Console.WriteLine($"Invalid throughput configuration: {ex.Message}");
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
    // Conflict: migration already in progress
    Console.WriteLine($"Throughput migration in progress: {ex.Message}");
}

Throughput for Other APIs

Cassandra Keyspace

var keyspaceData = new CassandraKeyspaceCreateOrUpdateContent(
    new CassandraKeyspaceResourceInfo("my-keyspace"))
{
    Options = new CosmosDBCreateUpdateConfig
    {
        Throughput = 400
    }
};

MongoDB Database

var mongoDbData = new MongoDBDatabaseCreateOrUpdateContent(
    new MongoDBDatabaseResourceInfo("my-mongodb"))
{
    Options = new CosmosDBCreateUpdateConfig
    {
        AutoscaleSettings = new AutoscaleSettings
        {
            MaxThroughput = 4000
        }
    }
};

Gremlin Database

var gremlinData = new GremlinDatabaseCreateOrUpdateContent(
    new GremlinDatabaseResourceInfo("my-gremlin"))
{
    Options = new CosmosDBCreateUpdateConfig
    {
        Throughput = 400
    }
};

Table API

var tableData = new CosmosDBTableCreateOrUpdateContent(
    new CosmosDBTableResourceInfo("my-table"))
{
    Options = new CosmosDBCreateUpdateConfig
    {
        Throughput = 400
    }
};

Source: SKILL.md on GitHub

1 warning15d4 checks · Risk SAFE
  • Gen Agent Trust Hub15d

    This skill provides comprehensive documentation and code patterns for the official Azure Resource Manager SDK for Cosmos DB in .NET. It describes management plane operations such as resource provisioning and credential retrieval, which are standard for administrative cloud tasks. The skill follows established security practices, including the use of DefaultAzureCredential and the avoidance of hardcoded secrets.

  • Socket15d

    No alerts

  • Snyk15d

    Risk: LOW · No issues

  • Runlayer7mo

    5/5 files flagged

Signed by skilld at 073741f. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 5 months ago
Other metadata
metadata
{
  "author": "Microsoft",
  "version": "1.0.0",
  "package": "Azure.ResourceManager.CosmosDB"
}

README badge

README badge for microsoft/skills/azure-resource-manager-cosmosdb-dotnet