D2 · Data Storage

Non-Relational Data Design

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.

🗄️Árbol de decisión — Cosmos DB API y NoSQL

NoSQL · MongoDB · Cassandra · Gremlin · Table · Azure Table

Interactivo

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.

Icon-databases-121

Cosmos DB: APIs and when to use each

APIModelWhen
NoSQL (Core)JSON documents, SQL-like queryDefault for new apps — the native API with all features first
MongoDBBSON documents, Mongo wire protocolMigrate existing MongoDB apps without rewriting drivers
CassandraWide-column, CQLMigrate Cassandra workloads
GremlinGraphs (vertices/edges)Complex relationships: social networks, recommendations, fraud
TableKey-valueUpgrade from Azure Table Storage: guaranteed latency, global distribution, indexing on everything
PostgreSQL (Citus)Distributed PostgresRelational with native horizontal sharding
Icon-databases-121

Partitioning and Request Units

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

  • • High cardinality: many distinct values (userId yes, country no)
  • • Distributes WRITES evenly (avoid hot partitions)
  • • Shows up in the filters of your most frequent queries (avoids expensive cross-partition queries)
  • • Limit: 20 GB per logical partition
  • • Hierarchical partition keys (e.g. tenantId/userId) for multi-tenant workloads exceeding 20 GB per tenant

Throughput modes

  • • Provisioned manual: fixed RU/s — stable, predictable workload
  • • Autoscale: scales between 10%-100% of the max — variable peaks (costs 1.5x the RU but saves on valleys)
  • • Serverless: pay per RU consumed — intermittent/unpredictable traffic, dev/test. No multi-region write distribution
Icon-databases-121

The 5

LevelGuaranteeScenario
StrongReads always see the last committed write (linearizable)Bank balances, critical inventory. Higher latency; limited multi-region writes
Bounded StalenessBounded lag: at most K versions or T seconds behindSports scoreboards, stock prices with a bounded, tolerated delay
Session (default)Within a session: you read your own writesThe correct default for most apps — user profiles, shopping carts
Consistent PrefixYou never see out-of-order writes (but may see older versions)Feeds where order matters more than freshness
EventualEventual convergence, no order guaranteeLike 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.

Icon-databases-121

Global distribution and multi-region

Single-region write + read replicas

  • •Writes in one region, local reads in N regions
  • •Automatic write failover if the primary region goes down (service-managed failover)
  • •Simpler: no write conflicts
  • •99.999% multi-region read SLA

Multi-region writes

  • •Writes accepted in ALL regions — local write latency
  • •99.999% write SLA
  • •Requires conflict resolution: Last-Writer-Wins (default) or custom
  • •Not compatible with Strong consistency across distant regions

Design extras

  • • Change feed: stream of changes for materialized views, events and incremental ETL (consumed by /Spark)
  • • TTL per container/item to automatically expire data
  • • Analytical store + Synapse Link: HTAP analytics without touching transactional RUs
  • • Backup: continuous (point-in-time restore) or periodic
Icon-databases-137

Alternatives: Table Storage, Redis, AI Search

ServiceWhen to choose it over Cosmos
Azure Table StorageSimple key-value, VERY cheap, no guaranteed-latency or global-distribution requirements. Logs, metadata, configuration
Azure Cache for RedisSub-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 SearchFull-text search, facets, vector/semantic search over data from other stores (indexers from Cosmos/SQL/Blob)
The object IS the data (images, videos, backups) — no need to query its contents

Decision table

RequirementDesign
Global users write with local latencyCosmos multi-region writes (+ conflict resolution)
The user must immediately see what they just wroteSession consistency
Financial data: every read sees the latest writeStrong consistency (single region or nearby regions)
Multi-tenant SaaS, queries always filter by tenantPartition key = tenantId (or hierarchical tenantId/entityId)
Traffic with unpredictable 10x spikesAutoscale throughput
React to every data change with a FunctionChange feed + Azure Functions trigger
Migrate a MongoDB app without rewritingCosmos DB API for MongoDB
Cheap key-value with no strict SLAsAzure Table Storage
Sub-ms session cacheAzure Cache for Redis (Standard/Premium for HA)
Redis cache with geo-replication or RDB/AOF persistenceAzure Cache for Redis Premium
Analytics on operational data without consuming RUsAnalytical 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?

Ready to test "Non-Relational Data Design"?

Put what you learned to the test with original AZ-305 exam questions.

Start AZ-305 mock exam

Unlimited mock exams with the Pro plan

Log in to track your progress.