← Back to DevBytes

Designing a Real-Time Analytics on Azure

Designing a Real-Time Analytics Solution on Azure

What is Real-Time Analytics on Azure?

Real-time analytics on Azure refers to the ability to ingest, process, and analyze data as it arrives—often within seconds or milliseconds—and act on insights immediately. Unlike traditional batch processing, which works with historical data in scheduled intervals, real-time analytics enables low-latency decision-making for scenarios such as fraud detection, IoT sensor monitoring, live dashboards, and personalized user experiences.

Azure provides a comprehensive set of managed services that work together to build end-to-end real-time pipelines without managing underlying infrastructure. The key components include event ingestion (Azure Event Hubs, IoT Hub), stream processing (Azure Stream Analytics, Apache Spark on Synapse), storage (Azure Data Lake, Cosmos DB), and visualization (Power BI, Azure Data Explorer).

Why It Matters

Core Azure Services for Real-Time Analytics

How to Design a Real-Time Analytics Pipeline

We will walk through a typical architecture: ingest IoT sensor data via Event Hubs, process it with Stream Analytics, and output aggregated results to Azure Cosmos DB for a live API and to Power BI for a dashboard.

Step 1: Create an Azure Event Hubs Namespace and Event Hub

Use Azure Portal, CLI, or ARM template. Here’s an example using Azure CLI:

az eventhubs namespace create --name myRealtimeNamespace \
  --resource-group myResourceGroup --location eastus --sku Standard

az eventhubs eventhub create --name sensor-events \
  --namespace-name myRealtimeNamespace \
  --resource-group myResourceGroup \
  --message-retention 1 \
  --partition-count 4

Step 2: Send Sample Data to Event Hubs

A Python script to simulate temperature sensors:

import json, time, random
from azure.eventhub import EventHubProducerClient, EventData

connection_str = "Endpoint=sb://myRealtimeNamespace.servicebus.windows.net/;SharedAccessKeyName=...;SharedAccessKey=..."
producer = EventHubProducerClient.from_connection_string(connection_str, eventhub_name="sensor-events")

with producer:
    for _ in range(100):
        data = {
            "deviceId": f"sensor-{random.randint(1,10)}",
            "temperature": round(random.uniform(20, 30), 2),
            "humidity": round(random.uniform(40, 60), 2),
            "timestamp": time.time()
        }
        event_data = EventData(json.dumps(data))
        producer.send(event_data)
        print(f"Sent: {data}")
        time.sleep(0.1)

Step 3: Create a Stream Analytics Job

Define input (Event Hubs), output (Cosmos DB), and the transformation query.

-- Stream Analytics Query: Aggregate temperature per device every 10 seconds
SELECT
    deviceId,
    AVG(temperature) AS avgTemperature,
    COUNT(*) AS eventCount,
    System.Timestamp AS windowEnd
INTO
    [cosmosdb-output]
FROM
    [eventhub-input] TIMESTAMP BY timestamp
GROUP BY
    deviceId,
    TumblingWindow(second, 10)

Step 4: Configure Output to Cosmos DB

Cosmos DB output settings (SQL API) – provide endpoint, database, collection (container), document ID pattern:

{
  "outputAlias": "cosmosdb-output",
  "type": "DocumentDB",
  "properties": {
    "accountId": "myrealtimecosmos",
    "database": "SensorDB",
    "container": "SensorAggregates",
    "documentId": "deviceId_windowEnd",
    "authenticationMode": "ConnectionString",
    "accountKey": "..."
  }
}

Step 5: Start the Job and Monitor

Start the Stream Analytics job from the portal or CLI. Verify data flowing into Cosmos DB using Data Explorer:

SELECT * FROM c WHERE c.windowEnd >= '2025-01-01'

Step 6: Real-Time Dashboard in Power BI

Add a second output to Stream Analytics of type Power BI. Create a dataset and tile in Power BI service that refreshes every few seconds. Alternatively, use Azure Data Explorer for interactive queries:

.create table SensorAggregates (deviceId:string, avgTemperature:real, eventCount:long, windowEnd:datetime)

Best Practices

Conclusion

Designing a real-time analytics solution on Azure empowers organizations to gain immediate, actionable insights from streaming data. By combining Event Hubs for ingestion, Stream Analytics for processing, and Cosmos DB or Power BI for serving results, you can build a scalable, low-latency pipeline that handles millions of events per second. Following best practices around partitioning, checkpointing, schema management, and security ensures your solution remains robust and maintainable as data volumes grow. Start small, iterate, and leverage Azure’s managed services to focus on business logic rather than infrastructure.

🚀 Need a reliable AI agent for your project?

Deploy Hermes Agent in 10 minutes. Managed hosting, zero DevOps.

Get Started — $23.99/mo
← Back to all articles