Azure Storage, Comos DB Flashcards
What is an Azure Cosmos DB account?
An Azure Cosmos DB account is an Azure resource that acts as an organizational entity for your databases. It connects your usage to your Azure subscription for billing purposes.
True or False? Azure Cosmos DB provides different data models
True:
SQL API, MongoDB, CAssandra, Azure Table and Gremlin (graph)
To minimize Cosmos DB latency, what can you do on creating Azure Cosmos DB Account?
Select a location thats near to customers
True or False? In Azure Cosmos DB, you provision throughput for your containers to run writes, reads, updates, and deletes
True
How is Azure Cosmos DB measuring throughput?
With request unit (RU). Request unit usage is measured per second, so the unit of measure is request units per seconds (RU/s)
True or False? You must reserve the number of RU/s you want Azure Cosmos DB to provision in advance, so it can handle the load you’ve estimated, and you can scale your RU/s up or down at any time to meet current demand.
True
True or false: The number of RUs used for a given database operation over the same data varies over time.
False, Azure Comos DB guarentees that the same query on the same data is consistent.
Which of the following options affects the number of request units it takes to write a document?
Size of the document
Item property count
Indexing policy
All of the above
All of the above
Which of the following statements is false about Request Units (RUs) in Azure Cosmos DB?
The cost to read a 1 KB item is approximately one Request Unit (or 1 RU).
Requests are rate-limited if you exceed the number of provisioned RU.
Once you set the number of request units, it’s impossible to modify this number.
If you provision ‘R’ RUs on an Azure Cosmos container (or a database), Azure Cosmos DB ensures that ‘R’ RUs are available in each region associated with your account.
Once you set the number of request units, it’s impossible to modify this number.
Its always possible to change them from 400 to 250000.
In Azure Comos DB, What is a partition strategy?
Because a Database Partition can run out of space, a partitioning strategy enables you to add more partitions to your database when required. This scaling strategy is called scale out or horizotal scaling
True or False? A partition key defines the partition strategy, it’s set when you create a container and can’t be changed
True
In Azure Comos DB, What is a partition key
A partition key is the value by which Azure organizes your data into logical divisions
Read Again:
When you’re trying to determine the right partition key and the solution isn’t obvious, here are a few tips to keep in mind.
Don’t be afraid of choosing a partition key that has a large number of values. The more values your partition key has, the more scalability you have.
To determine the best partition key for a read-heavy workload, review the top three to five queries you plan on using. The value most frequently included in the WHERE clause is a good candidate for the partition key.
For write-heavy workloads, you’ll need to understand the transactional needs of your workload, because the partition key is the scope of multi-document transactions.
OK
True or false: You can add a partition key to an Azure Cosmos DB container after it has been created.
False, You can set the partition key only when the container is created.
Your organization is planning to use Azure Cosmos DB to store vehicle telemetry data generated from millions of vehicles every second. Which of the following options for your Partition Key will optimize storage distribution?
Vehicle Model
Vehicle Identification Number (VIN) which looks like WDDEJ9EB6DA032037
Vehicle Identification Number (VIN)
True or False? Core (SQL) API is the default Api for Azure Cosmos DB
True
True or False? Core (SQL) API: You can query hierarchical JSON documents with a SQL-like language
True
True or False? at the lowest level Cosmos DB Stores Data in ARS Format (atom-record-sequence) and APIs are just ways to access and modify those.
True
Best API for creating projects from Scratch using Cosmos DB?
Core (SQL)
Best Approach when there is existing DB?
Use the appropriate technology, like Mongo or Cassandra or Gremlin. What ever fits best in the project environment
What API fits best for Azure Comos DB when Data consists of Key-value pairs
Earlier Redis and Table API, but today best fit is Core (SQL) because of richer query experience with improved indexing
What should be the key requirement when deciding for Gremlin
Gremlin (graph) is good when Relations between items have to be made. Like “How is this item related to that item”
A good example is a shop recommendation engine.
How to determine the best fiting Comos DB Api based on a Problem description?
1) Is data unstructured?
2) Is there any existing technology used? If so, probably use even if there is a better choice to reuse code / reduce migrating time because of tech shift
3) Is migration downtime a issue? If not, prefer the better choice instead of 2)
What is CQL referring to?
Cassandra Query Language
When to use Azure Table?
When migrating from earlier Apis like Azure Table Storage or Redis. Then this is preferred instead of Core (SQL) when no downtime is wanted
The e-commerce application has a requirement to support a shopping basket. Customers can add and remove products, and any discounts (like buy one get one free) need to be kept in the basket. The sales team wants the flexibility to offer different kinds of discounts, and to add or remove different product categories.
This type of data is modeled best by documents. Core (SQL) is the best choice for a new system.
The risk department has asked if the new project could implement some form of fraud detection and prevention. The guidance is that the fraud system would need to be able to track the relationship between customers, payment types, billing and delivery addresses, IP address, geolocation, and past purchase history. Anything that doesn’t fit into normal behavior should be flagged.
Complex relationships, and needed to store metadata against them is best supported by a graph mode of data.
The sales team would like to offer a chat feature for customers. Messages will have a fixed number of characters and be simple. The schema is fixed, and the sales team has an existing chat app for which they have built up many CQL statements for creating reports. They would like to reuse them if possible.
The need to reuse existing CQL queries means that Cassandra is the best choice for in this scenario.
True or False? Azure Cosmos DB provides the Data Explorer tool in the Azure portal that you can use to perform all these operations: adding data, modifying data, and creating and running stored procedures.
True
True or False? The database account name must be unique across all Azure Cosmos DB instances.
True
What is the only required clause in a SQL query?
SELECT
FROM
WHERE
SELECT is the only required clause in a query.
Which query will get an ordered list of product IDs and descriptions, starting with the largest product ID and ending with the smallest product ID?
1) SELECT p.productId FROM Products p ORDER BY p.productId ASC
2) SELECT p.id FROM Products p ORDER BY p.productId DESC
3) SELECT p.productId, p.description FROM Products p ORDER BY p.productId DESC
3) SELECT p.productId, p.description FROM Products p ORDER BY p.productId DESC
What does ACID mean?
Atomicity, Consistency, Isolation, Durability.
This is the transaction model for stored procedures and user defined functions in a cosmos db
True or false? Stored procedures are written in JavaScript and are stored in a container on Azure Cosmos DB
True
True or false? Stored procedures are the only way to achieve atomic transactions within Azure Cosmos DB; the client-side SDKs do not support transactions.
True
True or False? UDFs are used to extend the Azure Cosmos DB SQL query language grammar and implement custom business logic, such as calculations on properties and documents. UDFs can be called only from inside queries and, unlike stored procedures, they do not have access to the context object, so they cannot read or write documents.
True
True or False? In Cosmos DB, a graph is a structure that’s composed of vertices and edges. Both vertices and edges can have an arbitrary number of properties.
True
Explain what a Vertices or Node means in a Cosmos DB Graph
Vertices represent objects. For example: a person, a place, or a product.
Explain what a Edges or Relationships means in a Cosmos DB Graph
Edges denote relationships between vertices. For example: a person might know another person, or have visited a place.
Explain what a Property means in a Cosmos DB Graph
Properties express information about the vertices and edges.
For example:
Vertices properties might include the name and age of a person.
Edge properties might include a time stamp of a purchase or a hierarchical affiliation between coworkers.
In which of the following scenarios would a graph database, as opposed to another database model, be the best fit?
1) Where data is disconnected and relationships do not matter
2) A data model where the ability to expand the model to add new data or relationships is necessary
3) If your queries are doing table scans to find a match or searching for data
2) A data model where the ability to expand the model to add new data or relationships is necessary
Perfect for graph databases, with a graph data model, changes to the data model can be made with little or no impact to the application
Which of these answers is a primary strength of graph databases, as compared to other database models?
1) Performance
2) Storage
3) Where data models stay consistent and the structure is fixed and tabular
1) Performance
A graph database has superior performance for querying related data. Graph databases are designed to traverse stored data quickly and retrieve results in milliseconds
True or False? An entity, in a NoSQL table, is the equivalent of a row in a relational database table.
True
True or False? Its possible migrate Tables located in Azure Storage accoutns over to Cosmos DB
True
Suppose you are using Visual Studio Code to develop a .NET Core application that accesses Azure Cosmos DB. You need to include the connection string for your database in your application configuration. What is the most convenient way to get this information into your project?
1) Directly from Visual Studio Code
2) From the Azure portal
3) Using the Azure CLI
1) Directly from Visual Studio Code
When working with Azure Cosmos DB’s SQL API, which of these can be used to perform CRUD operations?
1) LINQ
2) Apache Cassandra client libraries
3) Azure Table Storage libraries
1) LINQ
When working with the Azure Cosmos DB Client SDK’s DocumentClient class, you use a NOSQL model. How would you use this class to change the FirstName field of a Person Document from ‘Ann’ to ‘Fran’?
1) Call UpdateDocumentAsync with FirstName=Fran
2) Call UpsertDocumentAsync with an updated Person object
3) Call ReplaceDocumentAsync with an updated Person object
3) Call ReplaceDocumentAsync with an updated Person object
ReplaceDocumentAsync will replace the existing document with the new one. In this case we’d intend the old and new to be the same other than FirstName.
True Or False? The partitioning configuration can be changed after a collection is provisioned.
False, partitioning is fixed when collection is created
True or False? In Cosmos DB / Core SQL you can change the index for a collection at anytime
True, unlike partitioning indexes are not fixed and can be changed at anytime.
True or False? When executing a SQL in Portals Data Explorer, its possible to see the RU/s for a Query that has been executed
True, Select Query Stats
True or false? Quering a Document within by using the Partition Key is cheaper that receving a document by other properties
True
What causes a hot partition in a distributed NoSQL database collection?
1) A partition key with a large number of values.
2) A partition key that doesn’t distribute requests evenly over storage and time.
3) A read-heavy workload.
4) Querying a large volume of data.
2) Spread your write workload across partitions.
Access that’s concentrated to fewer values of the partition key can cause bottlenecks on a single partition.
What’s the best way to maximize the efficiency of an individual database query?
1) Minimize the number of queries to the database.
2) Spread your write workload across partitions.
3) Design a partition key strategy so that your most frequent queries don’t cross partitions.
3) Design a partition key strategy so that your most frequent queries don’t cross partitions.
Querying within a partition places far fewer demands on Azure Cosmos DB than querying across partitions.
Read again
Partition design considerations:
https://docs.microsoft.com/en-us/learn/modules/monitor-and-scale-cosmos-db/5-partition-lesson
Ok
Indexing all properties in a collection results in:
1) Higher-demand writes to the database and lower-demand queries.
2) Lower-demand writes to the database and higher-demand queries.
3) Higher-demand writes and queries.
1) Higher-demand writes to the database and lower-demand queries.
More resources are consumed when Azure Cosmos DB is updating the index. But using the index to find documents is more efficient.
For read-heavy workloads with an unknown query pattern, the best starting indexing strategy is:
1) Set the indexing policy to none.
2) Index all properties.
3) Index only the specific properties that will be queried.
4) Index only the id property of your documents.
2) Index all properties.
This is a safe choice because you can perform queries efficiently. It’s also the Azure Cosmos DB default.
True or False? Collections are distributed across partitions based on the value of a collection’s partition key.
True
True or False? The partition key is NOT a document property.
False, its always a document property.
In Azure Cosmos DB, Explain What hot partition means
A hot partition is accessed more than the other partitions. The result is an inefficient use of the total configured throughput. If the demand on the hot partition is high enough, the partition becomes overloaded and traffic to the database is rate-limited.
In Cosmos DB, How to Identify a partition strategy?
Estimate the scale of your data needs => Size of ducments and read / writes per second. How many queries
Understand the workload => Is it read or write heavy? If read heavy, what are the top five queries. If write heavy, transactions required?
In Cosmos DB, Propose some partition key options
Does the key choice have a large number of possible values or large cardinality?
Do the values have a consistent spread across the data?
Are some values accessed more than others?
For read-heavy workloads, can the query be within a single partition?
For write-heavy transactional workloads, can the transaction be within a single partition?
In Cosmos DB, name two common scenarios for replicating data in two or more regions
1) Delivering low-latency data access to end users no matter where they are located around the globe
2) Adding regional resiliency for business continuity and disaster recovery (BCDR)
True or false: the benefits of writing to multiple regions are decreased latency, unlimited scaling potential, and improved availability.
True
Writing to multiple regions has many performance benefits. For example, the latency for write operations is less than in non-multi-master accounts.
What is the default conflict-resolution policy in a multi-master account?
1) Last-Writer-Wins
2) A custom user-defined procedure
1) Last writer wins
Which consistency level is most appropriate for the user data in an e-commerce database? Users need to ensure that their orders contain all the items they placed in their basket.
1) Strong
2) Bounded Staleness
3) Session
4) Consistent Prefix
5) Eventual
3) Session
Session is the best consistency setting for user data that contains shopping basket information. Session consistency will ensure that every item the user put in their basket is displayed when they review their basket.
Which consistency level consumes the least amount of request units per operation?
1) Strong
2) Bounded Staleness
3) Session
4) Consistent Prefix
5) Eventual
5) Eventual
In Cosmos DB, what is required to change the partition key?
In general its not possible to change it. If it is required to change the partition key, data must be moved to new container.
Read again:
For all containers, your partition key should ?
(Name at least two)
- Be a property that has a value which does not change. If a property is your partition key, you can’t update that property’s value.
- Have a high cardinality. In other words, the property should have a wide range of possible values.
- Spread request unit (RU) consumption and data storage evenly across all logical partitions. This ensures even RU consumption and storage distribution across your physical partitions.
How to distribute data globally for Azure Cosmos DB
In the Settings, select replicate data globally and then choose the datacenters from the map. Choose those that are close to your users.
In Cosmos DB, what is the following Code doing, whats the purpose?
ConnectionPolicy connectionPolicy = new ConnectionPolicy();
//Setting read region selection preference
connectionPolicy.PreferredLocations.Add(LocationNames.WestUS); // first preference
connectionPolicy.PreferredLocations.Add(LocationNames.EastUS); // second preference
connectionPolicy.PreferredLocations.Add(LocationNames.NorthEurope); // third preference
With the connection policy the client developer can specify the order preferece list to take advantage of global distribution.
Name the 5 Consitency Levels for Azure Cosmos DB
Strong, Bounded staleness, Session, consistent prefix, Eventual
What is a Cosmos DB change feed?
Change feed support in Azure Cosmos DB works by listening to an Azure Cosmos container for any changes. It then outputs the sorted list of documents that were changed in the order in which they were modified. The changes are persisted, can be processed asynchronously and incrementally, and the output can be distributed across one or more consumers for parallel processing.