Presentation is loading. Please wait.

Presentation is loading. Please wait.

Azure Cosmos DB: Design Patterns and Case Studies

Similar presentations


Presentation on theme: "Azure Cosmos DB: Design Patterns and Case Studies"— Presentation transcript:

1 Azure Cosmos DB: Design Patterns and Case Studies
6/1/ :20 AM BRK4008 Azure Cosmos DB: Design Patterns and Case Studies Andrew Liu PM, Azure Cosmos DB Andrew Potts Solution Architect, ASOS Mike Gore Solution Architect, ASOS © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

2 Outline A quick overview (recap) Common Scenarios and Architectures
6/1/ :20 AM Outline A quick overview (recap) Common Scenarios and Architectures Partitioning Design Change Feed Case Study: Event ASOS Q&A © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

3 Azure Cosmos DB Table API MongoDB API
A globally distributed, massively scalable, multi-model database service Table API MongoDB API Key-value Column-family Document Graph Guaranteed low latency at the 99th percentile Elastic scale out of storage & throughput Five well-defined consistency models Turnkey global distribution Comprehensive SLAs

4 Common Scenarios 6/1/2018 11:20 AM
© Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

5 Internet of Things – Telemetry & Sensor Data
Business Needs: High scalability to ingest large # of events coming from many devices Low latency queries and changes feeds for responding quickly to anomalies Schema-agnostic storage and automatic indexing to support dynamic data coming from many different generations of devices High availability across multiple data centers

6 Internet of Things – Telemetry & Sensor Data
Microsoft Build 2017 6/1/ :20 AM Internet of Things – Telemetry & Sensor Data Aggregated + Archived Events (Cold) pre-aggregates Apache Storm on Azure HDInsight Azure Cosmos DB (Hot) (telemetry and device state) Azure IoT Hub high-fidelity events PowerBI latest state Azure Logic Apps Azure Web Jobs (Change feed processor) © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

7 E-Commerce – Product Catalog & Order Processing
Business Needs: Elastic scale to handle seasonal traffic (e.g. Black Friday) Low-latency access across multiple geographies to support a global user-base and latency sensitive workloads (e.g. real-time personalization) Schema-agnostic storage and automatic indexing to handle diverse product catalogs, orders, and events High availability across multiple data centers

8 Retail Product Catalogs
Azure Web App (e-commerce app) Azure Cosmos DB (product catalog) (session state) Azure Search (full-text index) Azure Storage (logs, static catalog content)

9 Real-time Recommendations
Azure Cosmos DB (Distributed Model Store) E-commerce Website (Product Details Page) Azure Event Hub Azure Data Lake Storage (Offline Raw Data) Apache Spark on Azure HDInsight + Azure Data Factory (Scheduled Job to Refresh Persisted Models) Azure Service Fabric (Personalization Decision Engine) Online Recommendations Service (HOT path) Offline Recommendations Engine (COLD path) Shoppers

10 Retail Order Processing Pipelines
Stay tuned for a special deep dive 

11 Multiplayer Gaming Business Needs:
Elastic scale to handle bursty traffic on day Low-latency queries to support responsive gameplay for a global user-base Schema-agnostic storage and indexing allows teams to iterate quickly to fit a demanding ship schedule Change-feeds to support leaderboards and social gameplay

12 Multiplayer Gaming Azure CDN Azure Storage (game files)
Azure Cosmos DB (game database) Azure HDInsight (game analytics) Azure CDN Azure API Apps (game backend) Azure Storage (game files) Azure Notification Hubs (push notifications) Azure Functions Azure Traffic Manager

13 Partitioning Design 6/1/2018 11:20 AM
© Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

14 Cosmos DB Container (e.g. Collection)

15 Cosmos DB Container (e.g. Collection)

16 Cosmos DB Container (e.g. Collection)
Partitioning Scheme: top-most design decision in Cosmos DB

17 Cosmos DB Container (e.g. Collection)
Partition Key: User Id

18 Cosmos DB Container (e.g. Collection)
Partition Key: User Id Logical Partitioning Abstraction hash(User Id) Behind the Scenes: Physical Partition Sets Psuedo-random distribution of data over range of possible hashed values

19 Physical Partition Sets hash(User Id)
Behind the Scenes: Physical Partition Sets hash(User Id) Dharma Andrew Shireesh Karthik Rimma Mike …. Bob Alice Carol Partition 1 Partition 2 Partition n Frugal # of Partitions based on actual storage and throughput needs (yielding scalability with low total cost of ownership)

20 Physical Partition Sets hash(User Id)
Behind the Scenes: Physical Partition Sets hash(User Id) Dharma Andrew Shireesh Karthik Rimma Mike …. Bob Alice Carol Partition 1 Partition 2 Partition n What happens when partitions need to grow?

21 Physical Partition Sets hash(User Id)
Behind the Scenes: Physical Partition Sets hash(User Id) Partition Ranges can be dynamically sub-divided To seamlessly grow database as the application grows While sedulously maintaining high availability Partition X Dharma Shireesh Karthik Rimma Alice Carol + Partition X1 Partition X2

22 Physical Partition Sets hash(User Id)
Behind the Scenes: Physical Partition Sets hash(User Id) Partition Ranges can be dynamically sub-divided To seamlessly grow database as the application grows While sedulously maintaining high availability Best of All: Partition management is completely taken care of by the system You don’t have to lift a finger… the database takes care of you. Partition X Dharma Shireesh Karthik Rimma Alice Carol + Partition X1 Partition X2

23 Cosmos DB Container (e.g. Collection)
Best Practices: Design Goals for Choosing a Good Partition Key Distribute the overall request + storage volume Avoid “hot” partition keys Avoid blind fan-outs for queries Queries can be intelligently routed via partition key

24 Cosmos DB Container (e.g. Collection)
Best Practices: Design Goals for Choosing a Good Partition Key Distribute the overall request + storage volume Avoid “hot” partition keys Avoid blind fan-outs for queries Queries can be intelligently routed via partition key Steps for Success Ballpark scale needs (size/throughput) Understand the workload # of reads/sec vs writes per sec Use 80/20 rule to help optimize bulk of workload For reads – understand top X queries (look for common filters) For writes – understand ratio of inserts vs updates

25 Cosmos DB Container (e.g. Collection)
Best Practices: Design Goals for Choosing a Good Partition Key Distribute the overall request + storage volume Avoid “hot” partition keys Avoid blind fan-outs for queries Queries can be intelligently routed via partition key Steps for Success Ballpark scale needs (size/throughput) Understand the workload # of reads/sec vs writes per sec Use 80/20 rule to help optimize bulk of workload For reads – understand top X queries (look for common filters) For writes – understand ratio of inserts vs updates General Tips Don’t be afraid of having too many partition keys Partitions keys are logical More partition keys => more scalability

26 6/1/ :20 AM Change Feed © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

27 Azure Cosmos DB Change Feed
6/1/ :20 AM Azure Cosmos DB Change Feed Persistent log of records within an Azure Cosmos DB container in the order in which they were modified © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

28 Event Sourcing for Microservices
6/1/ :20 AM Event Sourcing for Microservices Trigger Action From Change Feed Persistent Event Store Microservice #1 Microservice #2 New Event Microservice #N © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

29 Materializing Views Application Cosmos DB Materialized View 123abc
6/1/ :20 AM Materializing Views Application Cosmos DB Materialized View Subscription User Create Date 123abc Ben6 6/17/17 456efg 3/14/17 789hij Jen4 8/1/16 012klm Joe3 3/4/17 User Total Subscriptions Ben6 2 Jen4 1 Joe3 © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

30 Replicating Data Secondary Datastore (e.g. archive) Replicate Records
6/1/ :20 AM Replicating Data Secondary Datastore (e.g. archive) Replicate Records CRUD Data © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

31 Working with Change Feed
6/1/ :20 AM Working with Change Feed © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

32 Working with Change Feed
6/1/ :20 AM Working with Change Feed Step 1: Retrieve a list of the partition key ranges © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

33 Working with Change Feed
6/1/ :20 AM Working with Change Feed Step 2: Consume the Change Feed on each PartitionKeyRange © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

34 Change Feed Processor Library
6/1/ :20 AM Change Feed Processor Library © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

35 Behind the Scenes 6/1/2018 11:20 AM
© Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

36 Working with Change Feed Processor Library
6/1/ :20 AM Working with Change Feed Processor Library Step 1: Implement ProcessChangesAsync() on IChangeFeedObserver © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

37 Working with Change Feed Processor Library
6/1/ :20 AM Working with Change Feed Processor Library Step 2: Register the IChangeFeedObserver with to a ChangeFeedEventHost © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

38 Case Study: Event Sourcing with Cosmos DB @ ASOS
6/1/ :20 AM Case Study: Event Sourcing with Cosmos ASOS Andrew Potts Mike Gore © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

39 6/1/ :20 AM Welcome to ASOS! © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

40 We work at Scale 85,000 ASOS and branded products on site
6/1/ :20 AM We work at Scale 85,000 ASOS and branded products on site 4,000 new items added each week 15 million active customers 100 million page views / day 893 product requests / second 33 orders / second And growing! © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

41 Why did we chose Cosmos DB?
6/1/ :20 AM Why did we chose Cosmos DB? Support for flexible Document data model Platform as a Service (PaaS) Predictable performance with RUs You can scale up and down Data can be geo-replicated High availability SLAs The change feed fits our architecture © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

42 Returns Express Architecture
6/1/ :20 AM Returns Express Architecture Validation Service Delivery Service Refund Service Booking API Returns Collection Europe Event Store Validation Service Notification Service Europe Booking API Returns Collection US Accent 1 Accent 2 Accent 3 Accent 4 Accent 5 Accent 6 © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

43 Use case 1 – booking a return
6/1/ :20 AM Use case 1 – booking a return © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

44 Our requirements Take bookings from all around the world
6/1/ :20 AM Our requirements Take bookings from all around the world Respond as quickly as possible Always be available Provide the highest SLAs Scale when needed My connection may be unreliable I may be on a train Requests may be retried © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

45 Our first approach – using a message queue
Returns Booking Processor Region A Region B Accent 1 Accent 2 Accent 3 Accent 4 Accent 5 Accent 6 © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

46 Approach #2 - save the request first!
6/1/ :20 AM Approach #2 - save the request first! Returns Booking Processor Region A Region B Accent 1 Accent 2 Accent 3 Accent 4 Accent 5 Accent 6 © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

47 Cosmos DB change feed Change feed processor Region A
6/1/ :20 AM Cosmos DB change feed Change feed processor Region A Change feed processor Region B Accent 1 Accent 2 Accent 3 Accent 4 Accent 5 Accent 6 © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

48 Demo – booking a return Andrew Potts 6/1/2018 11:20 AM
© Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

49 Returns Booking Processor
6/1/ :20 AM Demo – Booking a Return Change feed processor Booked Returns Returns Booking Processor Region A Event Store Change feed processor Booked Returns Region B Accent 1 Accent 2 Accent 3 Accent 4 Accent 5 Accent 6 © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

50 Use case 2 - processing returns
6/1/ :20 AM Use case 2 - processing returns © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

51 Event sourcing Return Created Return Accepted Delivery Booked
6/1/ :20 AM Event sourcing Return Id Status Refund Currency Refund Amount Created on Last modified 1234 Refund Authorized GBP 100.00 10/10/16 12:00 10/10/16 14:00 5678 Delivery Booked USD 30.00 10/10/16 12:10 10/10/16 15:00 compared to Accent 5 Return Created Return Accepted Delivery Booked Stream Id = “1234” First Scan Received Refund Authorized © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

52 How we structure events
6/1/ :20 AM How we structure events public class ReturnCreated { public Guid Id {get;} public DateTime Timestamp {get;} public string ReturnReference {get;} public int CustomerId {get;} public Product[] ReturnedProducts {get;} } © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

53 Cosmos DB + event sourcing
6/1/ :20 AM Cosmos DB + event sourcing Accent 5 Return Created Return Accepted Delivery Booked Return 123 Accent 5 Return Created Return Accepted Return 456 Geo-replicates to © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

54 Demo – event sourcing Mike Gore 6/1/2018 11:20 AM
© Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

55 Use case 3 – integrating with other systems
6/1/ :20 AM Use case 3 – integrating with other systems © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

56 Cosmos DB + microservice integration
6/1/ :20 AM Cosmos DB + microservice integration Returns Booking Processor Event Publisher Appends to Reads change feed Publishes to Integrating Service Receives © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

57 Demo – publish to Service Bus
6/1/ :20 AM Demo – publish to Service Bus Andrew Potts © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

58 Use case 4 - viewing returns
6/1/ :20 AM Use case 4 - viewing returns © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

59 Cosmos DB + read models Customer Returns Projection
6/1/ :20 AM Cosmos DB + read models West Europe Customer Returns Projection Customer Returns API Writes to Reads from Events Geo-replicates to North Europe Customer Returns Projection Customer Returns API Writes to Reads from Events © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

60 Demo – projections Mike Gore 6/1/2018 11:20 AM
© Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

61 Other Cosmos DB use cases at ASOS
6/1/ :20 AM Other Cosmos DB use cases at ASOS Pricing Recommendations Payments Saved Items © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

62 Summary Cosmos DB meets the high scale demands of ASOS
6/1/ :20 AM Summary Cosmos DB meets the high scale demands of ASOS Change Feed enables scalable, simple event sourcing and read model projections Azure Functions is an alternative approach to working with the Change Feed that allows you to focus on your business logic © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

63 Please evaluate this session
Tech Ready 15 6/1/2018 Please evaluate this session From your Please expand notes window at bottom of slide and read. Then Delete this text box. PC or tablet: visit MyIgnite Phone: download and use the Microsoft Ignite mobile app Your input is important! © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

64 Thank you and Q&A! References Azure Cosmos DB – cosmosdb.com
6/1/2018 Thank you and Q&A! References Azure Cosmos DB – cosmosdb.com Change Feed Processor (GitHub) – aka.ms/cosmosdb-cfp Simple Event Store (GitHub) – aka.ms/asos-ses Simple Event Store (NuGet) – aka.ms/asos-ses-nuget ASOS is hiring: asoscareers.asos.com Contact and Follow Us: Andrew Liu Andrew Potts @_AndyPotts Mike Gore @mikegore1000 © 2015 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

65 6/1/ :20 AM © Microsoft Corporation. All rights reserved. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.


Download ppt "Azure Cosmos DB: Design Patterns and Case Studies"

Similar presentations


Ads by Google