underguiz / sql-mi-dtc

This repository showcases the use of MSDTC in an Azure SQL Managed Instance, that allows an application to run transactions against several databases, for scenarios where Elastic Transactions are not supported.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

About

This repository showcases the use of MSDTC in an Azure SQL Managed Instance, that allows an application to run transactions against several databases, for scenarios where Elastic Transactions are not supported.

The sample app is a .net framework application that runs on a Virtual Machine Scale Set. It's a Flight and Hotel Booking application that spans a transaction over two SQL Databases using System.Transactions (see MakeReservation.cs).

Note: MSDTC on Managed Instance is still in private preview, for more information please check this announcement.

This project assumes you already have an existing environment with a working SQL MI instance with DTC enabled and configured. Hotel and Flight Databases must be created using the provided .sql scripts.

Architecture

This architecture uses Azure SQL Managed Instance with DTC support enabled as its database and a Virtual Machine Scale Set as its application backend.

The goal of the architeture is to minimize operational burden by using Terraform, Azure DevOps and Azure Image Builder to create immutable VM images and infrastructure and deploy them in an automated way on a VMSS. That way, if a given release is not working as expected, one can simple revert the virtualMachineProfile.storageProfile.imageReference.id of the VMSS to bring the environment back to a working condition.

Network Connectivity:

Architecture

Architecture:

Architecture

Usage

Create the base infrastructure need by Azure Image Builder and Azure DevOps.

Take note of terraform apply output, you'll need it later.

$ cd terraform/
$ vi variables.tfvars # existing environment information
$ terraform init
$ terraform plan -var-file='variables.tfvars' \
-target azurerm_role_assignment.image_builder_storage \
-target azurerm_role_assignment.image_builder_container \
-target azurerm_role_assignment.image_builder_rg
$ terraform apply -var-file='variables.tfvars' \
-target azurerm_role_assignment.image_builder_storage \
-target azurerm_role_assignment.image_builder_container \
-target azurerm_role_assignment.image_builder_rg

Import this project into Azure DevOps and create a variable group for the build pipeline, changing the values accordingly to your environment.

Variable Groups

Create a service connection named service-connection.

Service Connection

Give Storage Blob Data Contributor permission to the service connection Service Principal on the storage account from the terraform output.

Blob Contributor

Create a build pipeline from the sample-app/azure-pipelines.yaml definition.

Add Pipeline

Run the pipeline.

Review Pipeline

The first run will fail on the Update VMSS Image step since this resource is yet to be created.

Create the infrastructure.

$ vi variables.tfvars # set the vmss-image-id created by Azure Image Builder
$ terraform plan -var-file='variables.tfvars'
$ terraform apply -var-file='variables.tfvars'

Get the application url from terraform's output and open it in your browser.

From now on, every push to the main branch with changes to the sample-app or its vm image template will trigger the pipeline and deploy the application to the Virtual Machine Scale Set.

Docs

https://en.wikipedia.org/wiki/Microsoft_Distributed_Transaction_Coordinator

https://learn.microsoft.com/en-us/archive/msdn-magazine/2017/october/cloud-development-building-better-cloud-deployments-5-steps-to-immutability

https://docs.microsoft.com/en-us/dotnet/api/system.transactions?view=net-6.0

https://learn.microsoft.com/en-us/azure/devops/repos/git/import-git-repository?view=azure-devops

https://learn.microsoft.com/en-us/azure/devops/pipelines/library/variable-groups?view=azure-devops&tabs=yaml

https://learn.microsoft.com/en-us/azure/virtual-machines/image-builder-overview?tabs=azure-cli

About

This repository showcases the use of MSDTC in an Azure SQL Managed Instance, that allows an application to run transactions against several databases, for scenarios where Elastic Transactions are not supported.


Languages

Language:HCL 47.0%Language:C# 37.1%Language:HTML 10.6%Language:Smarty 2.0%Language:Dockerfile 1.5%Language:TSQL 1.4%Language:ASP.NET 0.4%