SlideShare une entreprise Scribd logo
1  sur  106
Télécharger pour lire hors ligne
About me
Agenda:
What is Cosmos DB
What is Azure Cosmos DB
What is Azure Cosmos DB
Global Distribution
Worldwide presence
Automatic multi-region replication
Multi-homing APIs
Manual and automatic failovers
What is Azure Cosmos DB
Five Consistency Models
Helps navigate Brewer's CAP theorem
Intuitive Programming
• Tunable well-defined consistency levels
• Override on per-request basis
Clear PACELC tradeoffs
• Partition – Availability vs Consistency
• Else – Latency vs Consistency
What is Azure Cosmos DB
Comprehensive SLAs
99.99% availability
Durable quorum committed writes
Latency, consistency, and throughput also covered by
financially backed SLAs
Made possible with highly-redundant architecture
Operation
type Single region
Multi-region (single
region writes)
Multi-region (multi-
region writes)
Writes 99.99 99.99 99.999
Reads 99.99 99.999 99.999
Cosmos DB Data Formats
Cosmos DB Data Formats
Cosmos DB Data Formats
• The query syntax is geared at navigating
graphs – you could say e.g. .has(‘person’, ‘name’,
‘Thomas’).outE(‘Knows’) to find people who
Thomas knows.
Cosmos DB Data Formats
Cosmos DB Data Formats
Cosmos DB Design
Containers and Databases
Cosmos DB Storage
Cosmos DB Indexing
 Indexing on by default
 Index only specific paths in your document
Cosmos DB Resources
Cosmos DB Resources
Cosmos DB
Resources
Cosmos DB Resources - Core (SQL) API
Container
Cosmos DB Resources
• Database Account:
• Regions
• API
Cosmos DB Resources
• The container that houses
your data
• /dbs/{id} is not your ID
• Hash known as a “Self Link”
Cosmos DB Resources
• Video
• Audio
• Blob
• Etc.
Cosmos DB Resources
• Invite in an existing azure account
• Allows you to set permissions on
each concept of the database
Cosmos DB Resources
• Authorization token
• Associated with a user
• Grants access to a given
resource
Cosmos DB Resources
• Most like a “table”
• Structure is not defined
• Dynamic shapes based on
what
you put in it
Cosmos DB Resources
• A blob of JSON representing your data
• Can be a deeply nested shape
• No specialty types
• No specific encoding types
Cosmos DB Resources
• Think media – at the
document level!
The maximum size for a document
and it's attachment in CosmosDB now is 2 MB.
In DocumentDB the maximum size of document
and it’s attachment was 512KB
Media size – 2GB
Cosmos DB Resources
• Written in JavaScript!
• Is transactional
• Executed by the database engine
• Can live in the store
• Can be sent over the wire
Cosmos DB Resources
• Can be Pre or Post (before or after)
• Can operate on the following actions
• Create
• Replace
• Delete
• All
• Also written in javascript!
+ Azure
Functions
Cosmos DB Resources
• Can only be ran on a query
• Modifies the result of a
given query
• mathSqrt()
Cosmos DB Resources
Cosmos DB Resources
 JSON array {"exports": [{"city": “Moscow"}, {"city": Athens"}]} correspond to the
paths /"exports"/0/"city"/"Moscow" and /"exports"/1/"city"/"Athens".
Cosmos DB Resources
Cosmos DB Resources
Cosmos DB Resources
Cosmos DB Resources
Property User settable or system generated? Purpose
_rid System generated System generated, unique and hierarchical
identifier of the resource.
_etag System generated etag of the resource required for
optimistic concurrency control.
_ts System generated Last updated timestamp of the resource.
_self System generated Unique addressable URI of the resource.
id User settable User defined unique name of the
resource.
Cosmos DB Resources
Value of the _self Description
/dbs Feed of databases under a database account.
/dbs/{_rid-db} Database with the unique id property with the value {_rid-db}.
/dbs/{_rid-db}/colls/ Feed of collections under a database.
/dbs/{_rid-db}/colls/{_rid-coll} Collection with the unique id property with the value {_rid-coll}.
/dbs/{_rid-db}/users/ Feed of users under a database.
/dbs/{_rid-db}/users/{_rid-user} User with the unique id property with the value {_rid-user}.
/dbs/{_rid-db}/users/{_rid-user}/permissions Feed of permissions under a database.
/dbs/{_rid-db}/users/{_rid-user}/permissions/{_rid-permission} Permission with the unique id property with the value {_rid-permission}.
Request Units
Request Units
Request Units (RUs) is a rate-based currency – e.g. 1000 RU/second
Abstracts physical resources for performing requests
% IOPS% CPU% Memory
Cosmos DB Resources
Request Units
Each request consumes # of RU
Approx. 1 RU = 1 read of 1 KB document
Approx. 5 RU = 1 write of a 1KB document
Query: Depends on query & documents involved
GET
POST
PUT
Query
…
=
=
=
=
Request Units- Provisioned throughput
Provisioned in terms of RU/sec – e.g. 1000 RU/s
Billed for highest RU/s in 1 hour
Easy to increase and decrease on demand
Rate limiting based on amount of throughput provisioned
Background processes like TTL expiration, index
transformations scheduled when quiescent
Min RU/sec
Max
RU/sec
IncomingRequests
No rate limiting,
process background
operations
Rate limiting –
SDK retry
No rate limiting
Cosmos DB Resources
Partitioned
collection
Single partition
collection (only via
SDK v.2) S1 S2 S3
Maximum
throughput
Unlimited 10K RU/s 250 RU/s 1 K RU/s 2.5 K RU/s
Minimum
throughput
2.5K
400 RU/s
400 RU/s 250 RU/s 1 K RU/s 2.5 K RU/s
Maximum storage Unlimited 10 GB 10 GB 10 GB 10 GB
Price Throughput: $6 /
100 RU/s
Storage: $0.25/GB
Throughput: $6 /
100 RU/s
Storage: $0.25/GB
$25 USD $50 USD $100 USD
Data Modeling in
Azure Cosmos DB
2 Extremes
Sample structure
{
"ID": 1,
"ItemName": "hamburger",
"ItemDescription": "cheeseburger, no cheese",
“CategoryId": 5,
"Category": "sandwiches"
"CategoryDescription": "2 pieces of bread + filling"
}
Modeling challenge : To embed or reference?
{
"menuID": 1,
"menuName": "Lunch menu",
"items": [
{"ID": 1, "ItemName": "hamburger", "ItemDescription":...}
{"ID": 2, "ItemName": "cheeseburger", "ItemDescription":...}
]
}
{
"menuID": 1,
"menuName": "Lunch menu",
"items": [
{"ID": 1}
{"ID": 2}
]
}
{"ID": 1, "ItemName": “hamburger", "ItemDescription":...}
{"ID": 2, "ItemName": “cheeseburger", "ItemDescription":...}
But wait, you can do both!
{
"id": "speaker1",
"name": "Alice",
"email": "alice@contoso.com",
“address”: “1 Microsoft Way”
“phone”: “555-5555”
"sessions":[
{"id": "session1"},
{"id": "session2"}
]
}
{
"id": “session1",
"name": "Modelling Data 101",
"speakers":[
{"id": "speaker1“, “name”: “Alice”,
“email”: “alice@contoso.com”},
{"id": "speaker2“, “name”: “Bob”}
]
}
Embed reference less frequently
used
Partitioning in
Azure Cosmos DB
Partitioning in Cosmos DB
Partitioning
Logical partition: Stores all data associated with the same partition
key value
Physical partition: Fixed amount of reserved SSD-backed storage +
compute.
Cosmos DB distributes logical partitions among a smaller number of
physical partitions.
From user’s perspective: define 1 partition key per container
Containers support unlimited storage by dynamically
allocating additional physical partitions
Storage for single partition key value (logical partition)
is quota'ed to 10GB.
When a partition key reaches its provisioned storage
limit, requests to create new resources will return a
HTTP Status Code of 403 (Forbidden).
Azure Cosmos DB will automatically add partitions, and
may also return a 403 if:
• An authorization token has expired
• A programmatic element (UDF, Stored Procedure,
Trigger) has been flagged for repeated violations
Partition Key Storage Limits
HTTP 403
Partitioning in Cosmos DB
Partitioning in Cosmos DB
p
p1 p2
Partitioning in Cosmos DB
API Partition Key Row Key
DocumentDB custom partition key path fixed id
MongoDB custom shard key fixed _id
Graph custom partition key
property
fixed id
Table fixed PartitionKey fixed RowKey
Developing against
Cosmos DB (SQL API)
Developing against Cosmos DB SQL API
Cosmos DB APIs Support
Querying Cosmos DB SQL API
Querying Cosmos DB SQL API
 SELECT
AS
AS
AS
AS
 FROM
 JOIN IN
 JOIN IN
Querying Cosmos DB SQL API
 var
id: "contains",
function {
if (arr.indexOf(obj) > -1) {
 return true;
 }
 return false;
}
Querying Cosmos DB SQL API
 SELECT FROM Families WHERE
contains "Andersen" false
Querying Cosmos DB SQL API
Querying Cosmos DB SQL API
var createDocumentStoredProc = {
id: "createCustomDocument",
body: function createCustomDocument(documentToCreate) {
var context = getContext();
var collection = context.getCollection();
var accepted = collection.createDocument(collection.getSelfLink(),
documentToCreate,
function (err, documentCreated) {
if (err) throw new Error('Error' + err.message);
context.getResponse().setBody(documentCreated.id)
});
if (!accepted) return;
}
}
Querying Cosmos DB SQL API
var result =
client.ExecuteStoredProcedureAsync(
createdStoredProcedure._self);
Querying Cosmos DB SQL API
Querying Cosmos DB SQL API
Querying Cosmos DB SQL API
Cosmos DB and Table Storage
Cosmos DB: Table API
Cosmos DB: Table API
Cosmos DB: Table API
Azure Table Storage
Azure Cosmos DB: Table storage
(preview)
Latency Fast, but no upper bounds on latency Single-digit millisecond latency for reads and
writes, backed with <10-ms latency reads
and <15-ms latency writes at the 99th
percentile, at any scale, anywhere in the
world
Throughput variable throughput model. Tables have a
scalability limit of 20,000 operations/s
Highly scalable with dedicated reserved
throughput per table, that is backed by
SLAs. Accounts have no upper limit on
throughput, and support >10 million
operations/s per table
Global Distribution Single region with one optional readable
secondary read region for HA. You cannot
initiate failover
Turn-key global distribution from one to 30+
regions, Support for automatic and manual
failovers at any time, anywhere in the world
Indexing Only primary index on PartitionKey and
RowKey. No secondary indexes
Automatic and complete indexing on all
properties, no index management
Cosmos DB: Table API
Azure Table Storage
Azure Cosmos DB: Table storage
(preview)
Query Query execution uses index for primary
key, and scans otherwise.
Queries can take advantage of
automatic indexing on properties for
fast query times. Azure Cosmos DB's
database engine is capable of
supporting aggregates, geo-spatial, and
sorting.
Consistency Strong within primary region, Eventual
with secondary region
Five well-defined consistency levels to
trade off availability, latency,
throughput, and consistency based on
your application needs
Pricing Storage-optimized Throughput-optimized
SLAs 99.9% availability 99.99% availability within a single
region, and ability to add more regions
for higher availability. Industry-leading
comprehensive SLAs on general
availability
Cosmos DB
and
MongoDB
Cosmos DB: API for MongoDB
Cosmos DB: API for MongoDB
Cosmos DB
Change Feed
Cosmos DB Change Feed
Common Change Feed Scenarios
Common Scenarios
Event Sourcing (Microservices)
1. Event driven design with Azure Fuctions
Azure Functions
(E-Commerce Checkout API)
Azure Cosmos
DB (Order Event
Store)
Azure Functions
(Microservice 1: Tax)
Azure Functions
(Microservice 2: Payment)
Azure Functions
(Microservice N:
Fulfillment)
. . .
2. Real-time data movement
Data Movement / Backup
…
3. Materialized View
SubscriptionI
D
UserID Create
Date
…
123abc Ben6 6/17/17
456efg Ben6 3/14/17
789hij Jen4 8/1/16
012klm Joe3 3/4/17
UserID Total Subscriptions
Ben6 2
Jen4 1
Joe3 1
Three different ways to use the Change Feed
Implementation Use Case Advantages
Azure Functions
Serverless
applications
Easy to implement.
Used as a trigger, input or output binding to an Azure
Function.
Change Feed
Processor Library
Distributed
applications
Ability to distribute the processing of events towards
multiple clients. Requires a “leases collection”.
SQL API SDK for
.NET or Java
Not
recommended
Requires manual implementation in a .NET or Java
application.
Lease collection
Cosmos DB Performance
Cosmos DB Performance: SQL API
 Use direct connection mode for better performance
Cosmos DB Performance: SQL API
 var client =DocumentClient client = new DocumentClient
 (serviceEndpoint, authKey,
 new ConnectionPolicy
 {
 ConnectionMode = ConnectionMode.Direct,
 ConnectionProtocol = Protocol.Tcp
 });
Cosmos DB Performance: SQL API
Cosmos DB Performance: SQL API
Cosmos DB Performance: SQL API
Document document = await
client.ReadDocumentAsync("/dbs/1234/colls/1234354/docs/2332435465");
Cosmos DB Regional Failover
Multi-master at global scale with Azure Cosmos DB
Auto Scaling Containers
Auto Scaling Containers
Request Units and Bullings
Billing Model
Two components: Consumed Storage + Provisioned Throughput
You are billed on consumed storage and provisioned throughput
Containers in a database can share throughput
Unit Price (for most Azure regions)
SSD Storage (per GB) $0.25 per month
Provisioned Throughput (single region
writes)
$0.008/hour per 100 RU/s
Provisioned Throughput (multi-region
writes)
$0.016/hour per 100 multi-region write
RU/s
* pricing may vary by region; for up-to-date pricing, see: https://azure.microsoft.com/pricing/details/cosmos-
Billing Model
Automatically configuring provisioned throughput with Autopilot Preview
You are billed on consumed storage and provisioned throughput
Containers in a database can share throughput
Autopilot Throughput – Unit (100 RU/s
per hour)
Price
100 Autopilot RU/s, single-region account $0.012/hour
100 Autopilot RU/s, multi-region, single
master account with N regions
N regions x $0.012/hour, where N > 1
100 RU/s multi-region, multi-master
account with N regions
N regions x $0.016/hour, where N > 1
* pricing may vary by region; for up-to-date pricing, see: https://azure.microsoft.com/pricing/details/cosmos-
Billing Model
Reserved capacity for provisioned throughput
* pricing may vary by region; for up-to-date pricing, see: https://azure.microsoft.com/pricing/details/cosmos-
1 YEAR RESERVATION 3 YEAR RESERVATION
THROUGHPUT SINGLE REGION WRITE MULTIPLE REGION WRITE SINGLE REGION WRITE MULTIPLE REGION WRITE
PRICE/SAVINGS PRICE PER 100 RU/S
(SAVINGS OVER PAYG)
PRICE PER 100 RU/S
(SAVINGS OVER PAYG)
PRICE PER 100 RU/S
(SAVINGS OVER PAYG)
PRICE PER 100 RU/S
(SAVINGS OVER PAYG)
First 50K RU/s $0.0068 (~15%) $0.0128 (~20%) $0.006 (~25%) $0.0112 (~30%)
Next 450K RU/s $0.006 (~25%) $0.0112 (~30%) $0.0052 (~35%) $0.0096 (~40%)
Next 2.5M RU/s $0.0056 (~30%) $0.0104 (~35%) $0.0044 (~45%) $0.008 (~50%)
Over 3M RU/s $0.0044 (~45%) $0.008 (~50%) $0.0032 (~60%) $0.0056 (~65%)
Billing Model
Free Cosmos DB Tier
Azure Cosmos DB Free Tier. Develop and test applications, or
run small production workloads free within the Azure
environment.
Get Started: Enable Free Tier on a new account to receive 400
RU/s throughput and 5 GBs storage free each month for the life
of your account.
* pricing may vary by region; for up-to-date pricing, see: https://azure.microsoft.com/pricing/details/cosmos-
Demos
Questions?
Thank you!

Contenu connexe

Tendances

Tendances (20)

Building Lakehouses on Delta Lake with SQL Analytics Primer
Building Lakehouses on Delta Lake with SQL Analytics PrimerBuilding Lakehouses on Delta Lake with SQL Analytics Primer
Building Lakehouses on Delta Lake with SQL Analytics Primer
 
Building the Enterprise Data Lake - Important Considerations Before You Jump In
Building the Enterprise Data Lake - Important Considerations Before You Jump InBuilding the Enterprise Data Lake - Important Considerations Before You Jump In
Building the Enterprise Data Lake - Important Considerations Before You Jump In
 
Pipelines and Packages: Introduction to Azure Data Factory (DATA:Scotland 2019)
Pipelines and Packages: Introduction to Azure Data Factory (DATA:Scotland 2019)Pipelines and Packages: Introduction to Azure Data Factory (DATA:Scotland 2019)
Pipelines and Packages: Introduction to Azure Data Factory (DATA:Scotland 2019)
 
Zero to Snowflake Presentation
Zero to Snowflake Presentation Zero to Snowflake Presentation
Zero to Snowflake Presentation
 
Technical Deck Delta Live Tables.pdf
Technical Deck Delta Live Tables.pdfTechnical Deck Delta Live Tables.pdf
Technical Deck Delta Live Tables.pdf
 
Azure Data Factory v2
Azure Data Factory v2Azure Data Factory v2
Azure Data Factory v2
 
Azure Cosmos DB
Azure Cosmos DBAzure Cosmos DB
Azure Cosmos DB
 
Data Lakehouse Symposium | Day 1 | Part 2
Data Lakehouse Symposium | Day 1 | Part 2Data Lakehouse Symposium | Day 1 | Part 2
Data Lakehouse Symposium | Day 1 | Part 2
 
Get Savvy with Snowflake
Get Savvy with SnowflakeGet Savvy with Snowflake
Get Savvy with Snowflake
 
Azure Data Factory V2; The Data Flows
Azure Data Factory V2; The Data FlowsAzure Data Factory V2; The Data Flows
Azure Data Factory V2; The Data Flows
 
Modern data warehouse
Modern data warehouseModern data warehouse
Modern data warehouse
 
Snowflake Data Loading.pptx
Snowflake Data Loading.pptxSnowflake Data Loading.pptx
Snowflake Data Loading.pptx
 
Azure Databricks - An Introduction (by Kris Bock)
Azure Databricks - An Introduction (by Kris Bock)Azure Databricks - An Introduction (by Kris Bock)
Azure Databricks - An Introduction (by Kris Bock)
 
1- Introduction of Azure data factory.pptx
1- Introduction of Azure data factory.pptx1- Introduction of Azure data factory.pptx
1- Introduction of Azure data factory.pptx
 
Elastic Data Warehousing
Elastic Data WarehousingElastic Data Warehousing
Elastic Data Warehousing
 
Building a Data Lake on AWS
Building a Data Lake on AWSBuilding a Data Lake on AWS
Building a Data Lake on AWS
 
Azure Data Factory ETL Patterns in the Cloud
Azure Data Factory ETL Patterns in the CloudAzure Data Factory ETL Patterns in the Cloud
Azure Data Factory ETL Patterns in the Cloud
 
NOVA SQL User Group - Azure Synapse Analytics Overview - May 2020
NOVA SQL User Group - Azure Synapse Analytics Overview -  May 2020NOVA SQL User Group - Azure Synapse Analytics Overview -  May 2020
NOVA SQL User Group - Azure Synapse Analytics Overview - May 2020
 
Snowflake for Data Engineering
Snowflake for Data EngineeringSnowflake for Data Engineering
Snowflake for Data Engineering
 
Introducing Azure SQL Database
Introducing Azure SQL DatabaseIntroducing Azure SQL Database
Introducing Azure SQL Database
 

Similaire à Dealing with Azure Cosmos DB

CouchDB Open Source Bridge
CouchDB Open Source BridgeCouchDB Open Source Bridge
CouchDB Open Source Bridge
Chris Anderson
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Justin Smestad
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Alex Bilbie
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
DATAVERSITY
 
CouchDB at JAOO Århus 2009
CouchDB at JAOO Århus 2009CouchDB at JAOO Århus 2009
CouchDB at JAOO Århus 2009
Jason Davies
 

Similaire à Dealing with Azure Cosmos DB (20)

Azure CosmosDb
Azure CosmosDbAzure CosmosDb
Azure CosmosDb
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
Couchdb Nosql
Couchdb NosqlCouchdb Nosql
Couchdb Nosql
 
CouchDB Open Source Bridge
CouchDB Open Source BridgeCouchDB Open Source Bridge
CouchDB Open Source Bridge
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Couchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problemCouchdb: No SQL? No driver? No problem
Couchdb: No SQL? No driver? No problem
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
Zero to 60 with Azure Cosmos DB
Zero to 60 with Azure Cosmos DBZero to 60 with Azure Cosmos DB
Zero to 60 with Azure Cosmos DB
 
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in Bavaria
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...Replacing Oracle with MongoDB for a templating application at the Bavarian go...
Replacing Oracle with MongoDB for a templating application at the Bavarian go...
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo2016 feb-23 pyugre-py_mongo
2016 feb-23 pyugre-py_mongo
 
Using MongoDB and Python
Using MongoDB and PythonUsing MongoDB and Python
Using MongoDB and Python
 
phptut4
phptut4phptut4
phptut4
 
phptut4
phptut4phptut4
phptut4
 
CouchDB at JAOO Århus 2009
CouchDB at JAOO Århus 2009CouchDB at JAOO Århus 2009
CouchDB at JAOO Århus 2009
 

Plus de Mihail Mateev

Win j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateevWin j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateev
Mihail Mateev
 
Using SQL Local Database in Mobile Applications
Using SQL Local Database in Mobile ApplicationsUsing SQL Local Database in Mobile Applications
Using SQL Local Database in Mobile Applications
Mihail Mateev
 
Spatial Data with SQL Server Reporting Services
Spatial Data with SQL Server Reporting ServicesSpatial Data with SQL Server Reporting Services
Spatial Data with SQL Server Reporting Services
Mihail Mateev
 

Plus de Mihail Mateev (7)

Clash of Technologies Google Cloud vs Microsoft Azure
Clash of Technologies Google Cloud vs Microsoft AzureClash of Technologies Google Cloud vs Microsoft Azure
Clash of Technologies Google Cloud vs Microsoft Azure
 
Devday 2014 using_afs_in_your_cloud_app
Devday 2014 using_afs_in_your_cloud_appDevday 2014 using_afs_in_your_cloud_app
Devday 2014 using_afs_in_your_cloud_app
 
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
 
Varna conf nodejs-oss-microsoft-azure[final]
Varna conf nodejs-oss-microsoft-azure[final]Varna conf nodejs-oss-microsoft-azure[final]
Varna conf nodejs-oss-microsoft-azure[final]
 
Win j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateevWin j svsphonegap-damyan-petev-mihail-mateev
Win j svsphonegap-damyan-petev-mihail-mateev
 
Using SQL Local Database in Mobile Applications
Using SQL Local Database in Mobile ApplicationsUsing SQL Local Database in Mobile Applications
Using SQL Local Database in Mobile Applications
 
Spatial Data with SQL Server Reporting Services
Spatial Data with SQL Server Reporting ServicesSpatial Data with SQL Server Reporting Services
Spatial Data with SQL Server Reporting Services
 

Dernier

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Dernier (20)

JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 

Dealing with Azure Cosmos DB

  • 1.
  • 5. What is Azure Cosmos DB
  • 6. What is Azure Cosmos DB Global Distribution Worldwide presence Automatic multi-region replication Multi-homing APIs Manual and automatic failovers
  • 7. What is Azure Cosmos DB Five Consistency Models Helps navigate Brewer's CAP theorem Intuitive Programming • Tunable well-defined consistency levels • Override on per-request basis Clear PACELC tradeoffs • Partition – Availability vs Consistency • Else – Latency vs Consistency
  • 8. What is Azure Cosmos DB Comprehensive SLAs 99.99% availability Durable quorum committed writes Latency, consistency, and throughput also covered by financially backed SLAs Made possible with highly-redundant architecture Operation type Single region Multi-region (single region writes) Multi-region (multi- region writes) Writes 99.99 99.99 99.999 Reads 99.99 99.999 99.999
  • 9. Cosmos DB Data Formats
  • 10. Cosmos DB Data Formats
  • 11. Cosmos DB Data Formats • The query syntax is geared at navigating graphs – you could say e.g. .has(‘person’, ‘name’, ‘Thomas’).outE(‘Knows’) to find people who Thomas knows.
  • 12. Cosmos DB Data Formats
  • 13. Cosmos DB Data Formats
  • 17. Cosmos DB Indexing  Indexing on by default  Index only specific paths in your document
  • 21. Cosmos DB Resources - Core (SQL) API Container
  • 22. Cosmos DB Resources • Database Account: • Regions • API
  • 23. Cosmos DB Resources • The container that houses your data • /dbs/{id} is not your ID • Hash known as a “Self Link”
  • 24. Cosmos DB Resources • Video • Audio • Blob • Etc.
  • 25. Cosmos DB Resources • Invite in an existing azure account • Allows you to set permissions on each concept of the database
  • 26. Cosmos DB Resources • Authorization token • Associated with a user • Grants access to a given resource
  • 27. Cosmos DB Resources • Most like a “table” • Structure is not defined • Dynamic shapes based on what you put in it
  • 28. Cosmos DB Resources • A blob of JSON representing your data • Can be a deeply nested shape • No specialty types • No specific encoding types
  • 29. Cosmos DB Resources • Think media – at the document level! The maximum size for a document and it's attachment in CosmosDB now is 2 MB. In DocumentDB the maximum size of document and it’s attachment was 512KB Media size – 2GB
  • 30. Cosmos DB Resources • Written in JavaScript! • Is transactional • Executed by the database engine • Can live in the store • Can be sent over the wire
  • 31. Cosmos DB Resources • Can be Pre or Post (before or after) • Can operate on the following actions • Create • Replace • Delete • All • Also written in javascript! + Azure Functions
  • 32. Cosmos DB Resources • Can only be ran on a query • Modifies the result of a given query • mathSqrt()
  • 34. Cosmos DB Resources  JSON array {"exports": [{"city": “Moscow"}, {"city": Athens"}]} correspond to the paths /"exports"/0/"city"/"Moscow" and /"exports"/1/"city"/"Athens".
  • 38. Cosmos DB Resources Property User settable or system generated? Purpose _rid System generated System generated, unique and hierarchical identifier of the resource. _etag System generated etag of the resource required for optimistic concurrency control. _ts System generated Last updated timestamp of the resource. _self System generated Unique addressable URI of the resource. id User settable User defined unique name of the resource.
  • 39. Cosmos DB Resources Value of the _self Description /dbs Feed of databases under a database account. /dbs/{_rid-db} Database with the unique id property with the value {_rid-db}. /dbs/{_rid-db}/colls/ Feed of collections under a database. /dbs/{_rid-db}/colls/{_rid-coll} Collection with the unique id property with the value {_rid-coll}. /dbs/{_rid-db}/users/ Feed of users under a database. /dbs/{_rid-db}/users/{_rid-user} User with the unique id property with the value {_rid-user}. /dbs/{_rid-db}/users/{_rid-user}/permissions Feed of permissions under a database. /dbs/{_rid-db}/users/{_rid-user}/permissions/{_rid-permission} Permission with the unique id property with the value {_rid-permission}.
  • 41. Request Units Request Units (RUs) is a rate-based currency – e.g. 1000 RU/second Abstracts physical resources for performing requests % IOPS% CPU% Memory
  • 43. Request Units Each request consumes # of RU Approx. 1 RU = 1 read of 1 KB document Approx. 5 RU = 1 write of a 1KB document Query: Depends on query & documents involved GET POST PUT Query … = = = =
  • 44. Request Units- Provisioned throughput Provisioned in terms of RU/sec – e.g. 1000 RU/s Billed for highest RU/s in 1 hour Easy to increase and decrease on demand Rate limiting based on amount of throughput provisioned Background processes like TTL expiration, index transformations scheduled when quiescent Min RU/sec Max RU/sec IncomingRequests No rate limiting, process background operations Rate limiting – SDK retry No rate limiting
  • 45. Cosmos DB Resources Partitioned collection Single partition collection (only via SDK v.2) S1 S2 S3 Maximum throughput Unlimited 10K RU/s 250 RU/s 1 K RU/s 2.5 K RU/s Minimum throughput 2.5K 400 RU/s 400 RU/s 250 RU/s 1 K RU/s 2.5 K RU/s Maximum storage Unlimited 10 GB 10 GB 10 GB 10 GB Price Throughput: $6 / 100 RU/s Storage: $0.25/GB Throughput: $6 / 100 RU/s Storage: $0.25/GB $25 USD $50 USD $100 USD
  • 48. Sample structure { "ID": 1, "ItemName": "hamburger", "ItemDescription": "cheeseburger, no cheese", “CategoryId": 5, "Category": "sandwiches" "CategoryDescription": "2 pieces of bread + filling" }
  • 49. Modeling challenge : To embed or reference? { "menuID": 1, "menuName": "Lunch menu", "items": [ {"ID": 1, "ItemName": "hamburger", "ItemDescription":...} {"ID": 2, "ItemName": "cheeseburger", "ItemDescription":...} ] } { "menuID": 1, "menuName": "Lunch menu", "items": [ {"ID": 1} {"ID": 2} ] } {"ID": 1, "ItemName": “hamburger", "ItemDescription":...} {"ID": 2, "ItemName": “cheeseburger", "ItemDescription":...}
  • 50. But wait, you can do both! { "id": "speaker1", "name": "Alice", "email": "alice@contoso.com", “address”: “1 Microsoft Way” “phone”: “555-5555” "sessions":[ {"id": "session1"}, {"id": "session2"} ] } { "id": “session1", "name": "Modelling Data 101", "speakers":[ {"id": "speaker1“, “name”: “Alice”, “email”: “alice@contoso.com”}, {"id": "speaker2“, “name”: “Bob”} ] } Embed reference less frequently used
  • 53. Partitioning Logical partition: Stores all data associated with the same partition key value Physical partition: Fixed amount of reserved SSD-backed storage + compute. Cosmos DB distributes logical partitions among a smaller number of physical partitions. From user’s perspective: define 1 partition key per container
  • 54. Containers support unlimited storage by dynamically allocating additional physical partitions Storage for single partition key value (logical partition) is quota'ed to 10GB. When a partition key reaches its provisioned storage limit, requests to create new resources will return a HTTP Status Code of 403 (Forbidden). Azure Cosmos DB will automatically add partitions, and may also return a 403 if: • An authorization token has expired • A programmatic element (UDF, Stored Procedure, Trigger) has been flagged for repeated violations Partition Key Storage Limits HTTP 403
  • 57. Partitioning in Cosmos DB API Partition Key Row Key DocumentDB custom partition key path fixed id MongoDB custom shard key fixed _id Graph custom partition key property fixed id Table fixed PartitionKey fixed RowKey
  • 60. Cosmos DB APIs Support
  • 62. Querying Cosmos DB SQL API  SELECT AS AS AS AS  FROM  JOIN IN  JOIN IN
  • 63. Querying Cosmos DB SQL API  var id: "contains", function { if (arr.indexOf(obj) > -1) {  return true;  }  return false; }
  • 64. Querying Cosmos DB SQL API  SELECT FROM Families WHERE contains "Andersen" false
  • 66. Querying Cosmos DB SQL API var createDocumentStoredProc = { id: "createCustomDocument", body: function createCustomDocument(documentToCreate) { var context = getContext(); var collection = context.getCollection(); var accepted = collection.createDocument(collection.getSelfLink(), documentToCreate, function (err, documentCreated) { if (err) throw new Error('Error' + err.message); context.getResponse().setBody(documentCreated.id) }); if (!accepted) return; } }
  • 67. Querying Cosmos DB SQL API var result = client.ExecuteStoredProcedureAsync( createdStoredProcedure._self);
  • 71. Cosmos DB and Table Storage
  • 74. Cosmos DB: Table API Azure Table Storage Azure Cosmos DB: Table storage (preview) Latency Fast, but no upper bounds on latency Single-digit millisecond latency for reads and writes, backed with <10-ms latency reads and <15-ms latency writes at the 99th percentile, at any scale, anywhere in the world Throughput variable throughput model. Tables have a scalability limit of 20,000 operations/s Highly scalable with dedicated reserved throughput per table, that is backed by SLAs. Accounts have no upper limit on throughput, and support >10 million operations/s per table Global Distribution Single region with one optional readable secondary read region for HA. You cannot initiate failover Turn-key global distribution from one to 30+ regions, Support for automatic and manual failovers at any time, anywhere in the world Indexing Only primary index on PartitionKey and RowKey. No secondary indexes Automatic and complete indexing on all properties, no index management
  • 75. Cosmos DB: Table API Azure Table Storage Azure Cosmos DB: Table storage (preview) Query Query execution uses index for primary key, and scans otherwise. Queries can take advantage of automatic indexing on properties for fast query times. Azure Cosmos DB's database engine is capable of supporting aggregates, geo-spatial, and sorting. Consistency Strong within primary region, Eventual with secondary region Five well-defined consistency levels to trade off availability, latency, throughput, and consistency based on your application needs Pricing Storage-optimized Throughput-optimized SLAs 99.9% availability 99.99% availability within a single region, and ability to add more regions for higher availability. Industry-leading comprehensive SLAs on general availability
  • 77. Cosmos DB: API for MongoDB
  • 78. Cosmos DB: API for MongoDB
  • 81. Common Change Feed Scenarios
  • 83. 1. Event driven design with Azure Fuctions Azure Functions (E-Commerce Checkout API) Azure Cosmos DB (Order Event Store) Azure Functions (Microservice 1: Tax) Azure Functions (Microservice 2: Payment) Azure Functions (Microservice N: Fulfillment) . . .
  • 84. 2. Real-time data movement Data Movement / Backup …
  • 85. 3. Materialized View SubscriptionI D UserID Create Date … 123abc Ben6 6/17/17 456efg Ben6 3/14/17 789hij Jen4 8/1/16 012klm Joe3 3/4/17 UserID Total Subscriptions Ben6 2 Jen4 1 Joe3 1
  • 86. Three different ways to use the Change Feed Implementation Use Case Advantages Azure Functions Serverless applications Easy to implement. Used as a trigger, input or output binding to an Azure Function. Change Feed Processor Library Distributed applications Ability to distribute the processing of events towards multiple clients. Requires a “leases collection”. SQL API SDK for .NET or Java Not recommended Requires manual implementation in a .NET or Java application.
  • 88.
  • 90. Cosmos DB Performance: SQL API  Use direct connection mode for better performance
  • 91. Cosmos DB Performance: SQL API  var client =DocumentClient client = new DocumentClient  (serviceEndpoint, authKey,  new ConnectionPolicy  {  ConnectionMode = ConnectionMode.Direct,  ConnectionProtocol = Protocol.Tcp  });
  • 94. Cosmos DB Performance: SQL API Document document = await client.ReadDocumentAsync("/dbs/1234/colls/1234354/docs/2332435465");
  • 95. Cosmos DB Regional Failover
  • 96. Multi-master at global scale with Azure Cosmos DB
  • 99. Request Units and Bullings
  • 100. Billing Model Two components: Consumed Storage + Provisioned Throughput You are billed on consumed storage and provisioned throughput Containers in a database can share throughput Unit Price (for most Azure regions) SSD Storage (per GB) $0.25 per month Provisioned Throughput (single region writes) $0.008/hour per 100 RU/s Provisioned Throughput (multi-region writes) $0.016/hour per 100 multi-region write RU/s * pricing may vary by region; for up-to-date pricing, see: https://azure.microsoft.com/pricing/details/cosmos-
  • 101. Billing Model Automatically configuring provisioned throughput with Autopilot Preview You are billed on consumed storage and provisioned throughput Containers in a database can share throughput Autopilot Throughput – Unit (100 RU/s per hour) Price 100 Autopilot RU/s, single-region account $0.012/hour 100 Autopilot RU/s, multi-region, single master account with N regions N regions x $0.012/hour, where N > 1 100 RU/s multi-region, multi-master account with N regions N regions x $0.016/hour, where N > 1 * pricing may vary by region; for up-to-date pricing, see: https://azure.microsoft.com/pricing/details/cosmos-
  • 102. Billing Model Reserved capacity for provisioned throughput * pricing may vary by region; for up-to-date pricing, see: https://azure.microsoft.com/pricing/details/cosmos- 1 YEAR RESERVATION 3 YEAR RESERVATION THROUGHPUT SINGLE REGION WRITE MULTIPLE REGION WRITE SINGLE REGION WRITE MULTIPLE REGION WRITE PRICE/SAVINGS PRICE PER 100 RU/S (SAVINGS OVER PAYG) PRICE PER 100 RU/S (SAVINGS OVER PAYG) PRICE PER 100 RU/S (SAVINGS OVER PAYG) PRICE PER 100 RU/S (SAVINGS OVER PAYG) First 50K RU/s $0.0068 (~15%) $0.0128 (~20%) $0.006 (~25%) $0.0112 (~30%) Next 450K RU/s $0.006 (~25%) $0.0112 (~30%) $0.0052 (~35%) $0.0096 (~40%) Next 2.5M RU/s $0.0056 (~30%) $0.0104 (~35%) $0.0044 (~45%) $0.008 (~50%) Over 3M RU/s $0.0044 (~45%) $0.008 (~50%) $0.0032 (~60%) $0.0056 (~65%)
  • 103. Billing Model Free Cosmos DB Tier Azure Cosmos DB Free Tier. Develop and test applications, or run small production workloads free within the Azure environment. Get Started: Enable Free Tier on a new account to receive 400 RU/s throughput and 5 GBs storage free each month for the life of your account. * pricing may vary by region; for up-to-date pricing, see: https://azure.microsoft.com/pricing/details/cosmos-
  • 104. Demos