Skip to main content

Active/Active Mechanism over Azure Service Bus

In one of my latest post I talk about Azure Service Bus and Active/Passive mechanism that works great when you need  fail-over mechanism.
Using this mechanism the system can use a secondary channel to send messages in case of the connectivity or reliability problems with the first resources (in our case with our Active namespace). The Passive resource it is recommended to be placed in another region (data-center). In this way there is better protection in a case of a fail-over.


The downside of Active/Passive Mechanism is the risk of losing messages that were send with success on the channel. There is a risk of loosing messages when the Active resource goes down. If the system that sends messages over the wire is not capable to send again the lost messages than you could have an issues. This use case it is important only for use cases when it is not acceptable to lose messages.
For example in the above example (from the Active/Passive post, when backed send messages to the car, we want to be sure that Open Doors command will reach the car. We don't want to have a customer waiting 1h until the doors would open.

In the above example if the Active channel goes down (queue), all messages that were to Active Service Bus Queue and were not consumed by the consumer are not available anymore.
If is important to be able to still access them, even when the Active channel is down, then we will need to use Active/Active Mechanism.
Be aware, from all points of view, this is more expensive then Active/Passive Mechanism and you should use it only when you really need it.

The main difference between Active/Passive and Active/Active Mechanism is the way how messages are send and consumed. When we are using Active/Passive Mechanism a message is send to the Active resource all the time. Except when the Active is down and cannot be reached by producer. In this case the message is send the Passive resource. The consumer is usually listening both resources (Active/Passive), but the Active resource is usually checked more often.
In contrast, in Active/Active Mechanism, the producer will send each message to both resources. In this way, in the case of a fail-over of one resource, the other one will still have the message. This comes with an overhead on the consumer side.

Because the same message is send to both resources, the consumer needs to track messages.It needs to be able to skip messages that were already processed.


Tracking messages action can be done pretty simple using a caching mechanism.
A possible solution for this problem could be based on Redis Cache. As you already know, Redis Cache is not only extremely fast and reliable but also allow us to set an TTL (an expiration time) for each item that is added to the cache. In this way we can specify how long a key will will be stored and exist in the cache.
Using this functionality we could have the fallowing mechanism:
  1. [Producer] Send a message to both Active resources (to both Service Bus Queues) and setting the same unique message ID to both messages (SyncID - Guid)
  2. [Consumer] Receive message from one of the Active Resource
  3. [Consumer] Check if the message SyncID was already added to Redis Cache (consumed). If yes then skip next steps
  4. [Consumer] Add the message SyncID to Redis Cache
  5. [Consumer] Execute custom action

We could use the expiration flag to be sure that the cache stores only relevant information. Beside this, we could use Sets to store the Message SyncID. A Redis Set allow us to store around 4 billions items.


Of course for message tracking we can use other mechanism and even store different status. Beside Redis Cache we could use Azure Table a normal SQL database. Don't try to use in-memory storage when you have multiple instances that are connection to the same Active/Active resources. Why? Because you will need to find a way to sync the in-memory storage between different instances.

In this post we discover what are the advantages of Active/Active Mechanism and when we should use it. It is true that it is more reliable, but the resources that are required for such a system are higher (and is more expensive).

Comments

Popular posts from this blog

Windows Docker Containers can make WIN32 API calls, use COM and ASP.NET WebForms

After the last post , I received two interesting questions related to Docker and Windows. People were interested if we do Win32 API calls from a Docker container and if there is support for COM. WIN32 Support To test calls to WIN32 API, let’s try to populate SYSTEM_INFO class. [StructLayout(LayoutKind.Sequential)] public struct SYSTEM_INFO { public uint dwOemId; public uint dwPageSize; public uint lpMinimumApplicationAddress; public uint lpMaximumApplicationAddress; public uint dwActiveProcessorMask; public uint dwNumberOfProcessors; public uint dwProcessorType; public uint dwAllocationGranularity; public uint dwProcessorLevel; public uint dwProcessorRevision; } ... [DllImport("kernel32")] static extern void GetSystemInfo(ref SYSTEM_INFO pSI); ... SYSTEM_INFO pSI = new SYSTEM_INFO(

ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded

Today blog post will be started with the following error when running DB tests on the CI machine: threw exception: System.InvalidOperationException: The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name 'System.Data.SqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. at System.Data.Entity.Infrastructure.DependencyResolution.ProviderServicesFactory.GetInstance(String providerTypeName, String providerInvariantName) This error happened only on the Continuous Integration machine. On the devs machines, everything has fine. The classic problem – on my machine it’s working. The CI has the following configuration: TeamCity .NET 4.51 EF 6.0.2 VS2013 It see

Navigating Cloud Strategy after Azure Central US Region Outage

 Looking back, July 19, 2024, was challenging for customers using Microsoft Azure or Windows machines. Two major outages affected customers using CrowdStrike Falcon or Microsoft Azure computation resources in the Central US. These two outages affected many people and put many businesses on pause for a few hours or even days. The overlap of these two issues was a nightmare for travellers. In addition to blue screens in the airport terminals, they could not get additional information from the airport website, airline personnel, or the support line because they were affected by the outage in the Central US region or the CrowdStrike outage.   But what happened in reality? A faulty CrowdStrike update affected Windows computers globally, from airports and healthcare to small businesses, affecting over 8.5m computers. Even if the Falson Sensor software defect was identified and a fix deployed shortly after, the recovery took longer. In parallel with CrowdStrike, Microsoft provided a too