The What
An “Enterprise Service Bus” (ESB, or Service Bus SB) is an infrastructure component that is responsible for distributing work across multiple components. When used in SOA (Service Oriented Architecture) it usually comes with a dependency on a component called a Message Broker. Service Buses provide a uniform way for a system to deliver messages (like events) to remote systems and include mechanisms to subscribe/publish messages.
The Why
When designing an application / system there becomes a point where having all application/system components on the same physical or virtual machine becomes a problem. Resources for long running tasks cause problems in other areas and “Scaling Up” meaning adding physical/virtual resources like more CPUs, or Memory are not possible. This means you need to “Scale Out” meaning horizontally. Systems that are designed with SOA in mind are generally much better at scaling horizontally since their components are already wrapped up as a small unit.
Communicating between system components can quickly become a tangled mess, which is what a Service Bus fixes. Like the Command Bus and Event Bus objects the Service Bus ties up nicely an API for other components to use such that they don’t know or care about how other things operate. They only know that they need to tell the system about what it’s doing. This orchestration is key in large distributed systems as problems rise up not from simple logic errors, but instead of how the entire system reasons about an action in one of the sub-components.
Terminology
Message Broker - This is an application that manages the network traffic and delivery of the message to a set of components
Middleware - A piece of code that transforms inputs, and passes those modified inputs on.
Sample Code
Service Bus - https://gist.github.com/geggleto/29614279acee4912a7d9bdf26cd1a7ec
Conclusion
The service bus should be a core component in building a distributed system. One side effect of centralizing your system component communication is it improves your documentation, that whole concept of “Self Documenting Code”. It becomes a lot easier to find system level bugs, when you can with your service bus add middleware to aide in Logging. Distributed systems are a much different beast when it comes to productionizing and maintaining them, however that is weighed against making the product actually work in high-load scenarios.
This is largely the apex of web engineering. The problems that you face when adding a single server are much the same problems that you have when you add your 100th.