Loading...

Real-time data ingestion in Synapse SQL dedicated pool at scale

Real-time data ingestion in Synapse SQL dedicated pool at scale

This article reviews a common pattern of streaming data (i.e. real-time message ingestion) in Synapse SQL dedicated pool. It opens a discussion on the simple standard way to implement this, as well as the challenges and drawbacks. It then presents an alternate solution which enables optimal performance and greatly reduces maintenance tasks when using clustered column store indexes. This is aimed at developers, DBAs, architects, and anyone who works with streams of data that are captured in real-time.

 

Scenario description

Description of this scenario is as follow: we have messages produced by sensors (simulated by Azure container instances) sent to an Event Hub, then processed by an ASA job which redirects its output into a Synapse table named “rawdata”. At this stage there are two options:

  • query directly “rawdata” table.
  • use “rawdata” as a staging table, then build a pipeline that process the data every ten minutes and store it in a final fact table. It consists of an UPSERT statement to ensure existing records are updated (in case they are resent), otherwise inserts them into a final fact table named “rawdata_fact”.

 

General solution Design Architecture

Picture2.png

 

Building blocks of the current solution can be found on the following link

streaming-at-scale/eventhubs-streamanalytics-azuresql at main · Azure-Samples/streaming-at-scale (github.com)

This sample deploys within one resource group:

  • Container instances simulating IoT devices sending their temperature and amount of CO2.
  • Event Hub ingesting messages in real time.
  • Stream Analytics job preprocessing messages and redirect them into Synapse SQL dedicated pool.

How to handle the data ingested

In case ASA job loads data directly in the fact table and assuming it has a clustered column store index, what happens is:

  • no delta store compression can take place as the table is constantly inserted
  • simultaneous COPY INTO statements issued by ASA job can potentially trigger new delta stores creation, hence reduce the performance and/or require index maintenance tasks.

 

See illustration below which shows this:

Picture3.png

 

In case ASA job loads the telemetry data into a staging table named "rawdata" then upsert the fact table, we can see that what happens is the following:

  • there is one delta store per distribution where the insertions land, and no closed rowgroup hence all others are compressed rowgroups.
  • the tuple mover at each compute node ensures that once the delta stores get filled up they are converted in compressed rowgroups.

See illustration below which shows this:

Picture4.png

This task is constituted of:

  • A simple pipeline with a stored procedure activity.

 

 

 

{ "name": "processrawdata", "type": "SqlPoolStoredProcedure", "dependsOn": [], "policy": { "timeout": "7.00:00:00", "retry": 0, "retryIntervalInSeconds": 30, "secureOutput": false, "secureInput": false }, "userProperties": [], "sqlPool": { "referenceName": "sqlpool2", "type": "SqlPoolReference" }, "typeProperties": { "storedProcedureName": "[dbo].[processrawdata]" } }

 

 

 

  • A tumbling windows trigger that runs the pipeline every 10 minutes.

 

 

 

{ "name": "tumblingwindow10minutes", "properties": { "annotations": [], "runtimeState": "Stopped", "pipeline": { "pipelineReference": { "referenceName": "processrawdata", "type": "PipelineReference" } }, "type": "TumblingWindowTrigger", "typeProperties": { "frequency": "Minute", "interval": 10, "startTime": "2022-01-14T12:58:00Z", "delay": "00:00:00", "maxConcurrency": 50, "retryPolicy": { "intervalInSeconds": 30 }, "dependsOn": [] } } }

 

 

 

  • a stored procedure scheduled to update the fact from the staging:

 

 

 

ALTER PROC [dbo].[processrawdata] AS BEGIN begin TRANSACTION --We ensure the staging data is locked before its data gets either insert or update the fact table to avoid inconsistencies UPDATE rawdata SET partitionid=0 WHERE 1=0 --Now the fact update can take place as well as the stating data when processed MERGE dbo.rawdata_fact AS macible USING dbo.rawdata AS masource ON (macible.eventId = masource.eventId and macible.[Type]=masource.[Type] and macible.DeviceId=masource.DeviceId and macible.DeviceSequenceNumber=masource.DeviceSequenceNumber and macible.CreatedAt=masource.CreatedAt) WHEN MATCHED THEN UPDATE SET macible.EventId=masource.EventId, macible.[Type]=masource.[Type], macible.DeviceId=masource.DeviceId, macible.DeviceSequenceNumber=masource.DeviceSequenceNumber, macible.CreatedAt=masource.CreatedAt, macible.[Value]=masource.[Value], macible.ComplexData=masource.ComplexData, macible.EnqueuedAt=masource.EnqueuedAt, macible.ProcessedAt=masource.ProcessedAt, macible.StoredAt=masource.StoredAt WHEN NOT MATCHED BY TARGET THEN INSERT ([EventId] ,[Type] ,[DeviceId] ,[DeviceSequenceNumber] ,[CreatedAt] ,[Value] ,[ComplexData] ,[EnqueuedAt] ,[ProcessedAt] ,[StoredAt] ,[PartitionId]) VALUES (masource.[EventId] ,masource.[Type] ,masource.[DeviceId] ,masource.[DeviceSequenceNumber] ,masource.[CreatedAt] ,masource.[Value] ,masource.[ComplexData] ,masource.[EnqueuedAt] ,masource.[ProcessedAt] ,masource.[StoredAt] ,masource.[PartitionId]); delete from rawdata; commit TRAN; END

 

 

 

Then we can a simple view on to of both tables so we have the latest data as well as the processed one:

 

 

 

CREATE VIEW [dbo].[v_rawdata] AS select * from rawdata union ALL select * from rawdata_fact;

 

 

 

And monitor in near real time the average temperature and CO2 values:

 

 

 

select type, avg(value) as average from v_rawdata group by type

 

 

 

Takeaways

We can stream data directly from Stream Analytics into a Synapse SQL dedicated pool. We can avoid the clustered store index maintenance by using an intermediate table and a scheduled pipeline.

Published on:

Learn more
Need help with this product?

We can help you with Real-time data ingestion in Synapse SQL dedicated pool at scale

If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.

Azure Synapse Analytics Blog articles
Azure Synapse Analytics Blog articles

Azure Synapse Analytics Blog articles

Share post:

Related posts

We're moving!

We’re moving to the Analytics on Azure Tech Community! All new Azure Synapse Analytics content will be published there. In the next few days a...

1 year ago

Upgrade to Azure Synapse runtimes for Apache Spark 3.4 & previous runtimes deprecation

It is important to stay ahead of the curve and keep services up to date. That's why we encourage all Azure Synapse customers with Apache ...

2 years ago

ADF\Synapse Analytics - Replace Columns names using Rule based mapping in Mapping data flows

In real time, the column names from source might not be uniform, some columns will have a space in it, some other columns will not. For exampl...

2 years ago

Interpreting Script activity output json with Azure Data Factory\Synapse analytics

Script activity in Azure Data Factory\ Synapse analytics is very helpful to run queries against data sources mentioned here in this document.&...

2 years ago

Synapse Connectivity Series Part #4 - Advanced network troubleshooting and network trace analysis

Continuing the series of this blog posts I would like to go more advanced on troubleshooting connectivity issues. I would like to thank also&n...

2 years ago

Boost your CICD automation for Synapse SQL Serverless by taking advantage of SSDT and SqlPackage CLI

Introduction   Azure Synapse Analytics Serverless SQL is a query service mostly used over the data in your data lake, for data discovery,...

2 years ago

Metadata-Based Ingestion in Synapse with Delta Lake

  Overview     The crucial first step in any ETL (extract, transform, load) process or data engineering program is ingestion, w...

3 years ago

Missing Fields Added to Dedicated SQL pool Diagnostic Settings Logs

Over the past year, customers have informed the team there were a set of key columns missing in the standalone Dedicated SQL pools (formerly S...

3 years ago

Using Azure DevOps with Synapse Workspaces to create hot fixes in production environments

Have you ever deployed a release to production only to find out a bug has escaped your testing process and now users are being severely impact...

3 years ago

Azure Synapse MVP Corner - March 2023

About this blog series Microsoft Most Valuable Professionals, or MVPs, are technology experts who passionately share their knowledge with the ...

3 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.