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).


Popular posts from this blog

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 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 …

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&#…

Fundamental Books of a Software Engineer (version 2018)

More then six years ago I wrote a blog post about fundamental books that any software engineer (developer) should read. Now it is an excellent time to update this list with new entries.

There are 5 different categories of books, that represent the recommended path. For example, you start with Coding books, after that, you read books about Programming, Design and so on.
There are some books about C++ that I recommend not because you shall know C++, only because the concepts that you can learn from it.


Writing solid codeCode completeProgramming Pearls, more programming pearls(recommended)[NEW] Introduction to Algorithms


Refactoring (M. Fowler)Pragmatic ProgrammerClean code[NEW] Software Engineering: A Practitioner's Approach[NEW] The Mythical Man-Month[NEW] The Art of Computer Programming


Applying UML and Patterns (GRASP patterns)C++ coding standards (Sutter, Alexandrescu)The C++ programming language (Stroustrup, Part IV)Object-oriented programming (Peter Coad)P…