SQL Server Service Broker: a small change in the activation procedure can spike CPU usage and why benchmarking matters

In this post, I will demonstrate how a small change in Service Broker code can significantly increase CPU usage. This post may be helpful for those troubleshooting high CPU consumption related to Service Broker if their case is similar to mine. CPU before and after the bug in Service Broker got fixed However, the main purpose of the post is to highlight that even when following Microsoft's documentation to setup some database feature, things can still go wrong. This is why benchmarking and testing are crucial steps before deploying new features to your production system. Additionally, it is interesting to see that a small change in the code can completely alter the service broker behavior. If you'd like, you can code along with me and see the results for yourself, provided you have SQL Server installed. Architecture The service broker setup I will use is as follows: There are two services and two corresponding queues and their activation procedures: the...