Generated banner for Cosmosdb Best Practices
Generated logo for Cosmosdb Best Practices

Cosmosdb Best Practices

ClineOfficialCreated by cosmosdb-agent-kitDistributed by Cline

  • Skill
  • Guidelines
  • Software development
  • MIT
  • No issues found

From the author

Azure Cosmos DB performance optimization and best practices guidelines for NoSQL, partitioning, queries, SDK usage, and vector search. Use when writing, reviewing, or refactoring code that interacts with Azure Cosmos DB, designing data models, optimizing queries, or implementing high-performance database operations.
— the description by cosmosdb-agent-kit

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured set of 73+ guidelines for working with Azure Cosmos DB. It covers essential topics including data modeling, partition key design, query optimization, SDK usage, indexing, throughput scaling, global distribution, monitoring, design patterns, and vector search. The content is organized into modular rule files to assist developers in writing, reviewing, and refactoring code that interacts with the database.

What it does

  • Provides specific rules for designing efficient data models and choosing partition keys.
  • Offers guidance on optimizing queries and implementing SDK patterns.
  • Details strategies for indexing, throughput management, and global distribution.
  • Includes best practices for implementing vector search and RAG patterns.
  • Supplies diagnostic and monitoring recommendations for database operations.
  • Organizes content into categorized rule files for targeted retrieval.

When to use it

  • When designing data models or selecting partition keys for Cosmos DB.
  • When writing or refactoring application code that uses the Cosmos DB SDK.
  • When optimizing query performance or indexing strategies.
  • When configuring global distribution, throughput, or scaling settings.
  • When implementing vector search or advanced design patterns.

Advantages

  • Modular structure allows for loading only relevant rules for specific tasks.
  • Covers a wide range of operational and architectural concerns.
  • Provides clear examples of incorrect and correct implementation patterns.
  • Prioritizes rules by impact to guide development decisions.

Usage examples

“How should I choose a partition key for my Cosmos DB container?”
The agent will retrieve rules from the partition- prefix to explain high-cardinality, write distribution, and query alignment.
“What are the best practices for using the Cosmos DB SDK?”
The agent will load rules from the sdk- prefix to provide guidance on singleton client usage, async APIs, and retry logic.
“How do I optimize my data model for read-heavy workloads?”
The agent will reference model- prefixed rules to explain denormalization and embedding strategies.
“What should I consider when implementing vector search in Cosmos DB?”
The agent will access vector- prefixed rules to explain embedding policies, index types, and similarity search functions.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/cline/cosmosdb-best-practices/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip cosmosdb-best-practices.zip -d .agents/skills

Documentation by cosmosdb-agent-kit

Azure Cosmos DB Best Practices

Comprehensive performance optimization guide for Azure Cosmos DB applications, containing 73+ rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.

73 individual rule files are in the rules/ directory, one file per rule, synced from the AzureCosmosDB/cosmosdb-agent-kit. Load only the relevant rule file(s) when answering a question — do NOT load all files at once.

When to Apply

Reference these guidelines when:

  • Designing data models for Cosmos DB

  • Choosing partition keys

  • Writing or optimizing queries

  • Implementing SDK patterns

  • Reviewing code for performance issues

  • Configuring throughput and scaling

  • Building globally distributed applications

  • Implementing vector search and RAG patterns

Rule Index

Rules are grouped by category prefix. For a given question, load files matching the relevant prefix (e.g., model-*.md for data modeling, sdk-*.md for SDK usage). See rules/_sections.md for category descriptions.

1. Data Modeling — CRITICAL (prefix: model-)
2. Partition Key Design — CRITICAL (prefix: partition-)
3. Query Optimization — HIGH (prefix: query-)
4. SDK Best Practices — HIGH (prefix: sdk-)
5. Indexing Strategies — MEDIUM-HIGH (prefix: index-)
6. Throughput & Scaling — MEDIUM (prefix: throughput-)
7. Global Distribution — MEDIUM (prefix: global-)
8. Monitoring & Diagnostics — LOW-MEDIUM (prefix: monitoring-)
9. Design Patterns — HIGH (prefix: pattern-)
10. Vector Search — HIGH (prefix: vector-)

How to Use

Each rule is a separate file under rules/. When answering a Cosmos DB question, read only the relevant rule file(s) based on the prefix matching the topic:

  • Data modeling question → read rules/model-*.md files

  • Partition key question → read rules/partition-*.md files

  • SDK/client question → read rules/sdk-*.md files

  • etc.

Each rule file contains:

  • Brief explanation of why it matters

  • Incorrect code example with explanation

  • Correct code example with explanation

  • Additional context and references

Source: AzureCosmosDB/cosmosdb-agent-kit

Files

rules/model-denormalize-reads.md


title: Denormalize for Read-Heavy Workloads impact: HIGH impactDescription: reduces query RU by 2-10x tags: model, denormalization, read-optimization, performance

Denormalize for Read-Heavy Workloads

In read-heavy workloads, denormalize frequently-queried data to avoid expensive lookups. Accept write overhead for faster reads.

Incorrect (normalized requires multiple queries):

// Displaying product list with category names
public class Product
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string CategoryId { get; set; }  // Just the ID
    public decimal Price { get; set; }
}

// To display "Product Name - Category Name" requires JOIN-like pattern:
var products = await GetProductsAsync();
foreach (var product in products)
{
    // N+1 query problem!
    var category = await container.ReadItemAsync<Category>(
        product.CategoryId, new PartitionKey(product.CategoryId));
    product.CategoryName = category.Name;
}
// 1 + N queries = terrible performance

Correct (denormalized for read efficiency):

public class Product
{
    public string Id { get; set; }
    public string Name { get; set; }
    public string CategoryId { get; set; }
    
    // Denormalized category info for display
    public string CategoryName { get; set; }
    public string CategorySlug { get; set; }
    
    public decimal Price { get; set; }
}

// Single query returns everything needed for display
var query = "SELECT c.id, c.name, c.categoryName, c.price FROM c WHERE c.type = 'product'";
var products = await container.GetItemQueryIterator<Product>(query).ReadNextAsync();
// No additional queries needed!

// When category changes, update products using Change Feed
public async Task HandleCategoryChange(Category category)
{
    var query = $"SELECT * FROM c WHERE c.categoryId = '{category.Id}'";
    await foreach (var product in container.GetItemQueryIterator<Product>(query))
    {
        product.CategoryName = category.Name;
        await container.UpsertItemAsync(product);
    }
}

Denormalize when:

  • Read-to-write ratio is high (10:1 or more)

  • Denormalized data changes infrequently

  • Query patterns benefit from co-located data

Additional strategies to consider for denormalization: Short-Circuit Denormalization :

  • Definition: Duplicate only specific fields (not the full related document) to avoid a cross-partition lookup

  • When to use:

    • The duplicated property is mostly immutable (e.g., product name) or the app can tolerate staleness

    • The property is small (a string, not an object)

    • The access pattern would otherwise require a cross-partition read

  • Example: Copy customerName into Order doc to avoid looking up the Customer doc

Workload-Driven Cost Comparison Template for Denormalization Strategy :

Option 1 — Denormalized:
  Read cost:  [read_RPS] × [RU_per_read] = X RU/s
  Write cost: [write_RPS] × [RU_per_write] + [update_propagation_cost] = Y RU/s
  Total: X + Y RU/s

Option 2 — Normalized:
  Read cost:  [read_RPS] × ([RU_per_read] + [RU_for_lookup]) = X' RU/s
  Write cost: [write_RPS] × [RU_per_write] = Y' RU/s
  Total: X' + Y' RU/s

Decision: Choose option with lower total RU/s when workload profile details available

Reference: Denormalization patterns

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
cosmosdb-agent-kit
Publisher
Cline (Official)
Distributed by
Cline
Source
cline/skills · skills/cosmosdb-best-practices · commit 2637846
Licence
MIT License (redistribution allowed)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by cosmosdb-agent-kit or Cline.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download cosmosdb-best-practices.zip