Cosmos DB Architecture

Develop for Azure Storage

Shahzad Mian

Content developer, DataCamp

Azure Cosmos DB

Azure_Cosmos_DB.svg.png

Develop for Azure Storage

The problem

Cosmos DB problem

Develop for Azure Storage

What is Cosmos DB?

 

CosmosDB

  • Multi-model, globally distributed NoSQL database.
  • NoSQL - flexible, folder-like storage.
  • Supports multiple APIs and data types.
  • Like a flexible restaurant menu - choose your API flavor:
    • SQL (Core) for JSON documents.
    • MongoDB for Mongo developers.
    • Cassandra for wide-column data.
    • Gremlin for graph relationships.
    • Table API for key-value storage.
Develop for Azure Storage

Cosmos DB for developers

  • Built with developers in mind.
  • Automatic indexing - no schema management.
  • Fast queries.
  • Five consistency levels: from Strong to Eventual.
  • Trade-off between performance vs consistency.
    • Strong - everyone hears the same message instantly.
    • Eventual - everyone catches up later.

 

Strong and eventual consistency

Develop for Azure Storage

Scaling and Throughput (RU/s)

Provisioned mode

  • Request units per second (RU/s) = performance currency of Cosmos DB.
  • Each read, write, or query spends some RU/s.
  • Choose fixed provisioning or autoscale.
Develop for Azure Storage

Scaling and Throughput (RU/s)

Scaling

  • Request units per second (RU/s) = performance currency of Cosmos DB.
  • Each read, write, or query spends some RU/s.
  • Choose fixed provisioning or autoscale.
  • Autoscale adjusts automatically with demand.
Develop for Azure Storage

Elastic scale and Partitioning

  • Cosmos DB scales through partitioning.
  • Each container uses a partition key.
  • The key groups related data together.
  • Example: Cipher Coffee uses /customerId for orders.
  • All a customer's orders live in the same partition when using /customerId as the partition key.
  • Queries stay fast even as data grows.
  • Hot partition: Uneven partition load slowing down performance.

Elastic scale and partioning

Develop for Azure Storage

Global distribution

  • Replicate data to any Azure region easily.
  • Just tick checkboxes, no setup hassle.
  • If one region fails, traffic reroutes automatically.
  • No downtime, no data loss.
  • Like a backup cafe ready to serve customers instantly.

Global distribution

Develop for Azure Storage

Monitoring and cost optimization

  • Track performance in the Azure Portal.
  • View metrics like RU/s, latency, and request charge.
  • Like a car dashboard - see speed and fuel use.
  • Cipher Coffee engineers analyzed these metrics.
  • Reduced costs by adjusting throughput dynamically.

Monitoring

Develop for Azure Storage

Let's practice!

Develop for Azure Storage

Preparing Video For Download...