↑ ↓ to move, Enter to open, Esc to close

    DP-420Building AI Applications with Azure Cosmos DB

    Switch exam

    Microsoft Azure

    aws Amazon Web Services

    Google Cloud

    ServiceNow

    Databricks

    Cisco

    Salesforce

    All exams and search

    Exams / DP-420 / D1 Design and develop database solutions

    D1.1

    Evaluate resource models and SDK solutions

    • 6 min read
    • 5 sections
    • 47 questions
    • 40–45% of the exam
    • Free preview
    • Evaluate consistency levels
    • Evaluate Request Unit (RU) consumption requirements
    • Evaluating and configuring appropriate throughput
    • Configure account-level and container-level settings
    • Create and manage database and containers
    • Initialize SDK clients and connections
    You are reading a free preview. The rest of the DP-420 course unlocks with an Exam pass or All access.See plans

    1. Resource model

    An account holds databases, a database holds containers, and a container holds items plus server-side scripts (stored procedures, triggers, UDFs). The SDKs are data-plane tools: they create databases and containers, read and write items, and register or run scripts. Physical partitions are managed by the service. The SDK only exposes them as opaque FeedRange values (one per physical partition).

    Accountdefault consistency, regions,capacity mode, free tierDatabaseoptional shared RU/sContainerpartition key, TTL, unique keys,indexing,optional dedicated RU/sItemsStored procedures / triggers /UDFsPhysical partitions≤ 10,000 RU/s and 50 GB eachservice-managed
    Setting Where Changeable later?
    Default consistency Account Yes
    Capacity mode (provisioned / serverless) Account Chosen at creation
    Free tier (enableFreeTier) Account Opt-in at creation only, 1 per subscription
    Shared vs dedicated throughput Database / container No, only at creation, so changing it means migrating to a new container
    Partition key Container No, immutable, so changing it means migrating the data
    TTL (DefaultTimeToLive) Container (+ item ttl) Yes
    Unique key policy Container Set at creation

    TTL and unique keys

    • DefaultTimeToLive = -1 turns TTL on with no default expiry: items without ttl never expire. An item with ttl = n expires after n seconds.
    • TTL counts from the last modification, so every update restarts the timer.
    • Several paths inside one UniqueKey form one composite unique key. Uniqueness is enforced per logical partition (partition key + unique key).

    2. Consistency levels

    Strongest to weakest: Strong > Bounded Staleness > Session > Consistent Prefix > Eventual.

    Level Guarantee Reads Writes
    Strong Always the latest committed version (linearizable) 2 replicas (minority quorum), 2x RU Committed in every region (global majority)
    Bounded Staleness Lag between regions < K versions or T time 2 replicas, 2x RU Local majority; throttled if lag exceeds the bound
    Session Read-your-writes and write-follows-reads in a session (session token) 1 replica Local majority
    Consistent Prefix No out-of-order reads; transactional batches are seen whole and in order 1 replica Local majority
    Eventual No ordering guarantee 1 replica Local majority
    • Every level writes to a local majority (3 of 4 replicas) in its region.
    • Strong multi-region write latency is 2 × RTT of the two farthest regions + 10 ms (P99). Strong cannot be used with multiple write regions.
    • Bounded Staleness fits single-write accounts with 2+ regions. With multi-region writes it is an anti-pattern.

    Overriding consistency

    Account defaultReads only, same or WEAKERAlways follow the accountdefaultReads may be STRONGER:LatestCommitted, GlobalStrongNeed stronger than default?Change the account defaultConsistencyLevel overrideclient or requestwritesReadConsistencyStrategy.NET 3.46+, Java 4.69+
    • Overrides never affect writes. A Strong account still replicates writes synchronously to every region.
    • Session-or-weaker overrides read from a single replica.
    • Session consistency across clients (web tiers, devices) requires you to pass the session token yourself, for example by storing it with the user and sending it on reads.

    3. Request units and throughput

    • Every response exposes RequestCharge (HTTP header x-ms-request-charge). Point operation: ItemResponse<T>.RequestCharge. Query page: FeedResponse<T>.RequestCharge. The legacy .NET v2 SDK used ResourceResponse/IDocumentQuery, and it was retired on 31 August 2024.
    • RU/s are spread evenly across physical partitions. One partition serves at most 10,000 RU/s, so the instant scale limit is partitions × 10,000 RU/s (going above that splits partitions asynchronously).
    • Burst capacity: a partition under 3,000 RU/s can bank up to 300 s × its RU/s of idle capacity and spend it at up to 3,000 RU/s.

    Capacity modes

    Mode Best for Billing Notes
    Serverless Intermittent, unpredictable traffic, low average-to-peak ratio, dev/test RUs consumed + storage Single region only; RU/s ceiling per container
    Provisioned, manual Steady, predictable traffic Provisioned RU/s per hour Cheapest per RU/s when well used
    Provisioned, autoscale Variable or unpredictable traffic Highest RU/s reached each hour, floor 0.1 × Tmax Scales 10%–100% of Tmax; entry Tmax 1,000; storage limit Tmax/10 GB
    • Manual ↔ autoscale is a POST "migrate" operation: use az cosmosdb sql database|container throughput migrate or PowerShell Invoke-AzCosmosDB…ThroughputMigration. ARM templates can't do it, but they can update the autoscale max.

    Shared (database) vs dedicated (container) throughput

    • Containers in a shared database share one RU/s pool, with no per-container guarantee. What a container gets depends on the number of containers, the partition-key choices and the workload distribution.
    • A shared database holds up to 25 containers. Containers beyond 25 must use dedicated throughput.
    • Dedicated throughput is recommended for predictable performance.

    Free tier

    • 1,000 RU/s + 25 GB free for the life of the account, at most one account per subscription, opt-in at creation ("enableFreeTier": true). A shared database at 1,000 RU/s is fully free.

    4. SDK clients and connections

    Mode Protocol / port When
    Gateway HTTPS, 443, single DNS endpoint Strict firewalls, limited sockets (e.g. serverless functions); always used by Python and Node.js SDKs; required for the integrated cache
    Direct TCP + TLS, ports 10000–20000 Best performance (fewer hops); default in .NET/Java

    Integrated cache (dedicated gateway)

    AppDedicated gatewayitem cache + query cacheBackend partitionsGateway mode*.sqlx.cosmos.azure.comcache missDirect mode: bypasses cache

    Checklist for a cache hit (cost 0 RU):

    1. Provision a dedicated gateway. Accounts with availability zones can only get one in a few regions.
    2. Connection string/endpoint: replace documents.azure.com with sqlx.cosmos.azure.com.
    3. Gateway mode (.NET/Java). Direct-mode requests never use the cache.
    4. Read consistency Session or Eventual. Consistent Prefix, Bounded Staleness and Strong bypass the cache.
    5. MaxIntegratedCacheStaleness > 0. Higher values give more hits, and 0 means the cache is never used. Eviction is LRU when the cache is full.

    Emulator

    • Default endpoint https://localhost:8081 with a single account and a well-known key.
    • It is used for local development and CI tests: it is preinstalled on GitHub windows-latest runners, and a Linux Docker image is also available.

    5. ARM / CLI deployment notes

    • Child resources (database → container → sproc/UDF/trigger) need their parent to exist. Use dependsOn in the same template, or deployment fails (ParentResourceNotFound).
    • Incremental mode (the recommended one) leaves undeclared resources untouched.
    • Adding or removing regions can't be combined with other property changes in one update.
    • uniqueString(resourceGroup().id) gives a deterministic 13-character suffix for globally unique names. newGuid() changes on every deployment.
    • Activity log alerts see control-plane events (e.g. databaseAccounts/regenerateKey/action), never data-plane item writes.

    Exam traps

    • "Stronger than the account default": change the account, not the request (unless the question is about ReadConsistencyStrategy). There is no database-level consistency.
    • Consistency overrides apply to reads only. Writes follow the account default.
    • Session, Consistent Prefix and Eventual cost the same per read. Strong and Bounded Staleness cost 2x.
    • "Ordered batches + max throughput": Consistent Prefix. "Lag ≤ 5 minutes" → Bounded Staleness. "Local majority write + minority read" → Bounded Staleness.
    • Autoscale idle bill = 10% of Tmax. The instant max = partitions × 10,000.
    • Shared ↔ dedicated throughput and partition key: migrate to a new container.
    • Integrated cache with 0% hits and the sqlx endpoint: the client is still in Direct mode.
    • Burst capacity answers come in RU (300 s × RU/s), even if the option says RU/s.
    • Emulator: localhost:8081 + well-known key.

    Docs

    The rest of this chapter is part of the DP-420 premium course

    Unlock every chapter, all 271 questions and spaced review with All access or a 90-day exam pass. Every Fundamentals exam stays free, and the first chapter of every exam is open.

    Chapters