Cosmos DB Flashcards
Benefits of NOSQL
(1) Fluid Schema
(2) Multiple Structures
(key value, graph, document, wide-column)
(3) Horizontal scaling
(4) Provides BASE
(Basically available software state, eventual consistency
(5) Non-normilized data
If transaction volumes are very high such as many thousand transactions per second, you should consider a distrubuted NOSQL
What are Cosmos DB capabilities?
(1) Provides extremely low latency (single digit milliseconds)
(2) Provides SLA for throughput, latency, availability, and consistency
(3) Support multi-region replication at any point
(4) Enables elastic scalability
(5) Pricing is for the throughput provision *
Additional features: Integrated analytics, region support, schema agnostic, automatic indexing and support for multiple SDK
There is a serverless approach in preview but for now the price is dependent on Throughput
Cosmos DB Organization
Cosmos DB Account
Database
Container
Item(s)
What are the 5 available DB APIs
(1) SQL
(stores data in JSON format)
(2) Cassendra
(Want to leverage the CQL Query Lanague, wide-column format, already using Cassendra)
(3) MongoDB
(Already using MongoDB, familar, and stores in JSON)
(4) Gremlin
(Graph database, Apache Tinerpop’s Gremlin language)
(5) Azure Table
(Experience with Azure Tables and need to migrate to Cosmos, familar with querying using OData or LINQ Queries
Use the SQL version if Cassendar, MongoDB, or Gremlin fit your needs)
What is the entity and container for SQL?
Database/Container
What is the entity and container for Cassendra?
Keyspace/Table
What is the entity and container for MongoDB?
Database/Collection
What is the entity and container for Gremlin?
Database/Graph
Wha is the entity and container for Azure Table?
Not applicable (auto generated)/Table
Azure CLI to create a Cosmos DB
Resource Group
az group create –name $rgname –location $location
Create a DB Account with SQL API
az cosmosdb create –name $acctname –resource-group $rgname
Create a SQL Database
az cosmosdb sql database create –account-name $acctname –name $db
Create the Container
az cosmosdb sql container create –resource-group $rgname
–account-name $accountname –database-name $db –name $containername
In the Portal, you can create your own partition key. Not sure if CLI has this option?
What is a Request Unit?
A Request Unit encapsulates many of the resources needed for a the database into a single unit.
As a baseline, one RU equals one 1kb item read operation
What are the resources encapsulated in the RU?
Processing Power (CPU)
Memory
IOPS (inputs/outputs per second)
What are the characteristics of Provisioned CosmosDB
(1) Ideal for production
(2) Can be configured at database or container level
(3) Throughput evenly distributed to partitions
(4) Requires 10 RU’s per GB of storage
(5) Once RU’s have been reached, future requests are rate limited
If limited reached, responses show incomplete message
Scaling in Cosmos DB
Scaling is manual and is recommended to set an alert when reaching your limit
Autoscaling is available, you can specify a maximum amount. The minimum throughput is calculated as 10% of the maximum. (You do not want to set to high and pay for throughout not using!)
What is the serverless Cosmos DB features?
(1) Pay for what you consume and store
(2) ideal for development
(3) Max 5000 RU’s
(4) Requires a new Account Type
(5) Only supports SQL API
What are the best practices for Cosmos DB
(1) Use a partition strategy to evenly spead througput on partitions
(2) Provision throughput at the container level for predictiable performance
(3) Use the serverless account for development
(4) Understand the link between consistency types and the amount of RU’s Consumed
What are the consistency levels
(1) Eventual
(2) Consitent Prefix
(3) Session
(4) Bounded Staleness
(5) Strong
Consistency
Provides no guarantee for order and that you would even see your own writes
Eventual
Consistency
Guarantees that updates are returned in order
Consistent Prefix
Guarentees that a client session will read it’s own writes
Session
Guarantees that a read has a max lag and receive a fairly recent version
Bounded Staleness
Guarantees that reads get the most receipt version on an item
Strong
Consistency level for SQL API
Request specific level added to your query
Set at the Account Level
Important
No Answer
What types of partitioning concepts are there?
Logical
Physical
Partition Key
Replica Set
What are the chararistics of a Logical partition
A logical partition is a set of items that share the same partition key.
A container can hasve a many logical partition keys as needed but each one is limited to 20GB of storage.
Logical partitions are managed by Cosmos DB (but governed by your partition key stategey)
What are the chararistics of a physical partition?
A container that is scaled by distributiong data and througput across physical partitions and is manged by Azure Cosmos DB
What are the characteristics of a partition key?
Managed by user and serves as the means of routing your request to the correct partition.
Made up of both key and value of the defined partition key
SHOULD BE A VALUE THAT DOES NOT CHANGE
Should have many different values represented in the container
What are the characteristics of a replica set?
A physical partition contains **multiple replicas **of the data and enable your storage to be durable and fault tolerant.
What are the Stategy Considerations
(1) Hot Partition
(2) Multiple transactions requires triggers or stored procedures
(3) Minimize cross partition queries for heavier workloads
(4) Decide on partition key stategey before creating container
Incomplete
Server Side Programming with Cosmos DB