0% found this document useful (0 votes)
121 views

Cosmos DB - July 2019

This document provides an overview of Cosmos DB, including: - Cosmos DB can store multiple data structures like documents, key-value pairs, and graphs. - It offers global distribution, varying throughput levels, consistency models, and performance SLAs. - It has SQL, MongoDB, Table, Cassandra, Gremlin APIs. - Data is partitioned and replicated for high availability across regions. - Consistency levels include strong, bounded staleness, session, and eventual. - Cosmos DB is fully managed with auto-indexing and elastic scaling of throughput.

Uploaded by

B4H TV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
121 views

Cosmos DB - July 2019

This document provides an overview of Cosmos DB, including: - Cosmos DB can store multiple data structures like documents, key-value pairs, and graphs. - It offers global distribution, varying throughput levels, consistency models, and performance SLAs. - It has SQL, MongoDB, Table, Cassandra, Gremlin APIs. - Data is partitioned and replicated for high availability across regions. - Consistency levels include strong, bounded staleness, session, and eventual. - Cosmos DB is fully managed with auto-indexing and elastic scaling of throughput.

Uploaded by

B4H TV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 49

Cosmos DB

Fundamentals
Jes Borland

Software Engineer @
Microsoft
[email protected]
@grrl_geek
LessThanDot.com
Cosmos DB isn’t another SQL Server flavor in “the
cloud”!
 Cosmos DB is for NoSQL data
 Not relational, not highly structured

 This one data store has a common model for multiple types of data
structures
What kind of data can be stored?

Document Document
(SQL) (MongoDB)

Table Etcd
(Key/Value) (Key/Value)

Wide column Graph


(Cassandra) (Gremlin)
Benefits of Cosmos DB
 Globally distributed
 Offers varying levels of throughput
 Offers multiple consistency models
 Has performance SLAs
 Performs automatic indexing
 Fully managed Azure fabric
APIs
SQL
 The SQL API started life as DocumentDB - a JSON database engine with a
query language that will look familiar to those used to T-SQL
SQL API Use Cases
 Anything that generates JSON data!
 IOT
 Retail
 Gaming
MongoDB
 Mongo is an open-source document database which uses JSON-like
documents
 Existing Mongo databases can have data imported directly, then the
applications that use them can be pointed to Cosmos DB
 Existing tools like Mongo Shell can be used with Cosmos DB
MongoDB API Use Cases
 Content Management Systems (CMS)
 Timekeeping
 IOT
Table
 The Table API directly interacts with Azure Table Storage, which is
key/value pairs
 Gives additional features that Storage alone can't such as global
distribution, higher throughput
Table API Use Cases
 Replace Redis (an application caching program)
 Games and scores per player
 Shopping carts
 Analytics materialized view for specific dates
Etcd
 In Kubernetes, etcd is used to store the state and the configuration of the
Kubernetes clusters.
 Ensuring availability, reliability, and performance of etcd is crucial to the
overall cluster health, scalability, elasticity availability, and performance of
a Kubernetes cluster.
Cassandra
 Apache Cassandra is a distributed, wide column store database
 “Wide column store” has tables with rows and columns, but names and
format of columns vary from row to row in the same table
 Developed at Facebook to power the inbox search feature
Cassandra API Use Cases
 Systems where writes exceed reads
 Transaction logging
 Package tracking
 IoT
Graph
 Graph is a non-relational data store
that lets you define entities (vertices),
and the relationships between them
(edges)
 Uses the Apache TinkerPop language
"Gremlin"
 It's very different from SQL!
Graph API Use Cases
 Social networks
 Vertices - people
 Edges - relationships

 Recommendations
 Vertices - restaurant, location, cuisine type
 Edges - cuisine type, distance to specific location

 Logistics
 Vertices - airports
 Edges - flights
Cosmos DB Infrastructure
Resource Model
Horizontal Partitioning
 Partitioning maps data to physical
storage
 You choose a logical partitioning
key
 Choose wisely
 The partition key will determine how data is
returned when you query it later
Partition guidance and performance
 Queries that access data in a single logical partition are more cost-effective
than queries that access multiple.
 Transactions are allowed only against a single logical partition.
 The best choice is something with high cardinality
 What is high cardinality? More uniqueness.
 Binary is low cardinality - true/false
 Unique ID is high cardinality
 First name may be somewhere between
Partitioning questions
 Can I change the partitioning key?
 No. You would have to create a new collection with the new partition key, and move the data.
Global Distribution
 Global distribution is how the data is
replicated to the regions you choose
 You can choose automatic or manual
failover between regions
 This can be set in the Azure Portal, or
in the application's ConnectionPolicy
parameter
Multi-master writes
 Write-anywhere model
 < 10 ms latency and 99.999 % write availability
Consistency Levels
 SQL Server has isolation levels  Cosmos DB has consistency levels
 Read Uncommitted  Eventual
 Read Committed  Consistent prefix
 Repeatable Read  Session
 Snapshot  Bounded stateless
 Serializable  Strong
Strong
 A write is only visible after it's committed to a majority quorum of replicas
 Reads are guaranteed to return the most recent version
 Can only be used in one region
 Examples
 Banking accounts
 Payment processing
 Reservation systems

“Absolute truth every time”


Bounded stateless
 Reads can lag behind writes in a "staleness windows"
 K versions
 t time interval

 Global total order outside of that window


 Recommended for globally-distributed applications
 Examples
 Flight status app
 Package tracking app

“Not too old”


Session
 Consistency is scoped to a single session
 Guarantees RYW - read your own writes
 Examples
 Social profile updates
 Retail shopping cart
 Social music app preferences

“Logical, real-time experiences for a user”


Constant Prefix
 If there are no more writes, all replicas will have the same data
 ….and in the correct order
 Examples
 Baseball score updates
 Social media comments

“The order of the data tells as much of a story as the end result”
Client Jes
1 sees: Erin

Jes
App Erin Jes
Client
writes: Sarah
2 sees:

Jes
Client Erin
3 sees: Sarah
Eventual
 Eventually, with no further writes, all replicas in a group eventually
converge
 A session may get values older than what it saw on a previous read
 Examples
 Product reviews
 Social media following posts
 Receipts

“Apps that live and die according to their availability”


Throughput
 Request Units
 CPU + memory + IOPs
 Similar to a SQL Database DTU

 A 1-RU throughput corresponds to the throughput of the GET of a


1-KB document
 Each operation (create, update, delete, read, query) requires X RUs for each
consistency level
 CRUD are consistent
 SELECT returning X rows - these depend on X
 The query explorer in the Portal will show you how many RUs a query used
Viewing Metrics
Working with Cosmos DB
I'm the DBA...hold me, I'm scared
 High Availability
 All writes are durably committed to local disks by a quorum of replicas within a local data
center before acknowledging to the client
 Each partition is made highly available via a replica set

 Disaster Recovery
 Choose multiple regions for DR
Backup and restore
 Backups
 Full backups taken approximately every 4 hours
 The last 2 backups are stored at all times in Azure Blob storage
 Stored in same region as your current write region
 Replicated to another region via GRS
 "If the data is accidentally dropped or corrupted, contact Azure support within eight hours."

 Restores
 File a support ticket or call Azure support
Security
 Policy-driven IP-based access controls for inbound firewall support
 Using the master key for the account, you can create user resources and
permission resources per database
 Data is encrypted at rest
 All client-to-service Azure Cosmos DB interactions are SSL/TLS 1.2
capable. All intra datacenter and cross datacenter replication is SSL/TLS
1.2 enforced.
I'm the developer...hold me back!
 Quickstarts are available for all APIs in multiple languages

SQL MongoDB Graph Table


• .NET • Node.js • .NET • PHP
• Java • .NET • Gremlin console • .NET
• Node.js • Java • Java • Java
• Python • Golang • Node.js • Node.js
• Xamarin • Python • Python • Python
Let's play
 Azure Cosmos DB Emulator
https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator
 Quickstart: SQL API + .NET
https://docs.microsoft.com/en-us/azure/cosmos-db/create-sql-api-dotnet
Demo
 Open Azure Cosmos DB Emulator
 Open Visual Studio
 Emulator – click Explorer, click New Collection
 Database id – Create new – Tasks
 Collection id – Items
 Storage – Fixed
 Throughput – 400
 OK
Demo 2
 Click Items > Documents > New  {

Document  "id": "2",


 {  "category": "workout",
 "id": "1",  "name": "spin",
 "category": "personal",  "description": "12:10 spin class",
 "name": "groceries",  "isComplete": false
 "description": "Pick up apples and  }
strawberries.",  One more, category “personal”
 "isComplete": false
 }

 Save
 New
Demo 3
 Click Edit Filter button.
 Add ORDER BY c._ts DESC

 Click New SQL Query


 SELECT * FROM c WHERE c.category = "workout"
Demo 4
 Visual Studio > Open Project/Solution > C:\git-samples\documentdb-
dotnet-todo-app > todo.sln
 Open web.config
 <add key="endpoint“ – add URI
 <add key="authKey“ – add Primary Key
 <add key="database" – add Database name Tasks
 <add key="collection“ – add Collection name Items

 Run app – F5 or green arrow with “Microsoft Edge”


 Click Create New
 Baking
 Make zucchini bread
 Personal
 Create
Demo 5
 Emulator > Explorer > New SQL Query
 SELECT c.id, c.name, c.description, c.isComplete FROM c WHERE c.category = "personal"

 Close Edge
 Stop program
 Close VS
 Close Emulator
Why Cosmos DB?

Scalable up/down
Distributed
for surges and
worldwide
dips in usage

Flexible with Meets or exceeds


consistency performance
models SLAs
Resources
• Azure Cosmos DB product page -
https://azure.microsoft.com/en-us/services/cosmos-db/
• Documentation - https://docs.microsoft.com/en-us/azure/cosmos-db/
• eBook - https://discover.microsoft.com/apps-for-cats/ (Highly
recommended, less than half an hour to go through.)
• SLAs
https://azure.microsoft.com/en-us/support/legal/sla/cosmos-db/v1_2/
Questions?
Jes Borland
Premier Field Engineer
Microsoft
[email protected]
@grrl_geek
LessThanDot.com

You might also like