Performance tuning for Azure Cosmos DB - Hasan Savran - NDC Oslo 2024

Learn essential performance tuning strategies for Azure Cosmos DB, including partition management, indexing optimization, SDK best practices, and cost-effective operations.

Key takeaways
  • Physical partitions in Cosmos DB have limits of 50GB storage and 10,000 RUs per server. Understanding these limits is crucial for scaling

  • Indexing modes and strategies significantly impact costs:

    • Everything is indexed by default
    • Use composite indexes to optimize queries and save RUs
    • Exclude unnecessary properties from indexing
    • Index metrics help identify optimization opportunities
  • SDK connection modes affect performance:

    • Direct mode (recommended) uses TCP/TLS
    • Gateway mode uses HTTPS/DNS
    • Use 64-bit applications and singleton pattern for document clients
  • Request Units (RUs) optimization:

    • Point reads are cheapest way to read data
    • Include partition key in queries when possible
    • Use partial document updates instead of full updates
    • Caching can save RUs for frequently accessed data
  • Performance best practices:

    • Use bulk operations for large data loads
    • Implement proper partition key strategy
    • Leverage change feed for data synchronization
    • Use stream API when possible to reduce memory usage
    • Consider serverless for dev/QA environments
  • Data consistency considerations:

    • Avoid “lazy” consistency level
    • Session or eventual consistency can be more cost-effective
    • Consistency level affects RU consumption
  • Cost optimization strategies:

    • Reserved capacity offers 20-30% savings
    • Autoscale for variable workloads
    • Monitor and optimize indexing policies
    • Use caching for frequently accessed data
    • Implement composite indexes strategically