The Azure Cosmos DB Blog

All about Azure Cosmos DB and Azure

Category: Articles (page 1 of 7)

Azure Best Practices

Recently a client (IoT Device Manufacturer) asked me to provide them with a Best Practices guideline for migrating their IoT Services to Azure. I told them that there wasn’t a single guideline that encompasses everything, that there are many Best Practices Guidelines available.

I recommended that they start off with selecting the Architecture that is best suited to meet business requirements.

This is what I provided them.

Application Architecture Guide

1. We start off with selecting the Architectural Style.

There are several Architectural Styles that can be used. It has been my experience that the Microservices Architectural Style works best for IoT solutions. Another is the Event-driven Architectural Style.

2. Decide on the technology that will be used for Azure Applications.

  • Compute Options – refers to the hosting model for the computing resources that your application runs on. The main compute options available are Virtual Machines, App Service, Service Fabric, Azure Container Services, Azure Functions, Azure Batch, and Cloud Services.
  • Data Store – a single data store is usually not the best approach. Instead, it’s often better to store different types of data in different data stores, each focused towards a specific workload or usage pattern. These stores include Key/value stores, Document databases, Graph databases, Column-family databases, Data Analytics, Search Engine databases, Time Series databases, Object storage, and Shared files.

3. Following Design Principles is next

  • In a distributed system, failures happen. Design your application to be self healing when failures occur.
  • Build redundancy into your application, to avoid having single points of failure.
  • Minimize coordination between application services to achieve scalability.
  • Design your application so that it can scale horizontally, adding or removing new instances as demand requires.
  • Use partitioning to work around database, network, and compute limits.
  • Design your application so that the operations team has the tools they need.
  • When possible, use platform as a service (PaaS) rather than infrastructure as a service (IaaS).
  • Pick the storage technology that is the best fit for your data and how it will be used.
  • All successful applications change over time. An evolutionary design is key for continuous innovation.
  • Every design decision must be justified by a business requirement.

Software Quality is extremely important for a successful cloud application.

  • Scalability – The ability of a system to handle increased load.
  • Availability – The proportion of time that a system is functional and working.
  • Resiliency – The ability of a system to recover from failures and continue to function.
  • Management Operations processes that keep a system running in production.
  • Security – Protecting applications and data from threats.

Enforcing the use of Cloud Design Patterns will insure that your applications will be reliable, scalable, and secure.


  • Providing a high-level summary for choosing their Architectural Style and the Compute/ Data Store Technology choices, made it easier for them to understand.
  • Once they reviewed the information, I was able to answer their questons and provide them guidance on implementing Steps 1 and 2.

Using Microsoft PowerApps and Flows to query Cosmos DB Log Analytics

PowerApps with Flow simplify the task of querying Azure Log Analytics.
This tutorial will show you how easy it is to create a PowerApps application

The application does the following

  1. Queries Azure Log Analytics .
  2. Generates a chart result.
  3. Sends an email with the visualization embedded.

Creating the application

The following figure shows the workflow steps.


These steps to create the workflow are:

  1. Use a PowerApps button to start the process.
  2. Add the Azure Log Analytics action as shown below

Log Analytics
A. Select Run Query and visualize results

The Chart types are: 

Chart type
Select HTML which creates a Table

  1. Add a Condition to validate that the records exist
    @not(equals(length(body('Run_query_and_visualize_results')?['body']), 0))

    1. if Yes then use the Office 365 action to send a email
      Send Email
    2. If No then add a Terminate action with a Cancelled value
  2. Click Save.

NOTE: For this tutorial we are using live data from Cosmos DB Diagnostic Logging

The following is an example of the Azure Log Analytics data.


             "time": "2018-02-02T18:21:52.7720997Z",
             "category": "DataPlaneRequests",
             "operationName": "ReadFeed",
             "properties": {"activityId": "4e22c5e3-3169-4e02-a6b5-84fd69284e28","requestResourceType": "Document","requestResourceId": "jdUKAPpYJQA=","collectionRid": "jdUKAPpYJQA=","statusCode": "304","duration": "4092","userAgent": "documentdb-dotnet-sdk/1.17.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0changefeed-0.2","clientIpAddress": "","requestCharge": "1.000","requestLength": "0","responseLength": "0","resourceTokenUserRid": "","region": "Central US","partitionId": "6a6ca36b-7a1d-42b5-b866-3e5eed09186e"}
             "time": "2018-02-02T18:22:54.2597286Z",
             "category": "DataPlaneRequests",
             "operationName": "ReadFeed",
             "properties": {"activityId": "8d2dc86b-e7dc-4727-bab2-b8d3986b298e","requestResourceType": "Document","requestResourceId": "jdUKAPpYJQA=","collectionRid": "jdUKAPpYJQA=","statusCode": "304","duration": "3885","userAgent": "documentdb-dotnet-sdk/1.17.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0changefeed-0.2","clientIpAddress": "","requestCharge": "1.000","requestLength": "0","responseLength": "0","resourceTokenUserRid": "","region": "Central US","partitionId": "6a6ca36b-7a1d-42b5-b866-3e5eed09186e"}
             "time": "2018-02-02T18:24:06.0068309Z",
             "category": "DataPlaneRequests",
             "operationName": "ReadFeed",
             "properties": {"activityId": "cc5a0c11-a523-47c9-9a91-d0889cfae4b6","requestResourceType": "Document","requestResourceId": "jdUKAPpYJQA=","collectionRid": "jdUKAPpYJQA=","statusCode": "304","duration": "4181","userAgent": "documentdb-dotnet-sdk/1.17.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0changefeed-0.2","clientIpAddress": "","requestCharge": "1.000","requestLength": "0","responseLength": "0","resourceTokenUserRid": "","region": "Central US","partitionId": "6a6ca36b-7a1d-42b5-b866-3e5eed09186e"}
             "time": "2018-02-02T18:24:16.2453179Z",
             "category": "DataPlaneRequests",
             "operationName": "ReadFeed",
             "properties": {"activityId": "6f3249cb-d3e3-4756-872c-5de5f6b7a291","requestResourceType": "Document","requestResourceId": "jdUKAPpYJQA=","collectionRid": "jdUKAPpYJQA=","statusCode": "304","duration": "2810","userAgent": "documentdb-dotnet-sdk/1.17.0 Host/64-bit MicrosoftWindowsNT/6.2.9200.0changefeed-0.2","clientIpAddress": "","requestCharge": "1.000","requestLength": "0","responseLength": "0","resourceTokenUserRid": "","region": "Central US","partitionId": "6a6ca36b-7a1d-42b5-b866-3e5eed09186e"}

Testing our Workflow

  1. Start by clicking on as shown below.
  2. Enter our query and email subject as shown in the following figure.


INFO: You can read more about Log Analytics searches here

  1. After clicking on Run flow, we can view the process results.


Checking our email, we can see the results.


Monitoring our workflow

We can view the Flow Analytics as shown below.


Finally we can view our Flow administration



  • You have seen how easy it is to create a PowerApps with Flow application
  • You can create custom log searches.
  • You can edit the flow to change the chart type
  • You can extend the flow to add more actions.
  • You can easily modify the data connections.

More Info

You can ready more about Microsoft PowerApps/Flows here

Older posts
%d bloggers like this:
Skip to toolbar