Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Build Serverless App with Cosmos DB and Azure F...

Build Serverless App with Cosmos DB and Azure Functions

In this session , we will explore how we can create and deploy event-driven serverless apps with low-latency access to rich data for a global user base. We will also explore some best practices to use cosmos db for building cloud native applications.

Who is the target attendee?
IT Developers/Consultants

Why would that person want to attendee your session?
- To start your journey building scalable API driven cloud native apps.

What can the attendee walk away with?
- How to build and deploy event driven serverless apps with Azure Functions.
- How cosmos db can be helpful to maintain consistency and availability of data geographically in different regions.

Asif Waquar

April 16, 2022
Tweet

More Decks by Asif Waquar

Other Decks in Programming

Transcript

  1. Data Modelling: Relational vs. Document UserID Name Dob 1 John

    Smith 8/30/1964 StockID UserID Qty Symbol 1 1 100 MSFT 2 1 75 WMT Document { "id": 1, "name": "John Smith", "dob": "1964-30-08", "holdings": [ { "qty": 100, "symbol": "MSFT" }, { "qty": 75, "symbol": "WMT" } ] } User Table Holdings Table Relational Store Document Store Rows Documents Columns Properties Strongly-typed schemas Schema-free Highly normalized Typically denormalized
  2. NOSQL DB USE CASES ✓Frequent burst of large activities (IOT)

    ✓Single digit latency (Gaming) ✓Elastic scaled up and down (ecommerce) Eg. Skype ,Xbox ,M365 ,Azure or more
  3. Turnkey global distribution Elastic scale out of storage & throughput

    Comprehensive SLAs Guaranteed low latency at the 99th percentile Five well-defined consistency models Azure Cosmos DB A globally distributed, massively scalable, multi-model database service
  4. Turnkey global distribution Elastic scale out of storage & throughput

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

    storage & throughput Comprehensive SLAs Guaranteed low latency at the 99th percentile Five well-defined consistency models TableAPI Key-value Cosmos DB’s API for MongoDB Azure Cosmos DB A globally distributed, massively scalable, multi-model database service
  6. Features • Multi-model data paradigm: key-value, document, graph, family of

    columns; • Low latency for 99% of queries: less than 10 ms for read operations and less than 15 ms for (indexed) write operations; • Designed for high throughput; • Ensures availability, consistency of data, delay at SLA level of 99.999%; • Configurable throughput; • Automatic replication (master-slave); • Automatic data indexing; • Configurable levels of consistency of data. Five different levels (Strong, Bounded Staleness, Session, Consistent Prefix, Eventual); • Run no-ETL analytics over the near-real time operational data stored in Azure Cosmos DB with Azure Synapse Analytics.
  7. How to start ? • Get your Azure 30 day

    free trial http://azure.microsoft.com • Free try of 30 days of Cosmos DB (no subscription or credit-card required) http://azure.microsoft.com/en-us/try/cosmosdb/ • For local development use the Local Emulator (no internet needed). http://aka.ms/cosmosdb-emulator • For local development capacity planner https://cosmos.azure.com/capacitycalculator/ Take advantage of the Always free tier 25 GB and 400 RU/s (Request Units).
  8. COSMOS DB APIS View your data as traditional NOSQL document

    Store Typical Usage- Product Catalogue Typical Usage : Import historical order data Typical Usage : Web Analytics Application Typical Usage- Store IOT data consisting key value pair with no relationship information Provides graph based view over the data Typical Usage- Recommendation Engine
  9. Account Database Database Database Database Database Container Database Database Item

    Document Vertices/Edges Row Collection Graph Table Item Representations
  10. Account Database Database Database Database Database Container Database Database Item

    Conflict Feed Stored procedure Trigger UDF Container-Level Resources
  11. Store Procedure Trigger User Defined Function Change Feed Stored procedure

    must be defined in JavaScript Triggers must be defined in JavaScript UDF’s must be defined in JavaScript Enables you to be notified for any insert and update on yourdata Executes on a single partition, and it only has access to that partition Triggers can be executed either before (pre) of after (post) data is written Enables you to define a custom function that can be leveraged in a query Deletes are not directly supported, but you can leverage a soft-delete flag Partition key must be provided with the execution request (You should know partition key) Pre triggers can handle data transformation andvalidation Post triggers can handle aggregation and change notifications Enables encapsulation of common logic in query conditions A change will appear exactly once in the change feed Reading data from the database will consume throughput Partition updates will be in order, but between partitions there is no guarantee Supports a transaction model as all statements will be removed if it fails Triggers are not guaranteed to execute, as they have to be specified in a request Errors in either the pre or post trigger will result in data being rolled back Is not supported for the Azure Table API
  12. How do you ensure consistent reads across replicas? - Define

    a consistency level Replication within aregion - Data moves extremely fast (typically, within1ms) between neighboring racks Global replication - Ittakeshundreds of milliseconds to move data across continents Strongerconsistency Higherlatency Loweravailability Weakerconsistency Lower latency Higher availability Replication and Consistency
  13. 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 your perspective: define 1 partition key per container Partitioning
  14. ❑ Triggering a notification or a call to an API,

    when an item is inserted or updated. ❑ Real-time stream processing for IoT or real-time analytics processing on operational data. ❑ Additional data movement by either synchronizing with a cache or a search engine or a data warehouse or archiving data to cold storage.
  15. 1.

  16. Customer Checkout Jet.Com Microservices Item Added Cart Created Item Added

    Cart Checkout Inventory Shipping Customer Input Binding DB Trigger Output Binding
  17. Important Links https://azure.microsoft.com/en-us/pricing/calculator/?service=cosmos-db#cosmos-db7aed2059-b457-48cc- a0e9-6744ce81096b Pricing Calculator https://docs.microsoft.com/en-us/azure/cosmos-db/sql-query-getting-started Azure Cosmos Emulator

    https://docs.microsoft.com/en-us/azure/cosmos-db/local-emulator#controlling-the-emulator SQL API Query http://www.microsoft.com/en-us/download/details.aspx?id=46436 Data Migration Tool