Skip to main content

Azure Stream Analytics (Day 17 of 31)

List of all posts from this series:

Short Description 
In only few words, Stream Analytics is a service that allow us to analyze and process a stream of data in real-time. The most important thing here is real-time. This service allow us to process stream an allow us to react based on the events that are happening on the stream.

Main Features 
This service is able to analyze millions of events per second. Not per hour or minutes, but per second. For example we can analyze stream generated by Event Hub.
Stream Analytics comes not only with capacity, but also with computing power. It is able to analyze the stream content, detect different pattern and trigger different actions.
This is one of the Azure services where resiliency is quaranteed.
No data loss
Once the content reach the stream, the service guarantee to us that no data will be lost. Each bit from the stream will reach the final destination.
He have the ability to stream with multiple stream and processing units. In this way we can scale-up as much as we want.
There is the ability and support to correlate multiple streams of data. In this way working with multiple stream of data will not increase the complexity of our system.
SQL Syntax
The language used to process data streams is very similar with SQL (subset of SQL). In this way we don’t need to learn a new language, we only need to learn and know functions that are specific to Stream Analytics.
Data timestamp
In a system that analyze data in real-time the concept of timestamp and arrival time can be different based on the ingest source or other rules. Because of this we can specify using a command what column should be used as ‘arrival time’ – the command name is TIMESTAMP BY.
Data types
There are 4 types of data that can be used in Stream Analytics:

  • Bigint
  • Float
  • Datetime
  • Nvarchar(max)

Using this 4 primitive types we can map any kind of data from numbers to strings and dates.
Data Definition Language is a vocabulary used to define the data structure of Stream Analytics. For example CREATE TABLE is part of DDL vocabulary.
Data Manipulation Language is the vocabulary used to retrieve, process and work with Stream Analytics. Part of DML are “SELECT”, “WHERE”, “GROUP BY”, “JOIN”, “CASE”, “WITH” and so on.
A window in Stream Analytics terminology represent all events in a specific time frame. Using this time windows we can aggregate events, analyze them many more. There 3 types of time windows in Stream Analytics, from the simple ones that are fixed in time, from the one that start only when a specific event or action happen in the system:

  • Tumbling 
  • Hoping 
  • Sliding

There are a lot of functions that are built in. This functions allow us to do different things from extracting different part of a date time column get substrings or cast to different types.
Don’t forget that when cast is not possible the current version of the service will not throw an expectation. It will only return NULL value.
Low Latency
The latency from the moment when data reach the service until will be processed is extremely short.
Like for the rest of services from Microsoft Azure, all the service management is made using a simple REST API. Because of this we can create our own management application or portal.

Region Availability
In the preview phase, this service is only available in Central US and West Europe region. In future this service will be available worldwide.
Partition Id
In this preview phase, the data partitioning using ‘partition by’ must be on Partition Id. In the future we will be able to make partitioning on other fields.
Number of aggregation 
The maximum number of aggregation definitions that can be done in a query can be 7.
Job Management
When we need to redeploy or start again a job, we are not able to specify the start point. This mean that we cannot continue with data processing from the point where the last job stopped.
Input from blobs
When we are using blobs as input we should limit the maxim size of each blob to 10MB in this moment. This happens because jobs can have problem consuming large blobs and crash.
Columns Heather and Whitespaces
The system don’t make any kind of trim in the name or columns. This mean that if we specify a space at the beginning or end of a column will generate null entries in the job output.

Applicable Use Cases 
Below you can find some use cases when I would use Stream Analytics.
Analyze sensor events of a smart home system
I would use this service to analyze all the events that are produces by a smart home platform and react to this events. From simple events that notify me that the battery is low to the one that transmit the room temperature or that an open is open or close.
There are a type of logs that I would send to a stream analytic system and based on their content to trigger different alerts or alarms. Based on this data we could even make predictions.
Smart devices
When I say a smart device I have in mind a smart watch, a smart shoe, a phone or something similar. Why not aggregate all the data into a system that can analyze them and notify parents that the child has temperature or is sick.

Code Sample 

Pros and Cons 

  • Real time (real) capabilities
  • SQL subset language
  • Scalable
  • Multiple input/output sources
  • Different methods to aggregate data

None, for the use cases where I would like to use this service.

When you need to estimates the costs of Stream Analytics you should take into account the fallowing components:

  • Volume of data 
  • Streaming Unit
  • Outbound traffic
  • Ingest mechanism and costs

We should keep an eye on this service and be open to use it when you will need stream analytics in real time. Analyzing a stream in real time is a hard thing if you need SLAs. It is not only CPU power.


Popular posts from this blog

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine:
threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration:

TeamCity.NET 4.51EF 6.0.2VS2013
It seems that there …

Entity Framework (EF) TransactionScope vs Database.BeginTransaction

In today blog post we will talk a little about a new feature that is available on EF6+ related to Transactions.
Until now, when we had to use transaction we used ‘TransactionScope’. It works great and I would say that is something that is now in our blood.
using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (SqlConnection conn = new SqlConnection("...")) { conn.Open(); SqlCommand sqlCommand = new SqlCommand(); sqlCommand.Connection = conn; sqlCommand.CommandText = ... sqlCommand.ExecuteNonQuery(); ... } scope.Complete(); } Starting with EF6.0 we have a new way to work with transactions. The new approach is based on Database.BeginTransaction(), Database.Rollback(), Database.Commit(). Yes, no more TransactionScope.
In the followi…

GET call of REST API that contains '/'-slash character in the value of a parameter

Let’s assume that we have the following scenario: I have a public HTTP endpoint and I need to post some content using GET command. One of the parameters contains special characters like “\” and “/”. If the endpoint is an ApiController than you may have problems if you encode the parameter using the http encoder.
using (var httpClient = new HttpClient()) { httpClient.BaseAddress = baseUrl; Task<HttpResponseMessage> response = httpClient.GetAsync(string.Format("api/foo/{0}", "qwert/qwerqwer"))); response.Wait(); response.Result.EnsureSuccessStatusCode(); } One possible solution would be to encode the query parameter using UrlTokenEncode method of HttpServerUtility class and GetBytes method ofUTF8. In this way you would get the array of bytes of the parameter and encode them as a url token.
The following code show to you how you could write the encode and decode methods.