Azure Cosmos DB Developer Free Sample Questions

Description

Covers non-relational data modeling and partitioning, sizing and scaling, replication and multi-region writes, analytical workload integration, query performance, and monitoring and security.

20 free sample questions183 in the full practice test

Try simulator

DP-420 Sample Questions

  1. Question 1

    Intermediate

    Optimize an Azure Cosmos DB solution · Define and implement an indexing strategy for Azure Cosmos DB for NoSQL

    A financial services company is using Azure Cosmos DB for NoSQL to store transaction data. The container is partitioned by /transactionId. During a performance audit, you observe that queries filtering on /transactionDate are consuming a high number of RUs and are identified as cross-partition queries. The development team wants to add a composite index to improve performance for queries that filter by both /transactionDate and /transactionType. The current indexing policy is the default. What is the most likely outcome of adding a composite index for (/transactionDate, /transactionType)?

    Answer and explanation

    Correct answer: B

    A composite index can optimize the filtering and sorting of cross-partition queries, thereby reducing their RU cost. However, it does not change the fundamental nature of the query. Since the partition key (/transactionId) is not included in the query's WHERE clause, the query must still be fanned out across all partitions to find the relevant documents. The composite index makes the process of finding matching documents within each partition much more efficient.

  2. Question 2

    Advanced

    Design and implement data models · Design and implement a non-relational data model for Azure Cosmos DB for NoSQL

    You are designing a multi-tenant SaaS application on Azure Cosmos DB for NoSQL. Each tenant's data must be logically isolated. The application has a high volume of small, frequent writes and reads. To optimize costs, you provision throughput at the database level and use a shared container for all tenants. You choose /tenantId as the partition key. A new requirement mandates that within each tenant's data, all user profiles must have a unique emailAddress. How should you enforce this new uniqueness constraint?

    Answer and explanation

    Correct answer: D

    A unique key constraint in Azure Cosmos DB is always scoped to a logical partition. By defining a unique key policy on /emailAddress and having /tenantId as the partition key, you enforce that emailAddress must be unique for all documents that share the same tenantId. This perfectly matches the requirement for tenant-level data isolation.

  3. Question 3

    Advanced

    Design and implement data distribution · Design and implement multi-region write

    A global e-commerce platform uses Azure Cosmos DB for NoSQL with multi-region writes enabled to reduce latency for a worldwide user base. The consistency level is set to Session. To handle concurrent updates to a user's shopping cart, a custom conflict resolution policy has been implemented using a merge stored procedure. The policy is designed to merge the items from conflicting writes. During a sales event, users in Europe report that items they add to their cart are occasionally disappearing. Users in North America do not report this issue. The primary write region is North America. What is the most probable cause of this issue?

    Answer and explanation

    Correct answer: B

    When using a custom conflict resolution policy with a merge stored procedure, the stored procedure must be created in each region where writes can occur. If the stored procedure is only registered in the North America region, conflicts originating from writes in Europe will fail to be resolved correctly, leading to data loss. The conflict resolution mechanism will fall back to a default behavior which might not align with the intended merge logic.

  4. Question 4

    IntermediateMultiple answers

    Integrate an Azure Cosmos DB solution · Implement solutions across services

    You are building an event-sourcing solution where all changes to application state are captured as a sequence of events. You use Azure Cosmos DB for NoSQL and an Azure Function with a Cosmos DB trigger to process these events. The function archives events to cold storage and updates several materialized views in other containers. During testing, you notice that if the Azure Function fails while processing a batch of changes, it re-processes the same batch again upon restart, leading to duplicate data in the materialized views. Which two actions should you take to make the function idempotent and prevent data duplication? (Select TWO)

    Answer and explanation

    Correct answers: A, D

    The _lsn property is a unique, monotonically increasing number for each change. By tracking the last successfully processed _lsn for each partition in your destination (or a separate state store), your function can check if an incoming event's _lsn has already been processed, thus achieving idempotency.

    Making the write operations to the materialized views idempotent is crucial. Using an upsert (CreateItemAsync or ReplaceItemAsync logic) ensures that if an event is processed twice, the second operation simply overwrites the existing data with the same information, rather than creating a duplicate entry.

  5. Question 5

    Beginner

    Optimize an Azure Cosmos DB solution · Define and implement an indexing strategy for Azure Cosmos DB for NoSQL

    You are managing a large Azure Cosmos DB for NoSQL container that stores user session data. The container is configured with the default indexing policy (automatic indexing of all properties). You identify that a specific property, sessionTrace, contains large JSON blobs used only for debugging and is never queried. To reduce storage costs and improve write performance, you decide to exclude this property from indexing. Which JSON snippet represents the correct indexing policy to achieve this?

    Answer and explanation

    Correct answer: B

    This policy correctly uses the default behavior of indexing everything (includedPaths with /*) and then specifically carves out an exception. The excludedPaths array with the path /sessionTrace/* tells Cosmos DB to not index the sessionTrace property or any of its sub-properties. The * is a wildcard that matches any element beyond the sessionTrace property.

  6. Question 6

    Intermediate

    Maintain an Azure Cosmos DB solution · Implement a DevOps process for an Azure Cosmos DB solution

    A DevOps engineer is tasked with automating the deployment of an Azure Cosmos DB for NoSQL account using Azure Resource Manager (ARM) templates. The requirement is to configure the account with two regions: 'East US' as the primary write region and 'West US' as a read region. The deployment must also specify the automatic failover policy with 'West US' having a failover priority of 1. Which property within the Microsoft.DocumentDB/databaseAccounts resource in the ARM template should be configured to define the regions and failover priorities?

    Answer and explanation

    Correct answer: C

    The properties.locations property in an ARM template for a Cosmos DB account is an array of location objects. Each object specifies a locationName and a failoverPriority. The region with failoverPriority: 0 is the primary write region, and subsequent regions are assigned priorities of 1, 2, and so on, for the automatic failover order.

  7. Question 7

    Beginner

    Design and implement data models · Implement data access by using Azure Cosmos DB for NoSQL SDKs

    True or False: When using the Azure Cosmos DB for NoSQL SDK and performing a transactional batch operation, all operations within the batch must target documents that reside within the same logical partition.

    Answer and explanation

    Correct answer: A

    Transactional batch operations in Azure Cosmos DB for NoSQL are scoped to a single logical partition. This is because they are executed as a single transaction on the database engine replica set that hosts the logical partition. This constraint ensures ACID properties for the operations within the batch. If you attempt to include operations for documents in different logical partitions, the entire batch operation will fail.

  8. Question 8

    Intermediate

    Maintain an Azure Cosmos DB solution · Monitor and troubleshoot an Azure Cosmos DB solution

    You are monitoring an Azure Cosmos DB for NoSQL account using Azure Monitor. You notice that the 'Max RU/s Per Partition' metric shows one partition consistently at 10,000 RU/s, while other partitions are below 1,000 RU/s. The container is configured with autoscale throughput up to 40,000 RU/s. Despite having ample overall throughput, the application is experiencing throttling (HTTP 429 errors). What is this condition called and what is the primary solution?

    graph TD subgraph "RU Consumption per Physical Partition" P1["Partition 1: 10,000 RU/s"] -->|Throttling| App{Application} P2["Partition 2: 800 RU/s"] --> App P3["Partition 3: 500 RU/s"] --> App P4["Partition 4: 950 RU/s"] --> App end style P1 fill:#f77,stroke:#333,stroke-width:2px
    Answer and explanation

    Correct answer: B

    This scenario describes a classic 'hot partition' problem. A single physical partition is receiving a disproportionate amount of requests, causing it to hit the maximum throughput limit for a single partition (10,000 RU/s), while the overall container throughput is underutilized. The fundamental solution is to change the partition key to one that distributes requests more evenly across all logical and physical partitions, such as using a synthetic key or a key with higher cardinality.

  9. Question 9

    Intermediate

    Maintain an Azure Cosmos DB solution · Implement backup and restore for an Azure Cosmos DB solution

    A developer needs to implement a point-in-time restore for a critical Azure Cosmos DB for NoSQL account. The requirement is to be able to restore the account to any state within the last 15 days with a granularity of one second. The account currently has periodic backup configured with a 4-hour interval and 2 copies retained. What is the first and most critical step the developer must take to meet the new requirement?

    Answer and explanation

    Correct answer: B

    The requirement for granular, second-level point-in-time restore (PITR) can only be met by continuous backup mode. Periodic backup creates discrete snapshots at set intervals (e.g., every 4 hours). Continuous backup, on the other hand, constantly records changes, allowing for restoration to any point in time within the retention period (up to 30 days). The first step is to migrate the account's backup policy, which can be done via the Azure Portal, CLI, or ARM templates.

  10. Question 10

    Intermediate

    Maintain an Azure Cosmos DB solution · Implement security for an Azure Cosmos DB solution

    You need to implement security for an Azure Cosmos DB for NoSQL account to ensure that developers on your team can only manage database and container settings (control plane operations) but cannot read or write data (data plane operations). The developers must be able to perform their tasks through the Azure portal. Which Azure role should you assign to the developers at the Cosmos DB account scope?

    Answer and explanation

    Correct answer: A

    The 'Cosmos DB Operator' role is specifically designed for this scenario. It grants permissions to manage Azure Cosmos DB resources (accounts, databases, containers) but does not grant access to the data itself or the ability to use the Data Explorer. This effectively separates control plane management from data plane access, adhering to the principle of least privilege.

Register free for 10 more questions

Or unlock all 183 DP-420 questions with explanations, timed mode and flashcards.