Seamless data replication has emerged as a critical necessity for businesses striving to stay agile and competitive. Yet, the challenge remains: how can organizations harness the power of data replication without overhauling their existing architectural frameworks? Many organizations aren’t interested in or in a position to replace their centralized data stores.
Here, we focus on leveraging Azure Functions and HarperDB API to replicate data to the edge, which offers the following benefits:
- Data origin and existing systems unimpacted
- Offload system of record
- Reduced latency
- Continuous data sync
Implementation
The implementation is something like this:

- The Azure Function is executed through SqlTrigger when a change in a table is detected
- The code sends the corresponding updates to Harper DB
According to the documentation, this is the way the trigger works:
while (true) { Get a list of changes on the table – up to a maximum number controlled by the Sql_Trigger_MaxBatchSize setting. Trigger function with a list of changes Wait for delay controlled by the Sql_Trigger_PollingIntervalMs setting }
For example, let’s say we have a table called product:

and we want to synchronize the changes to our distributed DB:

For this to work, we must enable the change-tracking functionality in the database and the table.

The function uses the SqlTrigger:
[FunctionName(“HarperDBReplication”)] public static void Run( [SqlTrigger(“[SalesLT].[Product]”, “connectionStringSetting”)] IReadOnlyList<SqlChange> changes, ILogger log) {
On it, we specify the table we target and the corresponding connection string as a decorator for a List of SqlChanges of an entity called Product. This entity describes the fields we’d be retrieving
public class Product { public string ProductID { get; set; } public string Name { get; set; } public string Color { get; set; } public double ListPrice { get; set; } }
Whenever we make a change to the central database, the Azure Function is executed, sending the changes to Harper:

And the changes are reflected afterward:

Conclusion
This lightweight solution provides an efficient application replication mechanism, helping answer “What rows have changed for a table?” and ensuring data is up to date at the edge. The change tracking feature is supported in SQL Server 2016 (13.x) and above, Azure SQL and Azure SQL Managed Instance.
Leave a Reply