What is Service Broker?

A number of large database applications require asynchronous and distributed execution. Most loosely-coupled distributed systems provide scale out and resilience by queuing operations. Queues are used extensively in applications such as order entry systems, stock trading, warehouse querying and travel reservation systems. Writing queued distributed applications is a challenging task since it involves reliable network communication, integrity and ordering of messages, tolerance to process and system failuresa and coordination of transactions with the database. While most of these tasks can be achieved by using specialized messaging systems such as MSMQ and MQSeries, the close association between handling data and communicating messages invokes the need for an integrated solution.

Realizing this need, a group of developers at Microsoft started a project to develop reliable messaging in the SQL Server database engine. This feature, called Service Broker, will be launched as part of the upcoming SQL Server 2005 release. But the idea of "messaging in the database engine" raises the obvious question "Why???". The primary reason is to allow application clients to manipulate data and send/receive messages over a single connection. Application programs could access data and perform messasing operations in the same database transaction without having to use distributed transaction coordinators or two-phase commit. Besides the benefits of simpler programmability and possibly better performance, the integrated approach also allows for easier management.

The Service Broker programming model introduces several new concepts. SQL Server 2005 includes new database objects such as message types, contracts, queues and services. Services are endpoints in a database that can initiate (or be the target for) message exchanges called conversations. Conversations are long running and persistent sessions that span transaction boundaries and even network or system failures. In SQL Server 2005 we define a class of conversations called dialogs, which are peer-to-peer exchange of messages between an initiating service and a target service.

Here are some good resources to start learning about Service Broker: