Streaming Analytics Options in Cumulocity IoT
Tags: iot, analytics, microservices, cumulocity
Published: 2022-12-01 09:01:17

---
title: Streaming Analytics Options in Cumulocity IoT
published: true
date: 2022-11-15 16:49:38 UTC
tags: iot, analytics, microservices, cumulocity
canonical_url: https://tech.forums.softwareag.com/t/streaming-analytics-options-in-cumulocity-iot/265994
---

## Introduction

Many IoT Solutions (if not all) need to perform some real-time analytics on their connected devices data. Cumulocity IoT offers different tools to achieve this; starting from the very-straightforward **smart rules** , moving to a more business-user approach with the **Analytics Builder** app, followed by its more in-depth **EPL App** tool which is primarily focused for developers and finishing with a full blown Apama solution by creating a **microservice**. This article explains all the different Streaming Analytics options and when to use what.

## Smart Rules

Smart rules is a capability in Cumulocity IoT allowing a user to enable **pre-defined business rules** on incoming real-time data and to perform some actions based on this data. These rules can be configured and enabled by **domain experts** via simple dialogs in the Cockpit application. Behind the hood, these rules are actually implemented using the EPL language and injected into the Apama correlator but all of this is transparent to the user.

You want to use smart rules when the pre-defined rules are sufficient for your **business needs**. They can be enabled at device/group level or for all devices.

[![image](https://aws1.discourse-cdn.com/techcommunity/optimized/3X/6/a/6aee64d3642827054bb48a8b4c29242b2e3fdadd_2_684x500.png)](https://aws1.discourse-cdn.com/techcommunity/original/3X/6/a/6aee64d3642827054bb48a8b4c29242b2e3fdadd.png "image")

## Analytics Builder

Analytics Builder gives **engineers** and **domain experts** a web-based capability to develop analytics application on streaming data without coding. The users can combine logic blocks together to build powerful models to process data in real-time. Analytics Builder offers a large range of **pre-built blocks** which the users can drag and drop onto a canvas, configure them with a few clicks and link the blocks to one another to create an end-to-end business logic. There is also the possibility to create your own blocks using our Analytics Builder SDK. The combination of all the blocks in the canvas is called a **Model**.  
Models can be developed easily in minutes, edited and tested within the Cumulocity IoT environment. You can also test your analytics models with simulated or historical data and deploy them with a single-click. You can execute the same model from different devices in parallel. Model execution is also handled by Apama behind the scenes.

Analytic Builder models can be much more powerful and customizable than the smart rules templates included in Cumulocity IoT, and they are quicker and simpler to develop than writing Apama EPL code. You will want to use Analytics Builder when the existing smart rules are not enough to do the analysis required on the data or if, for example, you want to extend the devices’ data by adding new fragments, generate new types of events or measurements, trigger operations or much more based on a specific business logic. The tool is very easy to use and does not involve writing any lines of code so it is mainly aimed for business users or domain experts.

> **Note** that with Analytics Builder, the model can run only on a device or a group of devices. At the time of writing, you cannot run a model over **ALL** the tenant’s devices.

[![image](https://aws1.discourse-cdn.com/techcommunity/optimized/3X/5/b/5bcd4396ea395418b191d06b689648a4c062ab44_2_690x456.png)](https://aws1.discourse-cdn.com/techcommunity/original/3X/5/b/5bcd4396ea395418b191d06b689648a4c062ab44.png "image")

## EPL Apps

EPL Apps allows you to develop streaming analytics rules directly within Cumulocity IoT using the **Apama EPL language**. EPL Apps provides an interface to **developers** for interactively editing new or existing EPL applications. The rules need to be written in EPL as they will be directly injected as monitors into the Apama Correlator which runs on the tenant. The tool includes many examples to get you started in creating your own analytics rules. Every single EPL app is stateless and independent to one another; meaning a rule should have its own business logic without being dependent of another rule (they should not share events). This is one of the [limitations](https://cumulocity.com/guides/apama/best-practices/#general-apama-limitations-when-using-epl-apps-or-a-custom-microservice) imposed on EPL apps due to the Cumulocity IoT environment.

EPL Apps should be used by **developers** who are happy to write code in EPL. You want to choose EPL apps when the analytics you want to perform is quite advanced and cannot be easily implemented using Analytics Builder. Also, with EPL apps, the real-time analytics can be run over **ALL** your devices, whereas in Analytics Builder you can run the model only on one single device or a group of devices. EPL apps can be much more advanced than smart rules and Analytics Builder models and they can be much more flexible and powerful in terms of analytics possibilities. Just as an example, you can call external APIs over HTTP and handle their responses using an EPL app…

[![image](https://aws1.discourse-cdn.com/techcommunity/optimized/3X/6/5/65a9e7500ebf04a647ab3a74eb68d4f126a788c7_2_690x386.png)](https://aws1.discourse-cdn.com/techcommunity/original/3X/6/5/65a9e7500ebf04a647ab3a74eb68d4f126a788c7.png "image")

## Apama Microservice

Smart rules, Analytics Builder and EPL Apps all use the Streaming Analytics microservice behind the scenes which is provided with Cumulocity IoT. This microservice is doing a lot of the work for you, receives the devices data in real-time and persists whatever is required in the platforms operational store (MongoDB). However, if needed, you can also use Apama within your own custom microservice.

As a **developer** you would want to build you own custom microservice in case you need to create a large Apama solution similar to a standalone application. The microservice would include Apama and be comprised of multiple EPL monitors exchanging data to one another and potentially connecting to several external systems too. The usage of an IDE and the Cumulocity IoT connectivity plug-in will be required so you can easily connect to Cumulocity IoT and make use of its domain model.

However we usually do not typically recommend creating your own custom microservice including Apama. First of all, most of the analytics required should be achievable via the 3 previous options. But most of all, Apama uses the Cumulocity IoT real-time notification API for the ingestion of data and this mechanism is not considered reliable for production use cases. This means your microservice could miss some Cumulocity IoT events such as Measurements, Alarms etc… These reliability issues do not exist with the main Apama-ctrl microservice (the one being provided with Cumulocity IoT) because the Cumulocity IoT data is pushed to this microservice via a dedicated endpoint over REST.

## Conclusion | Next steps

Cumulocity IoT offers a wide range of options to create your own streaming analytics over the device data. Those options go from the simplest interface for non-coders to a more in-depth hands-on developer tool for technical people. Whatever your streaming analytics need are, you can build it with a single or a combination of these streaming analytics options described here.

If you want to learn more about EPL and go more in depth on every single option, then you might be interested in some of our [Training courses](https://learn.softwareag.com/enrol/index.php?id=1278) or [Fast Track Services](https://www.softwareag.com/en_corporate/resources/services/fast-track/cumulocity-streaming-analytics.html) which will allow you to learn much more about Apama and provide hands-on exercises.

## Useful links | Relevant resources

[Apama Advent Calendar](https://tech.forums.softwareag.com/t/apama-advent-calendar-01-dec-2021-finding-information/253610)  
[Apama Limitations in Cumulocity](https://cumulocity.com/guides/apama/best-practices/#limitations)

[Read full topic](https://tech.forums.softwareag.com/t/streaming-analytics-options-in-cumulocity-iot/265994)