Getting a better view from the roof of the Bus
Last time, I had a first spike with NServiceBus in combination with Castle Windsor, NHibernate & FluentNHibernate, and highlighted the fact that it was quite easy to get those guys up and running together in a clean way, and from there, to process your first messages.
This time, I would like to take a step back, off the Bus, to lay down the foundations of a more concrete & complete example. To do so, I will use the well-known used & abused database sample from Microsoft : Northwind !
I can already hear you all “Northwind, WTF ?!” … except that this time, it’s gonna be different, trust me !
Let’s start by having a look at our veteran database diagram …
As we can see, Northwind is a traditional sales company, with an online business, which is:
- Receiving Orders from Customers, classified in different Demographic segments, and shipping those orders via third-party Shippers.
- Provisioning adequate Stock quantities of Products, arranged in Categories, by buying from several Suppliers, to deliver ordered quantities.
- Managing Salesmen organized in Territories & Regions.
(yeah, I can get all that from a simple database diagram … impressive imagination huh ?
)
In an SOA world, we wil tend to breakdown the different facets of the company into several independent but cooperating Services.
A naive but all too common way to split our problem domain would probably be as follows:
- Employee service: manage employees, territories & regions.
- Customer service: manage customer & demographic segments.
- Order service: manages customer orders & shippers.
- Supplier service: manages suppliers & stock.
- Product service: manages products & categories.
Unfortunately, this simplistic way of defining service boundaries around groups of related concepts most often leads to services that are not autonomous (e.g. call each others, use same database), which violates one of the 4 tenets of SOA (“Services are autonomous“). Plus the fact that it just smells too much like a CRUD API.
A better starting point for modeling services is to analyze the Business Capabilities of the company, that is to say, the distinctive aspects of the company that are contributing to achieve its main goals. Another possibility can also be to model your Services around Bounded Contexts that you would have previously identified, if you are a DDD practitioner. I’m still not yet entirely sure which solution you should prefer and in which conditions … good topic for another discussion.
But in any case, your Services will be better aligned with the Business rather than just being technical CRUD-services.
Here is an attempt at defining the Business Capabilities (BC) and their respective goals in our beloved fictive Northwind company:
- Marketing BC: maintains a catalog of products, define pricing & promotional operations to maximize sales.
- Sales BC: accepts customer orders and improves customer relationship.
- Inventory BC: optimizes the provisioning of product stocks via suppliers to support sales.
- Shipping BC: optimizes delivery times & costs through shippers.
- HR BC: manages salesmen to cover sales territories & markets.
They might change as the company’s goals evolve, some being dropped, new ones being added but let’s focus on these ones for now. One service will be defined for each business capability.
Each of those services will eventually use it’s own independent datastore to persist information and will expose its features by accepting incoming Messages and triggering outgoing Events on the Messaging infrastructure.
Those services will be composed to form one or more application(s) that will deliver great value to the company and increase its sales by multiple orders of magnitude !!!
To break with the past, I’ve decided to name this sample Southwind! It sounds warmer and way cooler than Northwind, doesn’t it?
Indeed, it will feature a first personal attempt at building a sample bringing together an Event-Driven Architecture with domain models built following the Domain-Driven Design approach, on top of NServiceBus. Might be a bit ambitious, but it’s so interesting right ?
That’s it for now, till next time where I will focus on the messages & events being exchanged by the different services.
Meanwhile, go read this great article about Event Driven SOA with NServiceBus.
As always, remarks, comments, suggestions are welcome. And if you wanna help building this great sample, you’re more than welcome!




