Coding Blocks

This is a special episode recorded at Microsoft Ignite 2018 where John Callaway from The 6 Figure Developer Podcast joins Allen Underwood to talk about Azure Functions and CosmosDB. Find out what they are and why you might want to try them out for yourself. Using your podcast player to read these show notes? You can view this episode’s full show notes and participate in the discussion over at https://www.codingblocks.net/episode92

Sponsors

  • Datadog.com/codingblocks – Sign up today for a free 14 day trial and get a free Datadog t-shirt after creating your first dashboard.

News

  • Huge thank you to all those that left us a review, we really do appreciate it.
    • iTunes: Rick Wolter, Nikola Jankovic

Big Thanks to Microsoft

  • Huge thanks to Microsoft for having us out here to record an episode at Microsoft Ignite in their podcast booths!

If you’ve not heard of Ignite, here’s why you might care…

  • Over 700 deep dive sessions
  • Over 100 self-paced workshops
  • Watch demos, check out the latest technology, meet the experts
  • Keynotes from speakers such as Satya Nadella
  • Swag…of course you come for the swag

Azure Functions

What are they?

  • Serverless - just means you don’t have a server running 24/7 that you’re paying for
    • No provisioning or maintaining servers - all handled by Azure managed compute platform
  • Scales on demand
  • Supports multiple languages (depending on trigger types)

Why should you care?

  • Easy and inexpensive way to get familiar with the cloud
  • Ability to create powerful, low-cost micro services
  • Worry about your application functionality, and not your infrastructure

ANNOUNCEMENT

How do you use them?

  • Through the use of Triggers
    • HTTP
    • Timer
    • Queue
    • Service Bus Queue
    • Service Bus Topic
    • Blob
    • Event Hub
    • CosmosDB
    • IoT Hubs (Event / Service Bus)
    • Generic Webhook
    • External File
    • And More…
  • Most of the more generic trigger types support C#, F# and Javascript
  • There is also support for additional languages in experimental mode such as: Bash, Batch, PHP, PowerShell, Python and Typescript

Best Practices

  • Avoid long running functions - under 5 minutes from what I’ve seen
  • If not using “Durable Functions”, use storage queues for cross function communication
    • There are limits on storage queue size - 64KB - if that’s a problem, utilize storage blobs
  • Write functions to be stateless
    • If state needs to be maintained, use state on the data itself, such as having a state member or property
    • Write the function to be idempotent - it will return the same value with the same inputs
  • Write defensive functions
  • Scalability and how function scaling works https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale
    • Assuming the “Consumption Plan”
      • CPU and RAM scale up automatically - up to 1.5GB of RAM
      • Function apps that share the same consumption plan scale independently
      • Function files are stored on the main storage account associated with the function
    • Interesting gotcha - when using a blob trigger, it can take up to 10 minutes for a blob to be processed if the function went to sleep
      • Can avoid this by having an App Service plan with Always Enabled turned on, or use an Event Grid trigger
    • A scale controller automatically scales up the number of instances of the function to meet demand
      • Maximum number of 200 instances - created 10 seconds apart
        • There is no maximum number of concurrent requests a function can handle though
          • Need to be concerned with number of connections being used - 300 is the limit
  • Billing is in gigabyte-seconds - combination of the memory size and execution time of the function
    • At the time of this writing…
      • Consumption plan pricing includes a monthly free grant of 1 million requests and 400,000 GB-s of resource consumption per month
        • GB-s = Average memory size in Gigabytes (rounded up to the nearest 128MB) times the execution time in milliseconds
          • Minimum is 100ms and 128MB
        • $0.000016/GB-s
      • 1 million executions is $0.20 https://azure.microsoft.com/en-us/pricing/details/functions/
  • Best Practices https://docs.microsoft.com/en-us/azure/azure-functions/functions-best-practices

Useful Tools for Azure Functions and CosmosDB (and Azure in general)

CosmosDB

What is it?

  • Globally distributed, multi-model database for any scale
  • It offers throughput, latency, availability, and consistency guarantees with comprehensive service level agreements (SLAs), something no other database service can offer
  • Can distribute your data to any azure regions with the click of a button
  • Multi-homing API’s can detect your nearest enabled data center and route traffic there for lowest possible latency
    • All you do is add regions you want to scale to, no application changes necessary

Multi-Model

  • Uses the Atom-Record-Sequence (ARS) based data model - this just means it natively supports multi-models
    • Document, Graph, Key-Value, Table, Column-Family, and others
  • A number of API’s are available in multiple language SDKs
    • SQL - schema-less JSON database storage with SQL querying capability
    • MongoDB - MongoDB as a service - scalable and expressive document database
    • Cassandra - CassandraDB as a service - highly available, document database
    • Gremlin - Graph Database
    • Table - Key-Value storage - similar to Azure Table Storage but with lower latency, globally available, automatic-indexing with little to no code changes

Scalability

  • Scales at per second granularity
  • Storage scales transparently and automatically
  • For a typical 1KB item, Cosmos DB guarantees end-to-end latency of reads under 10 ms and indexed writes under 15 ms at the 99th percentile, within the same Azure region. The median latencies are significantly lower (under 5 ms).

High Availability

  • 99.99% availability SLA for all single region database accounts, and all 99.999% read availability on all multi-region database accounts.
  • Tunable consistency levels - allows you to choose how important consistent reads and writes are

Don’t Worry About Performance

  • Wait, what?!
    • Rapidly iterate the schema of your application without worrying about database schema and/or index management.
    • Azure Cosmos DB’s database engine is fully schema-agnostic – it automatically indexes all the data it ingests without requiring any schema or indexes and serves blazing fast queries.

Who’s it For?

  • Any web, mobile, gaming, and IoT application that needs to handle massive amounts of data, reads, and writes at a global scale with near-real response times for a variety of data will benefit from Azure Cosmos DB’s guaranteed high availability, high throughput, low latency, and tunable consistency.

Monitoring

Azure Functions

  • Built in monitoring using function storage for logging - limited information
  • Azure Application Insights - preferred method
    • There’s a daily limit for free monitoring, so pay close attention to your caps
    • Configure via an instrumentation key

Cosmos DB

  • Simply choose the Metrics page of the Cosmos DB to watch
  • Can also pull the performance information using the SQL API’s

Resources we Like

https://functionschallenge.azure.com/ https://microsoft.com/learn If you don’t have a PluralSight account, start a free trial and then check out the courses below: https://www.codingblocks.net/pluralsight https://app.pluralsight.com/library/courses/azure-functions-fundamentals https://app.pluralsight.com/library/courses/csharp-code-azure-functions-reducing-duplication

Tip of the Week

 

Direct download: coding-blocks-episode-92.mp3
Category:Software Development -- posted at: 8:12pm EST

We continue our dive into how to learn things while Michael's voice sounds an awful lot like Joe's, Joe says it's a square, and Allen says it's as triangle ... oh, and Google Feud is back!

Direct download: coding-blocks-episode-91.mp3
Category:Software Development -- posted at: 9:14pm EST

1