Azure Cosmos Db Flashcards

1
Q

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.

Choose the API that best supports the requirements.

A: Core (SQL)
B: MongoDB
C: Cassandra
D: Azure Table Storage
E: Gremlin (graph)
A

A: Core (SQL)

MongoDB might be a good second choice due to the document nature, but Core (SQL) is the best choice as there is no need to support existing MongoDB data or an existing application.

Cassandra isn’t a good fit as flexibility is needed - There isn’t a fixed schema,

Table Storage won’t work as this isn’t a simple key-value pair.

Gremlin is not correct as there is no requirement to store relationships or metadata on those links between items.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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 behaviour should be flagged.

Choose the API that best supports the requirements.

A: Core (SQL)
B: MongoDB
C: Cassandra
D: Azure Table Storage
E: Gremlin (graph)
A

E: Gremlin

Complex relationships, and needed to store metadata against them is best supported by a graph mode of data.

None of the other solutions offer this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

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.

Choose the API that best supports the requirements.

A: Core (SQL)
B: MongoDB
C: Cassandra
D: Azure Table Storage
E: Gremlin (graph)
A

C: Cassandra

The need to reuse existing CQL queries means that Cassandra is the best choice for in this scenario.

Core (SQL) would be a good second choice for this scenario.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the Default API for Cosmos DB

A

Core (SQL) is the default API for Azure Cosmos DB, which provides you with a view of your data that resembles a traditional NoSQL document store.

You can query the hierarchical JSON documents with a SQL-like language.

Core (SQL) uses JavaScript’s type system, expression evaluation, and function invocation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which API would be used for this query syntax?

db.Items.find({},{productName:1,_id:0})

A

Mongo DB

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What Cosmos DB Api would you use to provide a Graph like view of data in your database?

A

Gremlin (graph) API

Remember that at the lowest level, all data in any Azure Cosmos DB is stored in an ARS format.

A graph-based view on the database means data is either a vertex (which is an individual item in the database), or an edge (which is a relationship between items in the database).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The marketing team wants to be able to offer additional product recommendations while customers are browsing products on your e-commerce site.

For example, the team would like to provide suggestions like, “people who bought this product also bought that product”, and “people who viewed this product also are viewing that product.”

The products that are recommended first should be your most popular products, therefore a method needs to be provided that will enable ranking the relationships between products.

You decide tom implement a relational database using the SQL (Core) API

Would this solution meet the requirements?

A

No

It would be possible to model the relationship data in a NoSQL database; however, the lack of native queries that can answer the question, “How is this item related to that item?” means that this API isn’t the best choice.

The data store needs to be able to assign weight values to the relationships between products.

For example, you might store a count of the number of times that a relationship occurs.

With that in mind, each time that a person buys “Product A” and “Product B”, the relationship link between these two products needs to be incremented. This relationship counter is meta-data.

A graph database is the perfect fit to model this kind of data. Gremlin, the graph query language, will support the requirements.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

The operations team has been using an app that uses an existing MongoDB database to process purchase orders. The database captures data throughout the order process, including failed and partial orders, fulfillment data, and shipping status.

MongoDB was chosen because each supplier wanted their orders in different formats. In addition, each supplier returns different meta-data.

The volume of these suppliers has increased exponentially as your company has rolled out drop shipping.

The operations team wants to keep access to this data, and continue to use their current purchase order system with as few code changes and as little downtime as possible.

You decide to implement a MongDB API

Would this solution meet the requirements?

A

Yes

The operations team has semi-structured data that needs the flexibility to store many different supplier order formats.

Both Core (SQL) and MongoDB are good options.

However, your operations team wants to reduce downtime during their app migration, so your best bet would be to find a way to allow your operations team to continue to use the MongoDB wire protocol.

Azure TableAPI isn’t a good choice for this scenario, and should only be used to allow existing apps that are based on the Table API access to Azure Cosmos DB.

Cassandra API isn’t a good choice due to the existing MongoDB database, and the requirement to import and reuse application code.

Gremlin API isn’t a good choice because the data isn’t graph based.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Your web analytics team is using a third-party web analytics application that uses a Cassandra database, and the team has experience writing Cassandra Query Language (CQL) queries to produce their own reports.

You decide to use Mongo DB api
Would this solution meet the requirements?

A

No

The flexibility of a document-based data store is not enough of a reason to use MongoDB.

Since the web team is already using their Cassandra-based application, and because of their prior experience using the Cassandra Query Language (CQL) for some of their reporting, Cassandra is the right choice for this scenario, although Core (SQL) is still a close second choice.

All of the requirements for your web analytics application can be satisfied by Core (SQL), which makes your decision difficult when choosing between Core (SQL) and Cassandra.

Azure TableAPI isn’t a good choice for this scenario, and should only be used to allow existing apps that are based on the Table API access to Azure Cosmos DB.

Gremlin API isn’t a good choice because the data isn’t graph based.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The project architect has asked you to determine the advantages of moving data from an existing Azure Table Storage data set.

The project architect found an existing 10 TB database that one of the project teams uses to store data from a legacy Internet of Things (IoT) application, and the data is seldom updated.

Moving your database from Azure Table Storage into Azure Cosmos DB with a low throughput could have considerable cost savings, since Table Storage is charged on the size of data rather than how often it is accessed.

Should you recommend moving to Azure Cosmos DB?

A

No

The IoT data consists of key-value pairs with no relationship information, and the existing dataset is currently deployed in Azure Table Storage.

The best practice is to use Core (SQL) for new projects, as it has more features than the Azure Table API.

However, to reduce downtime during your migration to Azure Cosmos DB, you might want to consider using the Table API for now, and switch to Core (SQL) sometime in the near future.

Core (SQL) This API would be the best choice if you were designing a new system; however, since this scenario consists of a legacy application with a large existing Azure Table Storage dataset, the Azure Table API is the correct choice.

Gremlin This API isn’t a good choice because this scenario doesn’t need to process graph-based data, and because of the requirements to import and reuse application code.

MongoDB This API isn’t a good choice because of the existing Azure Table Storage database, and because of the requirements to import and reuse application code.

Cassandra This API isn’t a good choice because of the existing Azure Table Storage database, and because of the requirements to import and reuse application code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True or false: the benefits of writing to multiple regions are decreased latency, unlimited scaling potential, and improved availability.

A

True

Writing to multiple regions has many performance benefits. For example, the latency for write operations is less than in non-multi-master accounts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the default conflict-resolution policy in a multi-master account?

A: Last-Writer-Wins
B: A custom user-defined procedure

A

A: Last Writer Wins
Conflict resolution is built-in to Azure Cosmos DB and is performed on the server, inside the database engine. Last-Writer-Wins is the default policy.

User-defined procedures are supported, but they are not the default mechanism for handling conflicts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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.

A: Strong
B: Bounded Staleness
C: Session
D: Consistent Prefix
E: Eventual
A

C: 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.

Strong consistency is not available for databases replicated in multiple regions.

Bounded Staleness may result in only some of the users items being displayed in their basket.

Consistent Prefix could result in only some of the users items being displayed in their basket.

Eventual consistency might result in a situation in which a shopping basket didn’t display all the items the user had placed in it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which consistency level consumes the least amount of request units per operation?

A: Strong
B: Bounded Staleness
C: Session
D: Consistent Prefix
E: Eventual
A

Eventual

The cost of a read operation with eventual consistency consumes the least number of request units per seconds.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Strong consistency

A

Strong consistency offers a linearizability guarantee with the reads guaranteed to return the most recent version of an item.

Strong consistency guarantees that a write is only visible after it is committed durably by the majority quorum of replicas. A write is either synchronously committed durably by both the primary and the quorum of secondaries, or it is aborted. A read is always acknowledged by the majority read quorum, a client can never see an uncommitted or partial write and is always guaranteed to read the latest acknowledged write.

You can have an Azure Cosmos account with strong consistency and multiple write regions. However, the benefits such as low write latency, high write availability that are available to multiple write regions are not applicable to Cosmos accounts configured with strong consistency, because of synchronous replication across regions. For more information, see Consistency and Data Durability in Azure Cosmos DB article.

The cost of a read operation (in terms of request units consumed) with strong consistency is higher than session and eventual, but the same as bounded staleness.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Bounded Staleness consistency

A

Consistent Prefix. Reads lag behind writes by at most k prefixes or t interval.

17
Q

What is Session consistency

A

Within a single client session reads are guaranteed to honor the consistent-prefix, monotonic reads, monotonic writes, read-your-writes, and write-follows-reads guarantees.

This assumes a single “writer” session or sharing the session token for multiple writers.

Clients outside of the session performing writes will see the following guarantees:

Consistency for clients writing to multiple regions for a account with multiple write regions = Eventual

Consistency for clients in same region for an account with single write region = Consistent Prefix

Consistency for clients in different regions for an account with single write region = Consistent Prefix

Consistency for clients writing to a single region for an account with multiple write regions = Consistent Prefix

18
Q

What is Consisten Prefix consistency

A

Updates returned are some prefix of all the updates, with no gaps. Guarantees that reads never see out-of-order writes.

19
Q

What is Eventual Consistency

A

There’s no ordering guarantee for reads. In the absence of any further writes, the replicas eventually converge.

Eventual consistency is the weakest form of consistency because a client may read the values that are older than the ones it had read before.

Eventual consistency is ideal where the application does not require any ordering guarantees. Examples include count of Retweets, Likes, or non-threaded comments.

20
Q

A development team is developing an application. The application will be storing its data in Azure Cosmos DB – Table API. Below are the fields that are going to be stored in the table.

Region
Email address
Phone number
Below are some key aspects with respect to the fields

The region field will be used to load balance the data
There is a chance that some entities may have blank email.
The following snippet of code needs to be completed that would be used to retrieve a particular data entity from the table

class Customer : TableEntity {

    public Customer(string Region, string Phone)
    {
        PartitionKey = Region;
        RowKey = [Slot2];
    } 
}

Which of the following will go into Slot2?

A: Region
B: Phone
C: Email
D: Key

A

Phone

It states that Email might be blank

(also Phone is clearly shown as the parameter in the Constructor)

21
Q

A development team is developing an application. The application will be storing its data in Azure Cosmos DB – Table API. Below are the fields that are going to be stored in the table.

Region
Email address
Phone number

Below are some key aspects with respect to the fields

The region field will be used to load balance the data
There is a chance that some entities may have blank phone numbers.

The following snippet of code needs to be completed that would be used to retrieve a particular data entity from the table

provate static void ReadCustomer_keys ([Slot3] whizzlabs_table, string p_partitionkey, string p_rowkey){
TableResult result - whizzlabs_table.Execute(query)
}

Which of the following will go into Slot3?
A CloudTable
B .CloudTableClient
C. TableEntity
D: TableEntityAdapter
A

Answer – A

Since we are passing in a table parameter, and this would be a reference to our cloud table, we would need to use the CloudTable data type.

https://docs.microsoft.com/en-us/rest/api/storageservices/understanding-the-table-service-data-model

22
Q

Your application uses a Cosmos DB account with the MongoDB API to store confidential documents.

You need to give permission to other developers to create new databases and containers in Cosmos DB without allowing them access to confidential documents.

Which role-based access control (RBAC) role should you use?

A: Cosmos DB Account Reader
B: DocumentDB Account Contributor
C: Cosmos DB Operator
D: Cosmos Backup Operator

A

You should use the Cosmos DB Operator role. You can create Cosmos DB accounts, databases, and containers with this role. However, you cannot access the data from any Cosmos DB account with this role.

You should not use the DocumentDB Account Contributor role. You can manage Cosmos DB accounts with this role, including managing databases, containers, and master keys. You can access the confidential documents data with the master key.

You should not use the Cosmos DB Account Reader role. You can have access to read-only keys in Cosmos DB with this role. You cannot create new databases and containers with this role.

You should not use the Cosmos Backup Operator role. You can backup or restore databases or containers in Cosmos DB with this role. You cannot create new databases and containers with this role.

https: //docs.microsoft.com/en-us/azure/cosmos-db/role-based-access-control
https: //docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles

23
Q

Which consistency model provides the Lowest Latency and the highest availability?

A

You should use the eventual consistency level. This level provides the lowest latency and the higher availability for data reads because it does not guarantee the ordering of reads, but this is not an issue for a static database that will not be receiving new data writes.

24
Q

Which consistency model ensures that reads never see out of order rights??

A

You should use the consistent prefix level. This level ensures that reads never see out-of-order writes. However, this level has more latency and less availability than the eventual consistency level.

25
Q

Which consistency model ensures reads honor consistency guarantees including the consistent-prefix, monotonic reads, monotonic writes, read-your-writes, and write-follows-reads

A

You should use the session consistency level. This level ensures reads honor consistency guarantees including the consistent-prefix, monotonic reads, monotonic writes, read-your-writes, and write-follows-reads. However, this level has more latency and less availability than the consistent prefix consistency level.

26
Q

Which consistency model allows you to control how far reads might lag behind writes in terms of update versions (K) or time (t)

A

You should use the bounded staleness consistency level. This level reads might lag behind writes based on configured update versions (K) or time (t) and have more latency and less availability than the session consistency level.

27
Q

Which consistency model ensures clients always see the most recent commited version of an item?

What are the trade offs?

A

You should use the strong consistency level. This level reads always return the most recent committed version of an item. However, this level has more latency and less availability than the bounded staleness consistency level.

28
Q

ou have an instance of IDatabase named database that represents a valid connection to an Azure Redis Cache. No items are currently stored in the cache.

You need to determine the number of clients connected to the cache.

Which code segment should you use?

var info = database.Execute("INFO");
var result = database.Ping(CommandFlags.FireAndForget);
var streamInfo = database.StreamInfo("CLIENTS");
var clients = database.StringGet("connected_clients");
A

You should use the following code:

var info = database.Execute(“INFO”);

The Execute method allows you to issue commands to an Azure Redis Cache. If you issue the INFO command, the response is a collection of lines of text that describe information about the cache in the form of key:value pairs. The connected_clients key specifies the number of clients connected to the cache.

You should not use the following code:

var streamInfo = database.StreamInfo(“CLIENTS”);

The StreamInfo method allows you to retrieve information about a stream. It does not allow you to retrieve the number of connected clients.

You should not use the following code:

var result = database.Ping(CommandFlags.FireAndForget);

The Ping method allows you to issue the PING command to determine connectivity or latency to the cache. It does not allow you to retrieve the number of connected clients.

You should not use the following code:

var clients = database.StringGet(“connected_clients”);

The StringGet method returns the value of a string key in the cache. It does not allow you to return the number of connected clients unless you specifically set that data in the cache. However, in this scenario, no items are currently set in the cache.