SlideShare a Scribd company logo
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Specialties / Focus Areas / Passions:
• Performance Tuning & Troubleshooting
• Very Large Databases
• SQL Server Storage Engine
• HA/DR
• Cloud
@sqlbob
bob@bobpusateri.com
heraflux.com
bobpusateri
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
We were developing an IoT system
…Which needed to ingest data from thousands/millions of devices
… and that data needed to be queried within seconds?
We were building an e-commerce site
Which needed guaranteed performance and availability
… anywhere on Earth
… and needed to be able to scale up/down in response to conditions?
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
A globally distributed, massively scalable, multi-model database service
A globally distributed, massively scalable, multi-model database service
A globally distributed, massively scalable, multi-model database service
A globally distributed, massively scalable, multi-model database service
Key-Value GraphColumn-Family Document
A globally distributed, massively scalable, multi-model database service
Has multiple APIs as well
Table API
MongoDB
A database service featuring an engine built to excel at several things, but
especially:
Partitioning
Replication
It’s a NoSQL offering!
3 DBAS WALKED INTO
A NOSQL BAR….
A WHILE LATER THEY
WALKED OUT BECAUSE THEY
COULDN’T FIND A TABLE
• I often hear NoSQL == No Schema == No Design
▪ Not True
• GENERALLY NoSQL schemas
▪ Do Exist
▪ Are somewhat enforced by the database
▪ Are fully enforced by the application
• There are still design decisions that need to happen early on
▪ (And if they’re wrong you will pay for it later)
• Microsoft started having problems with internal large scale apps
▪ 2010 – “Project Florence”
▪ 2014 – Azure DocumentDB
▪ 2017 – Azure Cosmos DB
• MS leverages this internally
• Designed for the cloud
• One of the fastest-growing
services on Azure
https://tinyurl.com/ycmhp6kd
• We’re developing an internal app for a global company
• Thousands of users reading/updating data
• How would we architect this?
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
• Cosmos DB is a Foundational Azure service
• Put your data where the users are
• Replication between regions is automatic
• Multi-homing APIs
▪ Clients automatically connect to the nearest region
• Adding or removing regions? No code changes!
• Manual or automatic failovers
• Designed from the ground up for HA
• Both storage and throughput can be scaled transparently
• A single machine is never a bottleneck
• Collections can scale from GB to PB across many machines and regions
• Requests are served from the nearest region
• Database engine optimized for writes, latch-free
• Indexing is synchronous and automatic
• Single-digit millisecond latency at 99th Percentile
Reads (1KB) Indexed Writes (1KB)
50th Percentile < 2ms < 6ms
99th Percentile < 10ms < 15ms
• 99.99% availability when in a single region
• 99.999% availability in multiple regions
• Highly-redundant storage architecture
• Automatic or manual failover
• Will give you money back if they’re not met!
• https://azure.microsoft.com/en-us/support/legal/sla/cosmos-db/
• All data is encrypted, period.
• In transit and at rest
• Two types of keys:
• Master Keys
▪ Administrative
▪ Grant access to the entire account (not granular)
▪ Read-write and Read-only
• Resource Tokens
• Used for application resources (Containers, docs, SPs, Triggers, UDF, etc.)
▪ Kinda like SQL Permissions
• Tokens are specific to {user, resource, permission}
• Tokens are time-sensitive (default 1 hour, max 5 hours)
• Resource Tokens
DIRECT ACCESS
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Server
Object
Instance
Database
Account
Item
Database
Container
Account
Item
Database
Container
Account
Item
Database
Container
• Containers
• Users
• Permissions
Account
Item
Database
Container
• Data Model
• Document (Collection)
• Graph
• Key-Value
• Column-Value
• Throughput
Account
Item
Database
Container
• Data Model
• Document (Collection)
• Graph
• Key-Value
• Column-Value
• Throughput
ATOM RECORD SEQUENCE (ARS) SYSTEM
Atoms = primitives (string, bool, etc)
Records = structs of atoms
Sequences = arrays of {atom, record, sequence}
Cosmos DB translates & projects all data models
into an ARS model
Account
Item
Database
Container
Account
Item
Database
Container
• Depends on data model
• Document
• Node/Edge
• Row/Item
• Stored Procedures
• Triggers
• UDFs
Image: Microsoft
• RU is the rate-based currency of Cosmos DB
• Represents a combination of CPU, Memory, and IO
• 1 RU = 1 read of 1KB
• Every request is assigned a “cost” in RUs
▪ Reads, writes, stored procedures, etc
• Provisioned in units of RU/second
• Can be changed at any time; metered hourly
• Exceeding your RU budget = rate limiting
• When quiescent, background tasks run
▪ Index Maintenance
▪ TTL Expiration
Min RU/sec
Max RU/sec
RequestRate
Rate
Limiting
No
Limiting
Replica
Quiescent
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
• Define boundary values between partitions
• Map partitions to physical locations (filegroups)
• Similar values generally in the same partition
▪ Can lead to “hot” partitions
▪ Especially if on dates
• Partition management is manual
• Hard Limit: 15.000 partitions per table
• There are no “ranges”, every partition key is hashed
• Logical partitions (keys) are spread across physical partitions
• Partition management is automatic!
• No limit on number of partitions
• Hard limit: 10GB max of data per partition key
• The most important design decision in Cosmos DB
• Has a direct effect on
▪ How well it will scale
▪ How much you will pay
• Think through partitioning during the design phase, it’s easier!
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Partition Key: User ID
Cosmos DB Container
Partition Key: User ID
hash(User ID)
Pseudo-random data distribution of hash values
hash(User ID)
Chase
Ryder
Tracker
Cap’n Turbot
Everest
Skye
Rocky
Rubble
Zuma
Marshall
Robo-Dog
hash(User ID)
Chase
Ryder
Tracker
Cap’n Turbot
Everest
Skye
Rocky
Rubble
Zuma
Marshall
Robo-Dog
Physical
Partition
Logical
Partition
hash(User ID)
Chase
Ryder
Tracker
Cap’n Turbot
Everest
Skye
Rocky
Rubble
Zuma
Marshall
Robo-Dog
What happens when it needs to grow?
Tracker
Cap’n Turbot
Skye
Rocky
Robo-Dog
hash(User ID)
Tracker
Cap’n Turbot
Robo-Dog
Skye
Rocky+
Partitions can be dynamically subdivided
to grow the database without affecting
availability
This is done automatically.
• Plan to distribute both request and storage volume
▪ Remember the 10GB limit
▪ Adding dates after partition values can help with this
• For greatest efficiency, queries should eliminate partitions
• Queries can be routed/filtered via partition key
• “Fan-Out” is something to try to avoid where possible
• Understand your workload!
• Understand the most frequent/expensive queries
• Understand insert vs update ratios
• Remember partition keys are logical!
▪ Don’t be afraid of having too many
▪ More key values = better scalability
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
• This is huge because we have multiple replicas
• If a change is replicated, what is seen elsewhere?
• Why replicate, anyway?
▪ HA – multiple copies for failover
▪ Speed!
• Bring the data closer to the user
• “cheat” the speed of light!
Image: Microsoft
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
North Central US
UK South
Japan East
North Central US
UK South
Japan East
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
North Central US
UK South
Japan East
X
• Do we keep all the replicas online?
▪ One of them will be wrong?
• Do we shut down the stale replica?
▪ Sacrifice availability for correctness?
• Do we shut down everything?
▪ All or nothing?
• Relational Databases: ACID
▪ Atomic
▪ Consistent
▪ Independent
▪ Durable
• Distributed Systems: Brewer’s CAP Theorem
▪ Consistency
▪ Availability
▪ Partition tolerance
▪ (pick two)
• Problem: There’s no consistent definition of “consistent” in CS
• Transactions (ACID)
▪ Each transaction moves from a single valid state to another
• Replication (CAP)
▪ Getting a consistent view across replicated copies of data
▪ And CAP doesn’t even cover all cases….
• An extension of the CAP Theorem
• Partitioning: Availability vs. Consistency ELSE Latency vs. Consistency
• When partitioning a distributed system you have to choose between
availability and consistency, but also when not partitioning one must
choose between latency and consistency.
• Reader is far away from writer
• Value gets updated by writer
• Should the reader:
▪ See the old value? (prioritize latency)
▪ See the same result as the master?
▪ Wait for the new value (prioritize consistency)
• I love consistency models
• I also love isolation levels
• Azure Cosmos DB has 5 of them
• You can choose what gets prioritized
• Can be overridden on a per-request basis
Bounded
Staleness
Strong Consistent
Prefix
Session Eventual
• Linearizability guarantee: reads will always return the most recent version
of an item
• (Like SERIALIZABLE [maybe?])
• Writes are only visible after committed by a majority quorum of replicas
• If using this model, you are limited to a single Azure region
Bounded
Staleness
Strong Consistent
Prefix
Session Eventual
• Guarantees that “absence of any further writes, replicas will eventually
converge”
• No guarantee of order
▪ Client may get “new” values older than ones it had previously seen
• Lowest latency for reads and writes
▪ …but it’s fast!
Bounded
Staleness
Strong Consistent
Prefix
Session Eventual
• Guarantees that readers will always see writes in order
Bounded
Staleness
Strong Consistent
Prefix
Session Eventual
• Scoped to a client session
▪ There’s a session key that is passed around
• Provides predictable consistency within a session
▪ Monotonic reads & writes
▪ Guarantee that you can read your own writes immediately
• Great predictability for your session, good performance for everyone else
Bounded
Staleness
Strong Consistent
Prefix
Session Eventual
• Define a “window” of staleness in terms of # revisions or time
• If a replica gets too far behind (is outside the “window”)
▪ Cosmos DB will prioritize consistency over all else
▪ May even rate limit writes until stale replica catches up
Bounded
Staleness
Strong Consistent
Prefix
Session Eventual
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
• What if you’re not doing geo-replication? Does this matter?
• Yes it does!
• Even in local regions there are still 4 replicas of your database
1
2 3
4
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
• Yeah, about that….
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
• Schema-agnostic
• Automatic
▪ Every property of every record is indexed by default
▪ No latches involved (remember it’s highly write-optimized)
• Customizable
▪ You can define what is indexed (and save space)
{ "cars": [
{ "make": "Hyundai", "model": "Santa Fe" },
{ "make": "Subaru", "model": "Forester", “plate": "T SQL" }
],
"city": "Chicago"
}
city
Chicago0 1
make model make model license
cars
Hyundai
Santa
Fe
Subaru Forester T SQL
{ "cars": [
{ "make": "Tesla", "model": "X" }
],
"city": “Oslo"
}
city
Oslo0
make model
cars
Tesla X
city
Chicago0 1
make model make model license
cars
Hyundai
Santa
Fe
Subaru Forester T SQL
Oslo
{1,2}
{1,2}{1,2}
{1} {2}{1,2} {1}
Tesla X
{1,2} {1,2}
{1} {1}{2} {2} {1} {1} {1}
{1} {1}{1}
Term Postings
$/cars/0 1,2
$/cars/0/make 1,2
$/cars/0/model 1,2
$/cars/1 1
……
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
• Remember what I said about indexes?
• Backups are automatic
• Snapshots taken and stored separately in Azure Blob Storage
• For speed, it’s written to same region as current Cosmos DB write region
• For safety, it’s replicated to another region as well
• Taken every 4 hours
• Only the last 2 snapshots are retained
• “If the data is accidentally dropped or corrupted, contact Azure support
within eight hours.”
• You can maintain your own backups
▪ Azure Cosmos DB Data Migration Tool “export to JSON” option
• If you delete a container/database, backups retained for 30 days
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
https://docs.microsoft.com/en-us/azure/cosmos-db/use-cases
Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)
• You Pay For:
▪ Storage (2,0286 kr per GB/month)
▪ Throughput (0,065 kr per 100 RUs/hour)
▪ Data Transfer for geo-replication (varies by region)
▪ West Europe: 0,706 kr per GB
• Check Azure Portal for most current pricing info
• https://azure.microsoft.com/en-us/pricing/details/cosmos-db/
• There’s a Cosmos DB Emulator!
• Run locally on your machine for free
• https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator
• There’s a Cosmos DB Emulator!
• Run locally on your machine for free
• https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator
106
@sqlbob
bob@bobpusateri.com
bobpusateri.com
bobpusateri

More Related Content

What's hot (20)

PPTX
Azure data platform overview
Alessandro Melchiori
 
PPTX
HA/DR options with SQL Server in Azure and hybrid
James Serra
 
PDF
Data Platform Overview
Hamid J. Fard
 
PDF
Azure cosmos db
Bill Liu
 
PPT
Cloudant Overview Bluemix Meetup from Lisa Neddam
Romeo Kienzler
 
PPTX
SQL to NoSQL: Top 6 Questions
Mike Broberg
 
PPTX
Introduction to azure cosmos db
Ratan Parai
 
PDF
0812 2014 01_toronto-smac meetup_i_os_cloudant_worklight_part2
Raul Chong
 
PDF
Azure Cloud Dev Camp - Introduction
giventocode
 
PPTX
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp
 
PPTX
Introduction to Windows Azure Data Services
Robert Greiner
 
PPTX
How SQL Server 2016 SP1 Changes the Game
PARIKSHIT SAVJANI
 
PDF
Temporal Tables, Transparent Archiving in DB2 for z/OS and IDAA
Cuneyt Goksu
 
PDF
Microsoft SQL server 2017 Level 300 technical deck
George Walters
 
PPTX
Azure Data platform
Mostafa
 
PPTX
Overview of Microsoft Appliances: Scaling SQL Server to Hundreds of Terabytes
James Serra
 
PDF
Azure SQL Database
rockplace
 
PPTX
Azure SQL Managed Instance - SqlBits 2019
Jovan Popovic
 
PPTX
IaaS for DBAs in Azure
Kellyn Pot'Vin-Gorman
 
PPTX
SQL Azure the database in the cloud
Eduardo Castro
 
Azure data platform overview
Alessandro Melchiori
 
HA/DR options with SQL Server in Azure and hybrid
James Serra
 
Data Platform Overview
Hamid J. Fard
 
Azure cosmos db
Bill Liu
 
Cloudant Overview Bluemix Meetup from Lisa Neddam
Romeo Kienzler
 
SQL to NoSQL: Top 6 Questions
Mike Broberg
 
Introduction to azure cosmos db
Ratan Parai
 
0812 2014 01_toronto-smac meetup_i_os_cloudant_worklight_part2
Raul Chong
 
Azure Cloud Dev Camp - Introduction
giventocode
 
ITCamp 2019 - Andy Cross - Machine Learning with ML.NET and Azure Data Lake
ITCamp
 
Introduction to Windows Azure Data Services
Robert Greiner
 
How SQL Server 2016 SP1 Changes the Game
PARIKSHIT SAVJANI
 
Temporal Tables, Transparent Archiving in DB2 for z/OS and IDAA
Cuneyt Goksu
 
Microsoft SQL server 2017 Level 300 technical deck
George Walters
 
Azure Data platform
Mostafa
 
Overview of Microsoft Appliances: Scaling SQL Server to Hundreds of Terabytes
James Serra
 
Azure SQL Database
rockplace
 
Azure SQL Managed Instance - SqlBits 2019
Jovan Popovic
 
IaaS for DBAs in Azure
Kellyn Pot'Vin-Gorman
 
SQL Azure the database in the cloud
Eduardo Castro
 

Similar to Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018) (20)

PDF
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Bob Pusateri
 
PDF
Select Stars: A SQL DBA's Introduction to Azure Cosmos DB (SQL Saturday Orego...
Bob Pusateri
 
PDF
Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...
Andre Essing
 
PDF
Modeling data and best practices for the Azure Cosmos DB.
Mohammad Asif
 
PPTX
Technical overview of Azure Cosmos DB
Microsoft Tech Community
 
PDF
Azure Cosmos DB - The Swiss Army NoSQL Cloud Database
BizTalk360
 
PDF
CosmosDB for DBAs & Developers
Niko Neugebauer
 
PDF
Azure Cosmos DB - Technical Deep Dive
Andre Essing
 
PPTX
Azure CosmosDb
Marco Parenzan
 
PPTX
Tech-Spark: Exploring the Cosmos DB
Ralph Attard
 
PPTX
cosmodb ppt.pptxfkhkfsgkhgfkfghkhsadaljlsfdfhkgjh
Central University of South Bihar
 
PPTX
Azure CosmosDb - Where we are
Marco Parenzan
 
PPTX
Azure Cosmos DB + Gremlin API in Action
Denys Chamberland
 
PDF
Dealing with Azure Cosmos DB
Mihail Mateev
 
PPTX
Quick trip around the Cosmos - Things every astronaut supposed to know
Rafał Hryniewski
 
PPTX
cosmodb ppt personal.pptxgskjhkjsfgkhkjgskhk
Central University of South Bihar
 
PDF
CosmosDB for IoT Scenarios
Ivo Andreev
 
PPTX
Tour de France Azure PaaS 3/7 Stocker des informations
Alex Danvy
 
PPTX
Cosmos db
Martino Bordin
 
PDF
Cosmos DB at VLDB 2019
Dharma Shukla
 
Select Stars: A DBA's Guide to Azure Cosmos DB (Chicago Suburban SQL Server U...
Bob Pusateri
 
Select Stars: A SQL DBA's Introduction to Azure Cosmos DB (SQL Saturday Orego...
Bob Pusateri
 
Azure Cosmos DB - NoSQL Strikes Back (An introduction to the dark side of you...
Andre Essing
 
Modeling data and best practices for the Azure Cosmos DB.
Mohammad Asif
 
Technical overview of Azure Cosmos DB
Microsoft Tech Community
 
Azure Cosmos DB - The Swiss Army NoSQL Cloud Database
BizTalk360
 
CosmosDB for DBAs & Developers
Niko Neugebauer
 
Azure Cosmos DB - Technical Deep Dive
Andre Essing
 
Azure CosmosDb
Marco Parenzan
 
Tech-Spark: Exploring the Cosmos DB
Ralph Attard
 
cosmodb ppt.pptxfkhkfsgkhgfkfghkhsadaljlsfdfhkgjh
Central University of South Bihar
 
Azure CosmosDb - Where we are
Marco Parenzan
 
Azure Cosmos DB + Gremlin API in Action
Denys Chamberland
 
Dealing with Azure Cosmos DB
Mihail Mateev
 
Quick trip around the Cosmos - Things every astronaut supposed to know
Rafał Hryniewski
 
cosmodb ppt personal.pptxgskjhkjsfgkhkjgskhk
Central University of South Bihar
 
CosmosDB for IoT Scenarios
Ivo Andreev
 
Tour de France Azure PaaS 3/7 Stocker des informations
Alex Danvy
 
Cosmos db
Martino Bordin
 
Cosmos DB at VLDB 2019
Dharma Shukla
 
Ad

More from Bob Pusateri (7)

PDF
Dipping Your Toes: Azure Data Lake for DBAs
Bob Pusateri
 
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Bob Pusateri
 
PDF
Supercharging Backups and Restores (For Fun and Profit!) (SQL Saturday Boston...
Bob Pusateri
 
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Bob Pusateri
 
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Bob Pusateri
 
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Bob Pusateri
 
PDF
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Bob Pusateri
 
Dipping Your Toes: Azure Data Lake for DBAs
Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (New England SQ...
Bob Pusateri
 
Supercharging Backups and Restores (For Fun and Profit!) (SQL Saturday Boston...
Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASSDC User Gr...
Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (PASS DBA Virtu...
Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (Chicago Suburb...
Bob Pusateri
 
Locks, Blocks, and Snapshots: Maximizing Database Concurrency (SQL Saturday M...
Bob Pusateri
 
Ad

Recently uploaded (20)

PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PPTX
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Fl Studio 24.2.2 Build 4597 Crack for Windows Free Download 2025
faizk77g
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Building Search Using OpenSearch: Limitations and Workarounds
Sease
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 

Select Stars: A DBA's Guide to Azure Cosmos DB (SQL Saturday Oslo 2018)

  • 2. Specialties / Focus Areas / Passions: • Performance Tuning & Troubleshooting • Very Large Databases • SQL Server Storage Engine • HA/DR • Cloud @sqlbob [email protected] heraflux.com bobpusateri
  • 5. We were developing an IoT system …Which needed to ingest data from thousands/millions of devices … and that data needed to be queried within seconds?
  • 6. We were building an e-commerce site Which needed guaranteed performance and availability … anywhere on Earth … and needed to be able to scale up/down in response to conditions?
  • 9. A globally distributed, massively scalable, multi-model database service
  • 10. A globally distributed, massively scalable, multi-model database service
  • 11. A globally distributed, massively scalable, multi-model database service
  • 12. A globally distributed, massively scalable, multi-model database service Key-Value GraphColumn-Family Document
  • 13. A globally distributed, massively scalable, multi-model database service Has multiple APIs as well Table API MongoDB
  • 14. A database service featuring an engine built to excel at several things, but especially: Partitioning Replication
  • 15. It’s a NoSQL offering! 3 DBAS WALKED INTO A NOSQL BAR…. A WHILE LATER THEY WALKED OUT BECAUSE THEY COULDN’T FIND A TABLE
  • 16. • I often hear NoSQL == No Schema == No Design ▪ Not True • GENERALLY NoSQL schemas ▪ Do Exist ▪ Are somewhat enforced by the database ▪ Are fully enforced by the application • There are still design decisions that need to happen early on ▪ (And if they’re wrong you will pay for it later)
  • 17. • Microsoft started having problems with internal large scale apps ▪ 2010 – “Project Florence” ▪ 2014 – Azure DocumentDB ▪ 2017 – Azure Cosmos DB • MS leverages this internally • Designed for the cloud • One of the fastest-growing services on Azure https://tinyurl.com/ycmhp6kd
  • 18. • We’re developing an internal app for a global company • Thousands of users reading/updating data • How would we architect this?
  • 24. • Cosmos DB is a Foundational Azure service • Put your data where the users are • Replication between regions is automatic • Multi-homing APIs ▪ Clients automatically connect to the nearest region • Adding or removing regions? No code changes! • Manual or automatic failovers • Designed from the ground up for HA
  • 25. • Both storage and throughput can be scaled transparently • A single machine is never a bottleneck • Collections can scale from GB to PB across many machines and regions
  • 26. • Requests are served from the nearest region • Database engine optimized for writes, latch-free • Indexing is synchronous and automatic • Single-digit millisecond latency at 99th Percentile Reads (1KB) Indexed Writes (1KB) 50th Percentile < 2ms < 6ms 99th Percentile < 10ms < 15ms
  • 27. • 99.99% availability when in a single region • 99.999% availability in multiple regions • Highly-redundant storage architecture • Automatic or manual failover
  • 28. • Will give you money back if they’re not met! • https://azure.microsoft.com/en-us/support/legal/sla/cosmos-db/
  • 29. • All data is encrypted, period. • In transit and at rest
  • 30. • Two types of keys: • Master Keys ▪ Administrative ▪ Grant access to the entire account (not granular) ▪ Read-write and Read-only
  • 31. • Resource Tokens • Used for application resources (Containers, docs, SPs, Triggers, UDF, etc.) ▪ Kinda like SQL Permissions • Tokens are specific to {user, resource, permission} • Tokens are time-sensitive (default 1 hour, max 5 hours)
  • 37. Account Item Database Container • Data Model • Document (Collection) • Graph • Key-Value • Column-Value • Throughput
  • 38. Account Item Database Container • Data Model • Document (Collection) • Graph • Key-Value • Column-Value • Throughput ATOM RECORD SEQUENCE (ARS) SYSTEM Atoms = primitives (string, bool, etc) Records = structs of atoms Sequences = arrays of {atom, record, sequence} Cosmos DB translates & projects all data models into an ARS model
  • 40. Account Item Database Container • Depends on data model • Document • Node/Edge • Row/Item • Stored Procedures • Triggers • UDFs
  • 42. • RU is the rate-based currency of Cosmos DB • Represents a combination of CPU, Memory, and IO • 1 RU = 1 read of 1KB • Every request is assigned a “cost” in RUs ▪ Reads, writes, stored procedures, etc
  • 43. • Provisioned in units of RU/second • Can be changed at any time; metered hourly • Exceeding your RU budget = rate limiting • When quiescent, background tasks run ▪ Index Maintenance ▪ TTL Expiration Min RU/sec Max RU/sec RequestRate Rate Limiting No Limiting Replica Quiescent
  • 45. • Define boundary values between partitions • Map partitions to physical locations (filegroups) • Similar values generally in the same partition ▪ Can lead to “hot” partitions ▪ Especially if on dates • Partition management is manual • Hard Limit: 15.000 partitions per table
  • 46. • There are no “ranges”, every partition key is hashed • Logical partitions (keys) are spread across physical partitions • Partition management is automatic! • No limit on number of partitions • Hard limit: 10GB max of data per partition key
  • 47. • The most important design decision in Cosmos DB • Has a direct effect on ▪ How well it will scale ▪ How much you will pay • Think through partitioning during the design phase, it’s easier!
  • 49. Partition Key: User ID Cosmos DB Container
  • 50. Partition Key: User ID hash(User ID) Pseudo-random data distribution of hash values
  • 54. Tracker Cap’n Turbot Skye Rocky Robo-Dog hash(User ID) Tracker Cap’n Turbot Robo-Dog Skye Rocky+ Partitions can be dynamically subdivided to grow the database without affecting availability This is done automatically.
  • 55. • Plan to distribute both request and storage volume ▪ Remember the 10GB limit ▪ Adding dates after partition values can help with this • For greatest efficiency, queries should eliminate partitions • Queries can be routed/filtered via partition key • “Fan-Out” is something to try to avoid where possible
  • 56. • Understand your workload! • Understand the most frequent/expensive queries • Understand insert vs update ratios • Remember partition keys are logical! ▪ Don’t be afraid of having too many ▪ More key values = better scalability
  • 58. • This is huge because we have multiple replicas • If a change is replicated, what is seen elsewhere? • Why replicate, anyway? ▪ HA – multiple copies for failover ▪ Speed! • Bring the data closer to the user • “cheat” the speed of light!
  • 61. North Central US UK South Japan East
  • 62. North Central US UK South Japan East
  • 64. North Central US UK South Japan East X
  • 65. • Do we keep all the replicas online? ▪ One of them will be wrong? • Do we shut down the stale replica? ▪ Sacrifice availability for correctness? • Do we shut down everything? ▪ All or nothing?
  • 66. • Relational Databases: ACID ▪ Atomic ▪ Consistent ▪ Independent ▪ Durable • Distributed Systems: Brewer’s CAP Theorem ▪ Consistency ▪ Availability ▪ Partition tolerance ▪ (pick two)
  • 67. • Problem: There’s no consistent definition of “consistent” in CS • Transactions (ACID) ▪ Each transaction moves from a single valid state to another • Replication (CAP) ▪ Getting a consistent view across replicated copies of data ▪ And CAP doesn’t even cover all cases….
  • 68. • An extension of the CAP Theorem • Partitioning: Availability vs. Consistency ELSE Latency vs. Consistency • When partitioning a distributed system you have to choose between availability and consistency, but also when not partitioning one must choose between latency and consistency.
  • 69. • Reader is far away from writer • Value gets updated by writer • Should the reader: ▪ See the old value? (prioritize latency) ▪ See the same result as the master? ▪ Wait for the new value (prioritize consistency)
  • 70. • I love consistency models • I also love isolation levels
  • 71. • Azure Cosmos DB has 5 of them • You can choose what gets prioritized • Can be overridden on a per-request basis Bounded Staleness Strong Consistent Prefix Session Eventual
  • 72. • Linearizability guarantee: reads will always return the most recent version of an item • (Like SERIALIZABLE [maybe?]) • Writes are only visible after committed by a majority quorum of replicas • If using this model, you are limited to a single Azure region Bounded Staleness Strong Consistent Prefix Session Eventual
  • 73. • Guarantees that “absence of any further writes, replicas will eventually converge” • No guarantee of order ▪ Client may get “new” values older than ones it had previously seen • Lowest latency for reads and writes ▪ …but it’s fast! Bounded Staleness Strong Consistent Prefix Session Eventual
  • 74. • Guarantees that readers will always see writes in order Bounded Staleness Strong Consistent Prefix Session Eventual
  • 75. • Scoped to a client session ▪ There’s a session key that is passed around • Provides predictable consistency within a session ▪ Monotonic reads & writes ▪ Guarantee that you can read your own writes immediately • Great predictability for your session, good performance for everyone else Bounded Staleness Strong Consistent Prefix Session Eventual
  • 76. • Define a “window” of staleness in terms of # revisions or time • If a replica gets too far behind (is outside the “window”) ▪ Cosmos DB will prioritize consistency over all else ▪ May even rate limit writes until stale replica catches up Bounded Staleness Strong Consistent Prefix Session Eventual
  • 78. • What if you’re not doing geo-replication? Does this matter? • Yes it does! • Even in local regions there are still 4 replicas of your database 1 2 3 4
  • 80. • Yeah, about that….
  • 85. • Schema-agnostic • Automatic ▪ Every property of every record is indexed by default ▪ No latches involved (remember it’s highly write-optimized) • Customizable ▪ You can define what is indexed (and save space)
  • 86. { "cars": [ { "make": "Hyundai", "model": "Santa Fe" }, { "make": "Subaru", "model": "Forester", “plate": "T SQL" } ], "city": "Chicago" } city Chicago0 1 make model make model license cars Hyundai Santa Fe Subaru Forester T SQL
  • 87. { "cars": [ { "make": "Tesla", "model": "X" } ], "city": “Oslo" } city Oslo0 make model cars Tesla X
  • 88. city Chicago0 1 make model make model license cars Hyundai Santa Fe Subaru Forester T SQL Oslo {1,2} {1,2}{1,2} {1} {2}{1,2} {1} Tesla X {1,2} {1,2} {1} {1}{2} {2} {1} {1} {1} {1} {1}{1} Term Postings $/cars/0 1,2 $/cars/0/make 1,2 $/cars/0/model 1,2 $/cars/1 1 ……
  • 91. • Remember what I said about indexes?
  • 92. • Backups are automatic • Snapshots taken and stored separately in Azure Blob Storage • For speed, it’s written to same region as current Cosmos DB write region • For safety, it’s replicated to another region as well
  • 93. • Taken every 4 hours • Only the last 2 snapshots are retained • “If the data is accidentally dropped or corrupted, contact Azure support within eight hours.” • You can maintain your own backups ▪ Azure Cosmos DB Data Migration Tool “export to JSON” option • If you delete a container/database, backups retained for 30 days
  • 97. • You Pay For: ▪ Storage (2,0286 kr per GB/month) ▪ Throughput (0,065 kr per 100 RUs/hour) ▪ Data Transfer for geo-replication (varies by region) ▪ West Europe: 0,706 kr per GB • Check Azure Portal for most current pricing info • https://azure.microsoft.com/en-us/pricing/details/cosmos-db/
  • 98. • There’s a Cosmos DB Emulator! • Run locally on your machine for free • https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator
  • 99. • There’s a Cosmos DB Emulator! • Run locally on your machine for free • https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator