AZ-305
Deep Dive
Cosmos DB dominates this AZ-305 block: choosing the right API, designing the partition key, picking the consistency level that balances latency and correctness, and deciding on the multi-region topology. Plus the alternatives: Table Storage, Redis and AI Search.
Contents
🗄️Árbol de decisión — Cosmos DB API y NoSQL
NoSQL · MongoDB · Cassandra · Gremlin · Table · Azure Table
Pregunta 1
¿Es un proyecto nuevo o estás migrando una app existente?
💡 Para migraciones el driver es la compatibilidad de wire-protocol — no reescribir nada. Para proyectos nuevos, elige la API que mejor modela tus datos.
| API | Model | When |
|---|---|---|
| NoSQL (Core) | JSON documents, SQL-like query | Default for new apps — the native API with all features first |
| MongoDB | BSON documents, Mongo wire protocol | Migrate existing MongoDB apps without rewriting drivers |
| Cassandra | Wide-column, CQL | Migrate Cassandra workloads |
| Gremlin | Graphs (vertices/edges) | Complex relationships: social networks, recommendations, fraud |
| Table | Key-value | Upgrade from Azure Table Storage: guaranteed latency, global distribution, indexing on everything |
| PostgreSQL (Citus) | Distributed Postgres | Relational with native horizontal sharding |
Request Units (RU/s) are Cosmos's capacity currency: 1 RU ≈ reading a 1 KB item by id. Every operation costs RUs. Throughput is provisioned (manual or autoscale) or billed on consumption (serverless). RUs are split evenly across physical partitions — which is why the partition key is THE design decision.
Partition key — criteria
Throughput modes
| Level | Guarantee | Scenario |
|---|---|---|
| Strong | Reads always see the last committed write (linearizable) | Bank balances, critical inventory. Higher latency; limited multi-region writes |
| Bounded Staleness | Bounded lag: at most K versions or T seconds behind | Sports scoreboards, stock prices with a bounded, tolerated delay |
| Session (default) | Within a session: you read your own writes | The correct default for most apps — user profiles, shopping carts |
| Consistent Prefix | You never see out-of-order writes (but may see older versions) | Feeds where order matters more than freshness |
| Eventual | Eventual convergence, no order guarantee | Like counters, retweets — maximum speed and availability |
How to memorize it
From Strong to Eventual: less consistency = less latency + more availability + lower read RU cost. "Read my own writes" → Session. "Maximum 5-second delay" → Bounded Staleness. "Never out-of-order data but tolerates staleness" → Consistent Prefix.
Single-region write + read replicas
Multi-region writes
Design extras
| Service | When to choose it over Cosmos |
|---|---|
| Azure Table Storage | Simple key-value, VERY cheap, no guaranteed-latency or global-distribution requirements. Logs, metadata, configuration |
| Azure Cache for Redis | Sub-millisecond in-memory cache IN FRONT of another DB (cache-aside), session store, volatile pub/sub. Not the primary database. Tiers: Basic (dev), Standard (HA), Premium (persistence, clustering, geo-replication), Enterprise (Redis Stack modules, global active-active) |
| Azure AI Search | Full-text search, facets, vector/semantic search over data from other stores (indexers from Cosmos/SQL/Blob) |
| Blob Storage | The object IS the data (images, videos, backups) — no need to query its contents |
| Requirement | Design |
|---|---|
| Global users write with local latency | Cosmos multi-region writes (+ conflict resolution) |
| The user must immediately see what they just wrote | Session consistency |
| Financial data: every read sees the latest write | Strong consistency (single region or nearby regions) |
| Multi-tenant SaaS, queries always filter by tenant | Partition key = tenantId (or hierarchical tenantId/entityId) |
| Traffic with unpredictable 10x spikes | Autoscale throughput |
| React to every data change with a Function | Change feed + Azure Functions trigger |
| Migrate a MongoDB app without rewriting | Cosmos DB API for MongoDB |
| Cheap key-value with no strict SLAs | Azure Table Storage |
| Sub-ms session cache | Azure Cache for Redis (Standard/Premium for HA) |
| Redis cache with geo-replication or RDB/AOF persistence | Azure Cache for Redis Premium |
| Analytics on operational data without consuming RUs | Analytical store + Synapse Link |
Did you get this topic?
Test what you just learned
A global e-commerce app uses Cosmos DB (NoSQL API). Requirements: users in Europe, Asia and America must write with low latency in their own region; a user must always see their own recent actions (their updated cart); a few milliseconds of lag between regions is acceptable. Which configuration do you choose?
Put what you learned to the test with original AZ-305 exam questions.
Start AZ-305 mock examUnlimited mock exams with the Pro plan
Log in to track your progress.