Cosmos DB - July 2019
Cosmos DB - July 2019
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)
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
“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
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
Save
New
Demo 3
Click Edit Filter button.
Add ORDER BY c._ts DESC
Close Edge
Stop program
Close VS
Close Emulator
Why Cosmos DB?
Scalable up/down
Distributed
for surges and
worldwide
dips in usage