{"id":244,"date":"2014-11-16T23:01:50","date_gmt":"2014-11-16T23:01:50","guid":{"rendered":"http:\/\/looselycoupledlabs.com\/?p=244"},"modified":"2014-11-25T16:54:00","modified_gmt":"2014-11-25T16:54:00","slug":"masstransit-versus-nservicebus-fight","status":"publish","type":"post","link":"https:\/\/looselycoupledlabs.com\/2014\/11\/masstransit-versus-nservicebus-fight\/","title":{"rendered":"MassTransit versus NServiceBus: FIGHT!"},"content":{"rendered":"
I often get asked: “which is better, MassTransit<\/a> or NServiceBus<\/a>?” It’s a perfectly reasonable question for an outsider looking to get started with message-based SOA on .NET to ask. However, as is usually the case with the “which is better” question for any technology, the answer is the ubiquitous (and exasperating) “it depends.”<\/p>\n This post is not a deep-dive comparison of the two frameworks. To do so would be extremely time consuming and I\u2019m not sure would add a lot of value as the use cases for these frameworks are so broad. Instead, I hope to offer some general guidance on how to approach your own comparison research (with links to more details where appropriate).<\/p>\n The other goal for this post is to hopefully solicit feedback from others to improve the quality of advice offered here. You may want to check back frequently for updates and interesting conversation. Keep things civil, however, please. (The \u201cFIGHT”!\u201d in the post title is just my own attempt at journalistic sensationalism.)<\/p>\n First, the disclaimers\u2026 I\u2019ve used MassTransit for quite some time and obviously if you look at the other posts on this blog<\/a>, you can see there\u2019s a definite MassTransit bias. But there\u2019s a twist! I actually do some (paid) work for Particular Software<\/a> (makers of NServiceBus) writing documentation for their products. Particular is not paying me to write this blog post, however. If this post feels biased to you in any way, I apologize. We\u2019re all human. On the other hand, the level of exposure I have to both frameworks does put me in a good position to publish some thoughts on the differences. Proceed with caution!<\/p>\n Both frameworks have these qualities in common (in broad strokes):<\/p>\n The bottom line is these are both very solid frameworks.<\/p>\n It\u2019s been mentioned in other places many times before, but here are the basic differences if you haven\u2019t seen them (again in broad strokes):<\/p>\n Obviously, there are many other, more detailed, differences but these are the major factors most people are considering when getting started.<\/p>\n Let\u2019s use an automotive analogy and say MassTransit is a base model Honda Accord. Very solid, reliable vehicle. Always highly recommended by the auto experts and consumer groups. It will get you from point A to point B in a predictable manner. There are even upgraded components you can get that are designed to work well with it to give you a better experience.<\/p>\n If MassTransit is a Honda Accord, then NServiceBus is a Lexus IS350. All the same attributes as the Honda, but with a lot more capabilities right in the package. It\u2019s a lot more comfortable, has more horsepower, and can do some pretty impressive things. Could you make the Honda do all the things that a Lexus could do? Possibly, but you\u2019re going to be working in the garage a long time to upgrade it (or paying a custom car shop a lot of money to do so). It would be a very custom, one-of-a-kind vehicle, whereas the Lexus was designed holistically to have all its features work together in a reliable and safe package.<\/p>\n Let me give you a concrete example of some of the additional features you would get \u201cin the box\u201d from NServiceBus versus MassTransit. Take the example of working with a queuing system like RabbitMQ or Azure Service Bus that does not support distributed transactions. If you have a business process that needs to be highly reliable and<\/em> consistent, then you have to deal with this lack of distributed transaction support. Consider this simple example:<\/p>\n In this example, you will lose data because the message will no longer be in the queue, but your database work was not persisted.\u00a0This is why both MassTransit and NServiceBus don’t actually remove the message from the queue until your handler has completed successfully. So the scenario could go like this:<\/p>\n Now the message is still in the queue and will be processed again. This could lead to duplicate data. \u201cNo problem,\u201d you say, \u201cjust keep track of the messages that are processed in the database.\u201d<\/p>\n Now we\u2019re okay because the logic in your handler can check to see if the message id has already been processed. We\u2019re utilizing the transaction capability of your database to help us out here.<\/p>\n Problem solved, right? Actually, not quite\u2026 what if you want to publish another message after finishing the database work? That won\u2019t be involved in the same transaction and now you risk either publishing incorrect information to the service bus or not publishing it at all depending on what order you do your database commit and message publishing. Here\u2019s a great talk by Udi Dahan about this very problem and what the full end-to-end solution for it looks like:<\/p>\nGoals and Disclaimers<\/h1>\n
MassTransit versus NServiceBus<\/h1>\n
Common Qualities<\/h2>\n
\n
So What\u2019s Different?<\/h2>\n
\n
The Automotive Analogy<\/h2>\n
A Concrete Example<\/h2>\n
\n
\n
\n