Presentation is loading. Please wait.

Presentation is loading. Please wait.

Developer Intro to Cosmos DB

Similar presentations


Presentation on theme: "Developer Intro to Cosmos DB"— Presentation transcript:

1 Developer Intro to Cosmos DB

2 About Me Brandon Brockhoeft
BIO Brandon is a career software engineer working primarily with Microsoft solutions with over 15 years of professional experience. He has provided development and architecture technology solutions in the finance, state government, energy, and aerospace industries. His functional expertise includes: full-stack development, distributed architecture, real-time communication, DevOps and agile transformation, & mentoring. Brandon Brockhoeft Principal Consultant @bbrockhoeft22 brandon-brockhoeft-55777a1

3 What is Cosmos DB? Globally distributed, multi-model DB Azure service
Schema-less (Code is the schema!) Transparently replicates data Multi-master writes Consistency choices Automatic indexing SQL and NoSQL APIs Changefeed (CEP)

4 DB Usage Comparison Cosmos DB SQL Server Scale Horizontal Vertical
Data Geo-Distributed / Eventual Consistency Integrity and Consistency Focused Cost Throughput and Storage-based CPU-based Tooling Microsoft and Dev Community Microsoft and Commercial Products

5 Cosmos DB Setup Containers and Partitions Partition Keys
Request units: item size, indexing, property count, consistency, query patterns RU/s = $ Cost Insufficient funds = throttled requests

6 Indexing Cosmos DB automatically indexes every property for all items in your container Indexing done synchronously when data is written Indexes are written as trees used to map to property paths: /locations/1/country: "France" Customize indexing by setting its indexing mode & include/exclude property paths Order by multiple properties requires custom composite indexes Index transformation done online and in-place: impacts query consistency

7 Tools Cosmos DB Data Migration Tool
Build / Download: Documentation: Manage and automate Cosmos DB resources: PowerShell Azure CLI Azure Resource Manager templates Work with data (using SQL) Cosmos DB Playground: Document Explorer - Azure or Local Emulator

8 Data Modeling Code-first at all times
Performing w/o a net: little constraints, no cascading, few DB types, no sizes, or defaults Have well-defined and tested validation patterns Mistakes not as easily corrected* (as SQL Server) Self-joins only in SQL API Unique key constraints only within partition Implies document ID is not the partition ID Can be single property or composite key Cannot be changed; requires new container + data migration Modeling techniques: Embed data (denormalized) Reference data (normalized) Hybrid

9 Data Modeling - Embed All within one JSON document - allows single read/write Duplication of data is okay Typically better read performance Useful when: Contained relationships between entities One-to-few relationships between entities Embedded data that changes infrequently Embedded data that will not grow without bound Embedded data that is queried frequently together { "id": "1", "firstName": "Thomas", "lastName": "Andersen", "addresses": [ "line1": "100 Some Street", "line2": "Unit 1", "city": "Seattle", "state": "WA", "zip": 98012 } ], "contactDetails": [ {" ": {"phone": " "} ]

10 Data Modeling - Reference
No foreign-keys / weak links only Requires multiple database trips Don’t create join containers Typically better write performance Consider data growth for relationship Useful when: Representing one-to-many relationships Representing many-to-many relationships Related data changes frequently Referenced data could be unbounded Author documents: {"id": "a1", "name": "Thomas Andersen", "books": ["b1, "b2", "b3"]} {"id": "a2", "name": "William Wakefield", "books": ["b1", "b4"]} Book documents: {"id": "b1", "name": "Azure Cosmos DB 101", "authors": ["a1", "a2"]} {"id": "b2", "name": "Azure Cosmos DB for RDBMS Users", "authors": ["a1"]} {"id": "b3", "name": "Learn about Azure Cosmos DB", "authors": ["a1"]} {"id": "b4", "name": "Deep Dive into Azure Cosmos DB", "authors": ["a2"]}

11 Data Modeling - Hybrid Author documents: Book documents: { "id": "a1",
"firstName": "Thomas", "lastName": "Andersen", "countOfBooks": 3, "books": ["b1", "b2", "b3"], "images": [ {"thumbnail": " {"profile": " {"large": " ] }, "id": "a2", "firstName": "William", "lastName": "Wakefield", "countOfBooks": 1, "books": ["b1"], } Book documents: { "id": "b1", "name": "Azure Cosmos DB 101", "authors": [ {"id": "a1", "name": "Thomas Andersen", "thumbnailUrl": " {"id": "a2", "name": "William Wakefield", "thumbnailUrl": " ] }, "id": "b2", "name": "Azure Cosmos DB for RDBMS Users", {"id": "a1", "name": "Thomas Andersen", "thumbnailUrl": " }

12 Sample Azure Data Explorer
SQL Query examples - see CosmosDemo/CustomerContact/docs/SQL_Samples.md Customer Contact Demo application with C# SDK (v3) ASP.NET sample app with form data

13 More Info Conference video on Cosmos DB by Jimmy Bogard
Microsoft documentation (Used for presentation content) Microsoft dotnet SDK reference Query cheat sheets

14 Session Evaluations Session Evaluations are ONLINE ONLY. Your feedback is valuable! SQLSatBR.com/Sessions/SessionEvaluation.aspx

15 Changefeed Event Driven Architecture by default
Lambda Architecture with low TCO Use Azure Functions without infrastructure concerns Observe container changes sorted within partition key Consumer parallel processing available by partition key Use soft markers for data operation filtering (insert/update/delete) Consider use of TTL and start time options

16 Data Modeling - Mixed Types
Book and Review documents in one container: { "id": "b1", "name": "Azure Cosmos DB 101", "bookId": "b1", "type": "book" }, "id": "r1", "content": "This book is awesome", "type": "review" "id": "r2", "content": "Best book ever!", }


Download ppt "Developer Intro to Cosmos DB"

Similar presentations


Ads by Google