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

How to check in AngularJS if a service was register or not

There are cases when you need to check in a service or a controller was register in AngularJS.
For example a valid use case is when you have the same implementation running on multiple application. In this case, you may want to intercept the HTTP provider and add a custom step there. This step don’t needs to run on all the application, only in the one where the service exist and register.
A solution for this case would be to have a flag in the configuration that specify this. In the core you would have an IF that would check the value of this flag.
Another solution is to check if a specific service was register in AngularJS or not. If the service was register that you would execute your own logic.
To check if a service was register or not in AngularJS container you need to call the ‘has’ method of ‘inhector’. It will return TRUE if the service was register.
if ($injector.has('httpInterceptorService')) { $httpProvider.interceptors.push('httpInterceptorService&#…

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.51EF 6.0.2VS2013
It seems that there …

[Post-Event] Codecamp Conference Cluj-Napoca - Nov 19, 2016

Last day I was invited to another Codecamp Conference, that took place in Cluj-Napoca. Like other Codecamp Conferences, the event was very big, with more than 1.000 participants and 70 sessions. There were 10 tracks in parallel, so it was pretty hard to decide at  what session you want to join.
It was great to join this conference and I hope that you discovered something new during the conference.
At this event I talked about Azure IoT Hub and how we can use it to connect devices from the field. I had a lot of demos using Raspberry PI 3 and Simplelink SensorTag. Most of the samples were written in C++ and Node.JS and people were impressed that even if we are using Microsoft technologies, we are not limited to C# and .NET. World and Microsoft are changing so fast. Just looking and Azure IoT Hub and new features that were launched and I'm pressed (Jobs, Methods, Device Twin).
On backend my demos covered Stream Analytics, Event Hub, Azure Object Storage and DocumentDB.

Title:
What abo…