Developers guide to Azure Cosmos DB From onboarding
Developer’s guide to Azure Cosmos DB: From onboarding to production
Today’s session
What is…AZURE COSMOS DB? Core (SQL) API Mongo. DB Table API Column-family Document Graph Key-value Guaranteed low latency at the 99 th percentile Elastic scale out of storage & throughput Turnkey global distribution Five well-defined consistency models Comprehensive SLAs
Today’s scenario
Today’s scenario
Simplified Architecture
Fleet Management app
When should I use Azure Cosmos DB? One or more of these requirements…
Which API should I use for my app? Core (SQL) API • • • Best developer experience – Cosmos builds interface, service, and SDKs Gremlin API for graph data Other APIs for migration Core (SQL) API Mongo. DB Table API Column-family Key-value Document Graph
Let’s get started
What are Request Units (RUs)?
What are Request Units (RUs)? Each request consumes # of RU GET = POST = PUT = Query = …
Telemetry ingest…let’s estimate the RU/s we need
Sample telemetry event document { "partition. Key": "MP 80 QE 3 HPJPGAI 4 IG-2019 -10", "entity. Type": "Vehicle. Telemetry", "vin": "MP 80 QE 3 HPJPGAI 4 IG", "state": "CT", "outside. Temperature": 84, "engine. Temperature": 296, "speed": 20, "fuel": 5, "fuel. Rate": 12. 99, "engineoil": 45, "tirepressure": 3, "odometer": 209150, "timestamp": "2019 -10 -20 T 04: 46: 52. 5395469 Z", "id": "87701651 -fc 64 -40 b 5 -bc 4 c-7 be 2 b 7 f 655 e 2" }
Demo – finding RU charge in SDK
Telemetry ingest…let’s estimate the RU/s we need
Autopilot vs manual provisioning
Demo – Measuring performance & scaling
Partitioning
PARTITIONS hash(vin) Range 1 Range 2 Range X
PARTITIONS hash(vin) ABC 123 EFJSF DFJDFP XYZ 999 ABC 123 XYZ 999 IKDI 3 Range 1 Range 2 Range X
PARTITIONS hash(vin) 6000 RU/s ABC 123 EFJSF DFJDFP XYZ 999 IKDI 3 Range 1 6000 RU/s ILHFD BHDN EBHFI Range 2 Range 5
Partitioning best practices Write heavy workloads Read heavy workloads:
Demo: The impact of a good partitioning strategy
Data modelling
Our scenario: Embed vs. reference
[{ "id": "e 2 c 7 ca 5 e-2 ef 1 -4 ac 2 -836 d-74124811516 c" , "partition. Key": "DB 2 JXBWBLCL 09 FJFU", "entity. Type": "Trip", "vin": "DB 2 JXBWBLCL 09 FJFU", "consignment. Id": "1 f 145 aad-d 943 -44 c 7 -b 0 f 3 -1 bc 8562 c 7628" , "planned. Trip. Distance": 190. 53, "location": "OR", … "status": "Pending", "timestamp": "0001 -01 -01 T 00: 00", "packages": [ { "package. Id": "514 edbdc-210 b-45 f 8 -b 05 f-d 491 d 6 ded 7 e 4" , "storage. Temperature": 22, "high. Value": false }, …… { "package. Id": "26128844 -cc 3 f-4808 -99 f 7 -2 b 142 ad 002 e 5" , "storage. Temperature": 32, "high. Value": false } ], "consignment": { "consignment. Id": "1 f 145 aad-d 943 -44 c 7 -b 0 f 31 bc 8562 c 7628", "customer": "Bellows College", "delivery. Due. Date": "2019 -10 -20 T 05: 56: 44. 7367547 Z" }] [{ "id": "ad 476 b 94 -8 b 3 a-4 ab 8 -ba 5 f-b 95 ad 75 acd 63" , “package. Id": " 26128844 -cc 3 f-4808 -99 f 7 -2 b 142 ad 002 e 5" , "partition. Key": " 26128844 -cc 3 f-4808 -99 f 7 -2 b 142 ad 002 e 5" , "entity. Type": "Package", "trip. Id": "ed 96 feb 9 -957 e-4 d 30 -873 e-7 a 4 f 12266022" , "consignment. Id": "cb 56399 c-65 b 3 -452 b-89 f 0 -d 3 b 9 bed 5 fa 02" , "height": 33. 37, "length": 41. 45, "width": 20. 96, "gross. Weight": 223. 72, "storage. Temperature": 39, "high. Value": false, "trip": { "trip. Id": "ed 96 feb 9 -957 e-4 d 30 -873 e-7 a 4 f 12266022" , "vin": "AESQX 3 ZKCFM 25 HNNE", "planned. Trip. Distance": 137. 09 }, "consignment": { "consignment. Id": "cb 56399 c-65 b 3 -452 b-89 f 0 -d 3 b 9 bed 5 fa 02" , "customer": "Lamna Healthcare Company", "delivery. Due. Date": "2019 -10 -20 T 08: 26: 44. 7366267 Z" }, "timestamp": "0001 -01 -01 T 00: 00", }]
Demo – Querying multiple data types in 1 collection Packages & Trips
How many of you had this reaction…?
Let’s debug and optimize now… SDK – client side performance optimizations DEMO
SDK – client side tips & tricks
Let’s monitor with Diagnostic Logs
Query 1: Identifying throttles & hot partitions // See all the 429 s Azure. Diagnostics | where Time. Generated >= ago(8 hr) | where Category == "Data. Plane. Requests" | where status. Code_s == 429 | summarize count() by database. Name_s, collection. Name_s
Use Cosmos DB metrics in Portal to identify hot partitions
Monitor storage distribution in Metrics
Query 2: Identifying Top RU consuming queries Azure. Diagnostics | where Resource. Provider=="MICROSOFT. DOCUMENTDB" and Category=="Data. Plane. Requests" and todouble(request. Charge_s) > 100. 0 | project activity. Id_g, request. Charge_s | extend activity. Id = tostring(activity. Id_g) | join kind= inner ( Azure. Diagnostics | where Resource. Provider =="MICROSOFT. DOCUMENTDB" and Category == "Query. Runtime. Statistics" | project activity. Id_g, querytext_s ) on $left. activity. Id_g == $right. activity. Id_g | order by request. Charge_s desc | limit 100
Production readiness
Production readiness checklist
Production readiness checklist
Summary
• https: //github. com/deborahc/cosmos-perf-tips • Code Session Title Speaker Name(s) Timeslot Name Timeslot Date BRK 4000 Multi-Master and global distribution with Azure Cosmos DB Data modelling and partitioning in Azure Cosmos DB: What every BRK 3015 relational database user needs to know Mark Brown Thursday 11: 45 -12: 30 Thomas Weiss Friday 11: 45 -12: 30 11/07/2019 BRK 3014 What’s new with Cosmos DB API for Mongo. DB Sri Chintala Friday 1: 00 -1: 45 11/08/2019
- Slides: 43