Bird
Raised Fist0
Azurecloud~10 mins

Cosmos DB overview and use cases in Azure - Interactive Code Practice

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a Cosmos DB account with the correct API type.

Azure
az cosmosdb create --name myCosmosDBAccount --resource-group myResourceGroup --kind [1]
Drag options to blanks, or click blank then click option'
AMongoDB
BTable
CGlobalDocumentDB
DCassandra
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing MongoDB API when the task is to create a SQL API account.
Selecting Table API which is for key-value storage.
2fill in blank
medium

Complete the code to create a new database inside the Cosmos DB account.

Azure
az cosmosdb sql database create --account-name myCosmosDBAccount --resource-group myResourceGroup --name [1]
Drag options to blanks, or click blank then click option'
AmyTable
BmyContainer
CmyCollection
DmyDatabase
Attempts:
3 left
💡 Hint
Common Mistakes
Using container or collection names instead of database name.
Confusing database with table names.
3fill in blank
hard

Fix the error in the code to create a container with a partition key.

Azure
az cosmosdb sql container create --account-name myCosmosDBAccount --database-name myDatabase --name myContainer --partition-key-path [1]
Drag options to blanks, or click blank then click option'
A/partitionKey
Bid
C/id
DpartitionKey
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the leading slash in the partition key path.
Using property names without slashes.
4fill in blank
hard

Fill both blanks to configure the consistency level and throughput for the Cosmos DB account.

Azure
az cosmosdb update --name myCosmosDBAccount --resource-group myResourceGroup --default-consistency-level [1] --max-throughput [2]
Drag options to blanks, or click blank then click option'
ASession
BStrong
C400
D1000
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing Strong consistency which can reduce performance.
Setting throughput too low for expected workload.
5fill in blank
hard

Fill all three blanks to write a query that selects items with a price greater than 20 from a container.

Azure
SELECT * FROM c WHERE c.[1] [2] [3]
Drag options to blanks, or click blank then click option'
Aprice
B>
C20
Dquantity
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong property name like quantity.
Using incorrect operators like < or =.

Practice

(1/5)
1. What is the main benefit of using Azure Cosmos DB for global applications?
easy
A. It provides low latency and high availability worldwide.
B. It only supports SQL queries.
C. It requires manual scaling of resources.
D. It is designed for local, single-region apps only.

Solution

  1. Step 1: Understand Cosmos DB's global distribution

    Cosmos DB is designed to replicate data across multiple regions to provide fast access and high availability.
  2. Step 2: Identify the benefit for global apps

    This replication ensures low latency and continuous availability for users worldwide.
  3. Final Answer:

    It provides low latency and high availability worldwide. -> Option A
  4. Quick Check:

    Global apps need low latency and high availability = A [OK]
Hint: Global apps need fast, reliable data access worldwide [OK]
Common Mistakes:
  • Thinking Cosmos DB only supports SQL
  • Assuming manual scaling is required
  • Believing it's for single-region use only
2. Which of the following is a supported API model in Azure Cosmos DB?
easy
A. Oracle SQL API
B. MySQL API
C. MongoDB API
D. PostgreSQL API

Solution

  1. Step 1: Recall Cosmos DB supported APIs

    Azure Cosmos DB supports multiple APIs including SQL, MongoDB, Cassandra, Gremlin, and Table APIs.
  2. Step 2: Identify the correct API from options

    MongoDB API is officially supported, while Oracle, MySQL, and PostgreSQL APIs are not.
  3. Final Answer:

    MongoDB API -> Option C
  4. Quick Check:

    MongoDB API is supported by Cosmos DB = B [OK]
Hint: Remember Cosmos DB supports MongoDB API, not Oracle or MySQL [OK]
Common Mistakes:
  • Confusing Cosmos DB with relational databases
  • Assuming all SQL-based APIs are supported
  • Selecting unsupported database APIs
3. Given this Cosmos DB use case: A global e-commerce app needs to store product catalog data with fast reads and writes worldwide. Which Cosmos DB feature best supports this?
medium
A. Local SSD caching only
B. Multi-region replication with automatic failover
C. Single-region write with manual backups
D. Manual sharding without replication

Solution

  1. Step 1: Analyze the requirement for global fast reads and writes

    The app needs data available quickly everywhere and must handle writes globally.
  2. Step 2: Match Cosmos DB features to requirements

    Multi-region replication with automatic failover allows writes and reads in multiple regions with high availability and low latency.
  3. Final Answer:

    Multi-region replication with automatic failover -> Option B
  4. Quick Check:

    Global fast reads/writes need multi-region replication = C [OK]
Hint: Global writes need multi-region replication with failover [OK]
Common Mistakes:
  • Choosing single-region write limits scalability
  • Confusing caching with replication
  • Ignoring automatic failover importance
4. You created a Cosmos DB container but notice your app experiences high latency when accessing data globally. What is the most likely cause?
medium
A. The container is configured with single-region write and no multi-region replication.
B. The container uses multi-region replication with automatic failover.
C. The container has indexing enabled for all properties.
D. The container is using the MongoDB API.

Solution

  1. Step 1: Understand latency causes in global apps

    High latency often happens if data is only written and read from one region far from users.
  2. Step 2: Identify configuration causing latency

    Single-region write without multi-region replication means users far from that region experience delays.
  3. Final Answer:

    The container is configured with single-region write and no multi-region replication. -> Option A
  4. Quick Check:

    Single-region write without replication causes high latency = A [OK]
Hint: Check if multi-region replication is enabled to reduce latency [OK]
Common Mistakes:
  • Assuming indexing causes latency
  • Confusing API choice with latency issues
  • Believing multi-region replication increases latency
5. A company wants to build a globally distributed IoT app that collects sensor data continuously and requires automatic scaling and low latency. Which Cosmos DB feature combination best fits this use case?
hard
A. Gremlin API with no replication and fixed throughput
B. Single API support with manual scaling and single-region writes
C. Table API with single-region replication and manual failover
D. Multi-model support with multi-region writes and automatic scaling

Solution

  1. Step 1: Identify IoT app requirements

    The app needs to handle continuous data ingestion globally with automatic scaling and low latency.
  2. Step 2: Match Cosmos DB features to these needs

    Multi-model support allows flexible data types; multi-region writes enable global data ingestion; automatic scaling handles variable loads.
  3. Final Answer:

    Multi-model support with multi-region writes and automatic scaling -> Option D
  4. Quick Check:

    IoT needs global writes and scaling = D [OK]
Hint: IoT needs multi-region writes plus auto scaling [OK]
Common Mistakes:
  • Choosing single-region writes limits global data ingestion
  • Ignoring automatic scaling for variable IoT loads
  • Selecting APIs without replication support