Sitemap

Building a Serverless and Cognitive Services solution on Azure for COVID-19 data processing

5 min readMay 14, 2020

--

These days, there is only one thing on the mindshare of every individual, irrespective of industry, job profile or geography — COVID-19. Collectively, we are certain about one thing about the near future — uncertainty. That said, these testing times have provided new opportunities and avenues. For instance, in the IT industry, the extended periods of lockdowns have provided ample time to double up on online learning and skilling. I have been no exception to “binge learning”, if we were to call it that. In fact, spending countless hours of learning paths on the Microsoft Learn platform motivated me to write a detailed blog, where I talked about salient aspects that make a great online learning platform, and why Microsoft Learn was so good.

As I was amassing trophies on MS Learn, I was also motivated to apply these skills and create a relevant, working sample. So, I laid out some broad objectives to get my hands dirty and have some fun with code:

  1. Conceive a use case representative of the current COVID-19 medical crisis.
  2. Apply a combination of at least two powerful Cloud technologies — Serverless and Cognitive Services (AI) on Azure.
  3. Leverage both C# (.NET Core) and Python for development — two of my favourite languages.
  4. Apply published patterns and best practices to the best extent.

The COVID-19 Use Case

We are being bombarded with a ton of data on COVID-19 every day, on every media outlet. That said, we are still unclear about several aspects of the COVID outbreak. For example, we already know the top 3 symptoms. What are other symptoms out there — any new ones? What are the key words medical professionals on the frontlines are noting as they scan patients with symptoms. Any disturbing trends? As COVID warriors take notes, what is the sentiment? Can we infer if majority of the cases are mild? Are the recovery rates good? What other insights can we gather? These are some of the questions for which I decided to build a simple solution for — using Azure Functions and Cognitive Services.

The Implementation

Azure Deployment Architecture for the Serverless and Cognitive Services Sample
Azure Deployment Architecture for the sample

The diagram above (authored using the awesome CloudSkew tool), represents the deployment architecture on Azure. The process flow:

  1. An audio file (WAV) is uploaded to an Azure blob container (possible by an app). Say, the audio file represents notes from a COVID-19 warrior at a testing facility. A sample narration could be something like:

“Patient 2345 was admitted to Manipal hospital today. He had symptoms of cough, difficulty in breathing and mild fever.”

“Patient 1234 was discharged from Victoria Hospital yesterday. He tested negative for two consecutive days.”

2. An Azure function (processSoundFile) is triggered through a blob trigger.

3. The function uses Azure Speech Recognition SDK to get a text transcription from the audio file.

4. The output is then pushed to another blob container as a JSON file.

5. This in turn triggers three more Azure functions through blob triggers.

6. Each function individually performs the following text analytics on this file leveraging the following Cognitive services:

a) Entity Recognition (extractEntities) — returns a list of entities in the field notes narration

b) Key Phrase Extraction (keyPhraseExtraction) — returns key phrases from the field notes narration

c) Sentiment Analysis (processSentiment) — the sentiment of the narration- positive, negative or neutral.

7. The output of text analytics is pushed to Azure CosmosDB and another blob container as JSON documents.

Sample documents in CosmosDB after text analysis looks something like the following:

Sample of output from Extract entities function
Sample output from Key Phrase extraction function
Sample from Sentiment Analysis function

Architecture Considerations

  • At a high level, I have applied the Pipes and Filter Pattern to decompose the different parts of data processing — like speech recognition, text analysis etc. The goal is to develop, deploy and scale independent parts of the application, which are implemented using Azure functions. The asynchronous, event-driven nature of the this solution would therefore be able to accommodate any load of WAV file uploads and downstream processing.
  • While I have used blobs as a trigger for the functions, I could have just as well used Service Bus or Azure Storage Queues for messaging. However, my assumption here is that the output from the Cognitive services can be retained for a longer term and can also be part of a data lake.

Next steps

The solution outlined in this write-up is just the tip of the iceberg. Obviously, it also does not have all the bells and whistles of a production-grade system. There are at least a couple of things that can be improved upon in future iterations:

  1. The real value in a solution like this is downstream big data processing using solutions like Azure Databricks. Databricks can ingest data from either the Blob storage or CosmosDB, run machine learning models to provide insights and trends. These can be consumed by dashboards or be utilized by front end applications to enhance experience.
  2. I have not done much of Inner and Outer loops of DevOps in this sample. To this end, the logical next steps are to setup continuous build and deployment using Azure DevOps. Another important part of this is to add unit tests and mocking.

Source Code

The source code for this sample is on GitHub. For brevity, I have not covered all technical details, configuration settings and bindings in this write-up. Please checkout readme.md and the source code — it is relatively straight forward.

Conclusion

Thus far, this journey of learning and experimentation has been very rewarding. Here are some key takeaways while building this simple solution:

  1. It is relatively easy to AI-enable existing solutions with Azure Cognitive Services. The free tier is good enough for evaluation and prototyping. However, you may need to enrich out-of-box services with your models, trained from data relevant to your business
  2. The development experience of Azure Functions using Visual Studio Code and Azure Functions Core Tools is awesome. However, debugging runs on the Cloud without App Insights can be a steep challenge. Although enabling AppInsights is optional, you may not be left with a choice for monitoring functions.

References

  1. Create serverless applications
  2. Serverless apps: Architecture, patterns, and Azure implementation
  3. Azure Serverless Computing Cookbook, Second Edition
  4. Evaluate text with Azure Cognitive Language Services
  5. Process and translate speech with Azure Cognitive Speech Services

--

--

Responses (2)