Domain 3 β€” Module 3 of 5 60%
17 of 27 overall
Domain 3: Non-Relational Data on Azure Free ⏱ ~12 min read

Azure Cosmos DB: The Global Database

Azure Cosmos DB is Microsoft's globally distributed, multi-model NoSQL database. It's designed for apps that need single-digit millisecond latency at any scale, anywhere in the world.

What is Azure Cosmos DB?

Simple explanation

Cosmos DB is a super-fast, world-wide database that handles any shape of data.

Imagine a pizza chain with shops in Auckland, London, and New York. Each shop needs to check inventory and take orders instantly. With a normal database in one location, shops far away get slow responses. Cosmos DB puts copies of the data in every region β€” so every shop gets fast responses, no matter where they are.

Plus, Cosmos DB doesn’t force you into one data model. It can store JSON documents, key-value pairs, graphs, or even table-like data.

When to use Cosmos DB

Cosmos DB shines when your application needs:

NeedWhy Cosmos DB
Global distributionReplicate data to any Azure region for low-latency reads worldwide
Guaranteed speedSingle-digit millisecond response times, SLA-backed
Massive scaleHandle millions of requests per second across regions
Flexible schemaStore JSON documents with varying structures
Multi-modelChoose the right API for your data: document, key-value, graph, or table
Always available99.999% availability with multi-region writes

Common use cases

Jake’s CloudPulse example: The SaaS app serves customers globally. Session state and real-time user activity data go into Cosmos DB:

  • Users in Auckland, Singapore, and London all get sub-10ms reads
  • Each user’s session data is a JSON document with flexible fields
  • The app auto-scales during peak hours without manual intervention

Other common use cases:

  • E-commerce: Product catalogues with varying attributes per category
  • IoT: Ingesting millions of sensor readings per second
  • Gaming: Leaderboards, player profiles, real-time game state
  • Social media: User feeds, activity streams, content graphs
  • Personalisation: Recommendation engines, user preferences
Consistency levels

Cosmos DB offers five consistency levels β€” a spectrum between strong consistency (always the latest data, slower) and eventual consistency (might be slightly stale, faster):

  1. Strong β€” every read returns the most recent write (like a relational database)
  2. Bounded staleness β€” reads may lag behind writes by a defined time/operations window
  3. Session β€” reads within a session are consistent (default and most popular)
  4. Consistent prefix β€” reads never see out-of-order writes
  5. Eventual β€” no ordering guarantee, but fastest and cheapest

Session consistency (the default) is what most apps need β€” your own writes are immediately visible to you, while other regions catch up in the background.

Exam tip: Cosmos DB vs relational databases

The exam tests your ability to choose between Cosmos DB and relational databases:

  • β€œGlobal distribution needed” β†’ Cosmos DB
  • β€œFlexible schema, varying document structures” β†’ Cosmos DB
  • β€œMillions of operations per second” β†’ Cosmos DB
  • β€œNeed SQL joins across tables” β†’ Relational database (NOT Cosmos DB)
  • β€œNeed ACID transactions across multiple tables” β†’ Relational database
  • β€œFixed schema, strong referential integrity” β†’ Relational database

Request Units (RU/s) β€” how you pay

Cosmos DB measures throughput in Request Units per second (RU/s). One RU is the cost of reading a single 1KB document by its ID.

  • More complex queries cost more RUs
  • You provision a target RU/s capacity (or use serverless for variable workloads)
  • Throughput can be provisioned per database or per container

This is fundamentally different from relational databases where you provision CPU and memory.

Flashcards

Question

What are the key advantages of Azure Cosmos DB?

Click or press Enter to reveal answer

Answer

Global distribution (data replicated to any Azure region), guaranteed single-digit millisecond latency, automatic scaling, flexible schema (NoSQL), multi-model APIs, and 99.999% availability SLA.

Click to flip back

Question

What is a Request Unit (RU) in Cosmos DB?

Click or press Enter to reveal answer

Answer

A Request Unit is the measure of throughput in Cosmos DB. One RU equals the cost of reading a single 1KB document by its ID. More complex operations cost more RUs. You provision RU/s capacity for your workload.

Click to flip back

Question

What is the default consistency level in Cosmos DB?

Click or press Enter to reveal answer

Answer

Session consistency β€” your own writes are immediately visible to you within your session. Other regions see updates with a slight delay. It's the most popular choice, balancing consistency and performance.

Click to flip back

Knowledge check

Knowledge Check

Jake's SaaS application needs to serve users in Auckland, London, and New York with sub-10ms response times. User profiles are JSON documents with flexible schemas. Which Azure database should he use?

Knowledge Check

A gaming company needs to store player leaderboards that handle 500,000 writes per second during tournaments, with players connecting from 30 countries. Which service fits BEST?

Next up: Cosmos DB APIs: SQL, MongoDB & More β€” Cosmos DB supports multiple data models through its API layer.