<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Udi Dahan - The Software Simplist &#187; Autonomous Services</title>
	<atom:link href="http://www.udidahan.com/category/autonomous-services/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.udidahan.com</link>
	<description>Enterprise Development Expert &#38; SOA Specialist</description>
	<lastBuildDate>Mon, 08 Mar 2010 14:34:24 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Clarified CQRS</title>
		<link>http://www.udidahan.com/2009/12/09/clarified-cqrs/</link>
		<comments>http://www.udidahan.com/2009/12/09/clarified-cqrs/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 14:57:19 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[Messaging]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[Validation]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/?p=1149</guid>
		<description><![CDATA[
After listening how the community has interpreted Command-Query Responsibility Segregation I think that the time has come for some clarification. Some have been tying it together to Event Sourcing. Most have been overlaying their previous layered architecture assumptions on it. Here I hope to identify CQRS itself, and describe in which places it can connect [...]]]></description>
			<content:encoded><![CDATA[<p><img src="/wp-content/uploads/clarification.png" style="float:right; margin-left:10px; margin-bottom:10px" alt="clarification" title="clarification" /><br />
After listening how the community has interpreted Command-Query Responsibility Segregation I think that the time has come for some clarification. Some have been tying it together to Event Sourcing. Most have been overlaying their previous layered architecture assumptions on it. Here I hope to identify CQRS itself, and describe in which places it can connect to other patterns.</p>
<p><a href="/wp-content/uploads/Clarified_CQRS.pdf">Download as PDF</a> &#8211; this is quite a long post.</p>
<h3>Why CQRS</h3>
<p>Before describing the details of CQRS we need to understand the two main driving forces behind it: collaboration and staleness.</p>
<p>Collaboration refers to circumstances under which multiple actors will be using/modifying the same set of data &#8211; whether or not the intention of the actors is actually to collaborate with each other. There are often rules which indicate which user can perform which kind of modification and modifications that may have been acceptable in one case may not be acceptable in others. We&#8217;ll give some examples shortly. Actors can be human like normal users, or automated like software. </p>
<p>Staleness refers to the fact that in a collaborative environment, once data has been shown to a user, that same data may have been changed by another actor &#8211; it is stale. Almost any system which makes use of a cache is serving stale data &#8211; often for performance reasons. What this means is that we cannot entirely trust our users decisions, as they could have been made based on out-of-date information.</p>
<p>Standard layered architectures don&#8217;t explicitly deal with either of these issues. While putting everything in the same database may be one step in the direction of handling collaboration, staleness is usually exacerbated in those architectures by the use of caches as a performance-improving afterthought.</p>
<h3>A picture for reference</h3>
<p>I&#8217;ve given some talks about CQRS using this diagram to explain it:</p>
<p><img src="/wp-content/uploads/cqrs.png" width="500" height="319" alt="CQRS" title="CQRS" /></p>
<p>The boxes named AC are Autonomous Components. We&#8217;ll describe what makes them autonomous when discussing commands. But before we go into the complicated parts, let&#8217;s start with queries:</p>
<h3>Queries</h3>
<p>If the data we&#8217;re going to be showing users is stale anyway, is it really necessary to go to the master database and get it from there? Why transform those 3rd normal form structures to domain objects if we just want data &#8211; not any rule-preserving behaviors? Why transform those domain objects to DTOs to transfer them across a wire, and who said that wire has to be exactly there? Why transform those DTOs to view model objects?</p>
<p>In short, it looks like we&#8217;re doing a heck of a lot of unnecessary work based on the assumption that reusing code that has already been written will be easier than just solving the problem at hand. Let&#8217;s try a different approach:</p>
<p>How about we create an additional data store whose data can be a bit out of sync with the master database &#8211; I mean, the data we&#8217;re showing the user is stale anyway, so why not reflect in the data store itself. We&#8217;ll come up with an approach later to keep this data store more or less in sync.</p>
<p>Now, what would be the correct structure for this data store? How about just like the view model? One table for each view. Then our client could simply SELECT * FROM MyViewTable (or possibly pass in an ID in a where clause), and bind the result to the screen. That would be just as simple as can be. You could wrap that up with a thin facade if you feel the need, or with stored procedures, or using <a href="http://automapper.codeplex.com/">AutoMapper</a> which can simply map from a data reader to your view model class. The thing is that the view model structures are already wire-friendly, so you don&#8217;t need to transform them to anything else.</p>
<p>You could even consider taking that data store and putting it in your web tier. It&#8217;s just as secure as an in-memory cache in your web tier. Give your web servers SELECT only permissions on those tables and you should be fine.</p>
<h3>Query Data Storage</h3>
<p>While you can use a regular database as your query data store it isn&#8217;t the only option. Consider that the query schema is in essence identical to your view model. You don&#8217;t have any relationships between your various view model classes, so you shouldn&#8217;t need any relationships between the tables in the query data store.</p>
<p>So do you actually need a <i>relational</i> database?</p>
<p>The answer is no, but for all practical purposes and due to organizational inertia, it is probably your best choice (for now).</p>
<h3>Scaling Queries</h3>
<p>Since your queries are now being performed off of a separate data store than your master database, and there is no assumption that the data that&#8217;s being served is 100% up to date, you can easily add more instances of these stores without worrying that they don&#8217;t contain the exact same data. The same mechanism that updates one instance can be used for many instances, as we&#8217;ll see later.</p>
<p>This gives you cheap horizontal scaling for your queries. Also, since your not doing nearly as much transformation, the latency per query goes down as well. Simple code is fast code.</p>
<h3>Data modifications</h3>
<p>Since our users are making decisions based on stale data, we need to be more discerning about which things we let through. Here&#8217;s a scenario explaining why:</p>
<p>Let&#8217;s say we have a customer service representative who is one the phone with a customer. This user is looking at the customer&#8217;s details on the screen and wants to make them a &#8216;preferred&#8217; customer, as well as modifying their address, changing their title from Ms to Mrs, changing their last name, and indicating that they&#8217;re now married. What the user doesn&#8217;t know is that after opening the screen, an event arrived from the billing department indicating that this same customer doesn&#8217;t pay their bills &#8211; they&#8217;re delinquent. At this point, our user submits their changes.</p>
<p>Should we accept their changes?</p>
<p>Well, we should accept some of them, but not the change to &#8216;preferred&#8217;, since the customer is delinquent. But writing those kinds of checks is a pain &#8211; we need to do a diff on the data, infer what the changes mean, which ones are related to each other (name change, title change) and which are separate, identify which data to check against &#8211; not just compared to the data the user retrieved, but compared to the current state in the database, and then reject or accept. </p>
<p>Unfortunately for our users, we tend to reject the whole thing if any part of it is off. At that point, our users have to refresh their screen to get the up-to-date data, and retype in all the previous changes, hoping that this time we won&#8217;t yell at them because of an optimistic concurrency conflict.</p>
<p>As we get larger entities with more fields on them, we also get more actors working with those same entities, and the higher the likelihood that something will touch some attribute of them at any given time, increasing the number of concurrency conflicts. </p>
<p>If only there was some way for our users to provide us with the right level of granularity and intent when modifying data. That&#8217;s what commands are all about.</p>
<h3>Commands</h3>
<p>A core element of CQRS is rethinking the design of the user interface to enable us to capture our users&#8217; intent such that making a customer preferred is a different unit of work for the user than indicating that the customer has moved or that they&#8217;ve gotten married. Using an Excel-like UI for data changes doesn&#8217;t capture intent, as we saw above.</p>
<p>We could even consider allowing our users to submit a new command even before they&#8217;ve received confirmation on the previous one. We could have a little widget on the side showing the user their pending commands, checking them off asynchronously as we receive confirmation from the server, or marking them with an X if they fail. The user could then double-click that failed task to find information about what happened.</p>
<p>Note that the client <i>sends</i> commands to the server &#8211; it doesn&#8217;t publish them. Publishing is reserved for events which state a fact &#8211; that something has happened, and that the publisher has no concern about what receivers of that event do with it.</p>
<h3>Commands and Validation</h3>
<p>In thinking through what could make a command fail, one topic that comes up is validation. Validation is different from business rules in that it states a context-independent fact about a command. Either a command is valid, or it isn&#8217;t. Business rules on the other hand are context dependent.</p>
<p>In the example we saw before, the data our customer service rep submitted was valid, it was only due to the billing event arriving earlier which required the command to be rejected. Had that billing event not arrived, the data would have been accepted.</p>
<p>Even though a command may be valid, there still may be reasons to reject it.</p>
<p>As such, validation can be performed on the client, checking that all fields required for that command are there, number and date ranges are OK, that kind of thing. The server would still validate all commands that arrive, not trusting clients to do the validation.</p>
<h3>Rethinking UIs and commands in light of validation</h3>
<p>The client can make of the query data store when validating commands. For example, before submitting a command that the customer has moved, we can check that the street name exists in the query data store.</p>
<p>At that point, we may rethink the UI and have an auto-completing text box for the street name, thus ensuring that the street name we&#8217;ll pass in the command will be valid. But why not take things a step further? Why not pass in the street ID instead of its name? Have the command represent the street not as a string, but as an ID (int, guid, whatever).</p>
<p>On the server side, the only reason that such a command would fail would be due to concurrency &#8211; that someone had deleted that street and that that hadn&#8217;t been reflected in the query store yet; a fairly exceptional set of circumstances. </p>
<h3>Reasons valid commands fail and what to do about it</h3>
<p>So we&#8217;ve got a well-behaved client that is sending valid commands, yet the server still decides to reject them. Often the circumstances for the rejection are related to other actors changing state relevant to the processing of that command.</p>
<p>In the CRM example above, it is only because the billing event arrived first. But &#8220;first&#8221; could be a millisecond before our command. What if our user pressed the button a millisecond earlier? Should that actually change the <b>business outcome</b>? Shouldn&#8217;t we expect our system to behave the same when observed from the outside?</p>
<p>So, if the billing event arrived second, shouldn&#8217;t that revert preferred customers to regular ones? Not only that, but shouldn&#8217;t the customer be notified of this, like by sending them an email? In which case, why not have this be the behavior for the case where the billing event arrives first? And if we&#8217;ve already got a notification model set up, do we really need to return an error to the customer service rep? I mean, it&#8217;s not like they can do anything about it <b>other than notifying the customer</b>.</p>
<p>So, if we&#8217;re not returning errors to the client (who is already sending us valid commands), maybe all we need to do on the client when sending a command is to tell the user &#8220;thank you, you will receive confirmation via email shortly&#8221;. We don&#8217;t even need the UI widget showing pending commands. </p>
<h3>Commands and Autonomy</h3>
<p>What we see is that in this model, commands don&#8217;t need to be processed immediately &#8211; they can be queued. How fast they get processed is a question of Service-Level Agreement (SLA) and not architecturally significant. This is one of the things that makes that node that processes commands autonomous from a runtime perspective &#8211; we don&#8217;t require an always-on connection to the client.</p>
<p>Also, we shouldn&#8217;t need to access the query store to process commands &#8211; any state that is needed should be managed by the autonomous component &#8211; that&#8217;s part of the meaning of autonomy.</p>
<p>Another part is the issue of failed message processing due to the database being down or hitting a deadlock. There is no reason that such errors should be returned to the client &#8211; we can just rollback and try again. When an administrator brings the database back up, all the message waiting in the queue will then be processed successfully and our users receive confirmation.</p>
<p>The system as a whole is quite a bit more robust to any error conditions.</p>
<p>Also, since we don&#8217;t have queries going through this database any more, the database itself is able to keep more rows/pages in memory which serve commands, improving performance. When both commands and queries were being served off of the same tables, the database server was always juggling rows between the two.</p>
<h3>Autonomous Components</h3>
<p>While in the picture above we see all commands going to the same AC, we could logically have each command processed by a different AC, each with it&#8217;s own queue. That would give us visibility into which queue was the longest, letting us see very easily which part of the system was the bottleneck. While this is interesting for developers, it is critical for system administrators.</p>
<p>Since commands wait in queues, we can now add more processing nodes behind those queues (using the distributor with NServiceBus) so that we&#8217;re only scaling the part of the system that&#8217;s slow. No need to waste servers on any other requests.</p>
<h3>Service Layers</h3>
<p>Our command processing objects in the various autonomous components actually make up our service layer. The reason you don&#8217;t see this layer explicitly represented in CQRS is that it isn&#8217;t really there, at least not as an identifiable logical collection of related objects &#8211; here&#8217;s why:</p>
<p>In the <a href="http://en.wikipedia.org/wiki/Multitier_architecture">layered architecture</a> (AKA 3-Tier) approach, there is no statement about dependencies between objects within a layer, or rather it is implied to be allowed. However, when taking a command-oriented view on the service layer, what we see are objects handling different types of commands. Each command is independent of the other, so why should we allow the objects which handle them to depend on each other?</p>
<p>Dependencies are things which should be avoided, unless there is good reason for them.</p>
<p>Keeping the command handling objects independent of each other will allow us to more easily version our system, one command at a time, not needing even to bring down the entire system, given that the new version is backwards compatible with the previous one.</p>
<p>Therefore, keep each command handler in its own VS project, or possibly even in its own solution, thus guiding developers away from introducing dependencies in the name of reuse (it&#8217;s a <a href="http://www.udidahan.com/2009/06/07/the-fallacy-of-reuse/">fallacy</a>). If you do decide <b>as a deployment concern</b>, that you want to put them all in the same process feeding off of the same queue, you can ILMerge those assemblies and host them together, but understand that you will be undoing much of the benefits of your autonomous components.</p>
<h3>Whither the domain model?</h3>
<p>Although in the diagram above you can see the domain model beside the command-processing autonomous components, it&#8217;s actually an implementation detail. There is nothing that states that all commands <i>must</i> be processed by the same domain model. Arguably, you could have some commands be processed by <a href="http://martinfowler.com/eaaCatalog/transactionScript.html">transaction script</a>, others using <a href="http://martinfowler.com/eaaCatalog/tableModule.html">table module</a> (AKA active record), as well as those using the <a href="http://martinfowler.com/eaaCatalog/domainModel.html">domain model</a>. Event-sourcing is another possible implementation.</p>
<p>Another thing to understand about the domain model is that it now isn&#8217;t used to serve queries. So the question is, why do you need to have so many relationships between entities in your domain model?</p>
<p>(You may want to take a second to let that sink in.)</p>
<p>Do we really need a collection of orders on the customer entity? In what command would we need to navigate that collection? In fact, what kind of command would need <i>any</i> one-to-many relationship? And if that&#8217;s the case for one-to-many, many-to-many would definitely be out as well. I mean, most commands only contain one or two IDs in them anyway.</p>
<p>Any aggregate operations that may have been calculated by looping over child entities could be pre-calculated and stored as properties on the parent entity. Following this process across all the entities in our domain would result in isolated entities needing nothing more than a couple of properties for the IDs of their related entities &#8211; &#8220;children&#8221; holding the parent ID, like in databases.</p>
<p>In this form, commands could be entirely processed by a single entity &#8211; viola, an aggregate root that is a consistency boundary.</p>
<h3>Persistence for command processing</h3>
<p>Given that the database used for command processing is not used for querying, and that most (if not all) commands contain the IDs of the rows they&#8217;re going to affect, do we really need to have a column for every single domain object property? What if we just serialized the domain entity and put it into a single column, and had another column containing the ID? This sounds quite similar to key-value storage that is available in the various cloud providers. In which case, would you really need an object-relational mapper to persist to this kind of storage? </p>
<p>You could also pull out an additional property per piece of data where you&#8217;d want the &#8220;database&#8221; to enforce uniqueness. </p>
<p>I&#8217;m not suggesting that you do this in all cases &#8211; rather just trying to get you to rethink some basic assumptions.</p>
<h3>Let me reiterate</h3>
<p>How you process the commands is an implementation detail of CQRS.</p>
<h3>Keeping the query store in sync</h3>
<p>After the command-processing autonomous component has decided to accept a command, modifying its persistent store as needed, it publishes an event notifying the world about it. This event often is the &#8220;past tense&#8221; of the command submitted:</p>
<p>MakeCustomerPerferredCommand -> CustomerHasBeenMadePerferredEvent</p>
<p>The publishing of the event is done transactionally together with the processing of the command and the changes to its database. That way, any kind of failure on commit will result in the event not being sent. This is something that should be handled by default by your message bus, and if you&#8217;re using MSMQ as your underlying transport, requires the use of transactional queues.</p>
<p>The autonomous component which processes those events and updates the query data store is fairly simple, translating from the event structure to the persistent view model structure. I suggest having an event handler per view model class (AKA per table). </p>
<p>Here&#8217;s the picture of all the pieces again:</p>
<p><img src="/wp-content/uploads/cqrs.png" width="500" height="319" alt="CQRS" title="CQRS" /></p>
<h3>Bounded Contexts</h3>
<p>While CQRS touches on many pieces of software architecture, it is still not at the top of the food chain. CQRS if used is employed within a bounded context (DDD) or a business component (SOA) &#8211; a cohesive piece of the problem domain. The events published by one BC are subscribed to by other BCs, each updating their query and command data stores as needed.</p>
<p>UI&#8217;s from the CQRS found in each BC can be &#8220;mashed up&#8221; in a single application, providing users a single composite view on all parts of the problem domain. Composite UI frameworks are very useful for these cases.</p>
<h3>Summary</h3>
<p>CQRS is about coming up with an appropriate architecture for multi-user collaborative applications. It explicitly takes into account factors like data staleness and volatility and exploits those characteristics for creating simpler and more scalable constructs.</p>
<p>One cannot truly enjoy the benefits of CQRS without considering the user-interface, making it capture user intent explicitly. When taking into account client-side validation, command structures may be somewhat adjusted. Thinking through the order in which commands and events are processed can lead to notification patterns which make returning errors unnecessary.</p>
<p>While the result of applying CQRS to a given project is a more maintainable and performant code base, this simplicity and scalability require understanding the detailed business requirements and are not the result of any technical &#8220;best practice&#8221;. If anything, we can see a plethora of approaches to apparently similar problems being used together &#8211; data readers and domain models, one-way messaging and synchronous calls.</p>
<p>Although this blog post is over 3000 words (a record for this blog), I know that it doesn&#8217;t go into enough depth on the topic (it takes about 3 days out of the 5 of my <a href="http://www.udidahan.com/training/">Advanced Distributed Systems Design course</a> to cover everything in enough depth). Still, I hope it has given you the understanding of why CQRS is the way it is and possibly opened your eyes to other ways of looking at the design of distributed systems.</p>
<p>Questions and comments are most welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2009/12/09/clarified-cqrs/feed/</wfw:commentRss>
		<slash:comments>69</slash:comments>
		</item>
		<item>
		<title>The Fallacy Of ReUse</title>
		<link>http://www.udidahan.com/2009/06/07/the-fallacy-of-reuse/</link>
		<comments>http://www.udidahan.com/2009/06/07/the-fallacy-of-reuse/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 08:40:16 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[OO]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/?p=1026</guid>
		<description><![CDATA[This industry is pre-occupied with reuse.
There&#8217;s this belief that if we just reused more code, everything would be better.
Some even go so far as saying that the whole point of object-orientation was reuse &#8211; it wasn&#8217;t, encapsulation was the big thing. After that component-orientation was the thing that was supposed to make reuse happen. Apparently [...]]]></description>
			<content:encoded><![CDATA[<p>This industry is pre-occupied with reuse.</p>
<p>There&#8217;s this belief that if we just reused more code, everything would be better.</p>
<p>Some even go so far as saying that the whole point of object-orientation was reuse &#8211; it wasn&#8217;t, encapsulation was the big thing. After that component-orientation was the thing that was supposed to make reuse happen. Apparently that didn&#8217;t pan out so well either because here we are now pinning our reuseful hopes on service-orientation.</p>
<p>Entire books of patterns have been written on how to achieve reuse with the orientation of the day.<br />
Services have been classified every which way in trying to achieve this, from entity services and activity services, through process services and orchestration services. Composing services has been touted as the key to reusing, and creating reusable services.</p>
<p>I might as well let you in on the dirty-little secret:</p>
<h3>Reuse is a fallacy</h3>
<p>Before running too far ahead, let&#8217;s go back to what the actual goal of reuse was: getting done faster.</p>
<p>That&#8217;s it.</p>
<p>It&#8217;s a fine goal to have.</p>
<p>And here&#8217;s how reuse fits in to the picture:</p>
<blockquote><p>
If we were to write all the code of a system, we&#8217;d write a certain amount of code.<br />
If we could reuse some code from somewhere else that was written before, we could write less code.<br />
The more code we can reuse, the less code we write.<br />
The less code we write, the sooner we&#8217;ll be done!
</p></blockquote>
<p>However, the above logical progression is based on another couple of fallacies:</p>
<h3>Fallacy: All code takes the same amount of time to write</h3>
<h3>Fallacy: Writing code is the primary activity in getting a system done</h3>
<p>Anyone who&#8217;s actually written some code that&#8217;s gone into production knows this.</p>
<p>There&#8217;s the time it takes us to understand what the system should do.<br />
Multiply that by the time it takes the users to understand what the system should do <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
Then there&#8217;s the integrating that code with all the other code, databases, configuration, web services, etc.<br />
Debugging. Deploying. Debugging. Rebugging. Meetings. Etc.</p>
<p>Writing code is actually the least of our worries.<br />
We actually spend less time writing code than&#8230;</p>
<h3>Rebugging code</h3>
<p>Also known as bug regressions.</p>
<p>This is where we fix one piece of code, and in the process break another piece of code.<br />
It&#8217;s not like we do it on purpose. It&#8217;s all those dependencies between the various bits of code.<br />
The more dependencies there are, the more likely something&#8217;s gonna break.<br />
Especially when we have all sorts of hidden dependencies,<br />
like when other code uses stuff we put in the database without asking us what it means,<br />
or, heaven forbid, changing it without telling us.</p>
<p>These debugging/rebugging cycles can make stabilizing a system take a long time.</p>
<p>So, how does reuse help/hinder with that?</p>
<p>Here&#8217;s how:</p>
<h3>Dependencies multiply by reuse</h3>
<p>It&#8217;s to be expected. If you wrote the code all in one place, there are no dependencies. By reusing code, you&#8217;ve created a dependency. The more you reuse, the more dependencies you have. The more dependencies, the more rebugging.</p>
<p>Of course, we need to keep in mind the difference between&#8230;</p>
<h3>Reuse &#038; Use</h3>
<p>Your code <b>uses</b> the runtime API (JDK, .NET BCL, etc).<br />
Likewise other frameworks like (N)Hibernate, Spring, WCF, etc.</p>
<p>Reuse happens when you extend and override existing behaviors within other code.<br />
This is most often done by inheritance in OO languages.</p>
<p>Interestingly enough, by the above generally accepted definition, most web services &#8220;reuse&#8221; is actually really use.</p>
<p>Let&#8217;s take a look at the characteristics of the code we&#8217;re using and reusing to see where we get the greatest value:</p>
<h3>The value of (re)use</h3>
<p>If we were to (re)use a piece of code in only one part of our system, it would be safe to say that we would get less value than if we could (re)use it in more places. For example, we could say that for many web applications, the web framework we use provides more value than a given encryption algorithm that we may use in only a few places.</p>
<p>So, what characterizes the code we use in many places?</p>
<p>Well, it&#8217;s very <b>generic</b>.</p>
<p>Actually, the more generic a piece of code, the less likely it is that we&#8217;ll be changing something in it when fixing a bug in the system.</p>
<p><b>That&#8217;s important</b>.</p>
<p>However, when looking at the kind of code we reuse, and the reasons around it, we tend to see very <b>non-generic</b> code &#8211; something that deals with the domain-specific behaviors of the system. Thus, the likelihood of a bug fix needing to touch that code is higher than in the generic/use-not-reuse case, often much higher.</p>
<h3>How it all fits together</h3>
<blockquote><p>
Goal:&#09;Getting done faster<br />
Via:&#09;Spending less time debugging/rebugging/stabilizing<br />
Via:&#09;Having less dependencies reasonably requiring a bug fix to touch the dependent side<br />
Via:&#09;Not reusing non-generic code
</p></blockquote>
<p>This doesn&#8217;t mean you shouldn&#8217;t use generic code / frameworks where applicable &#8211; absolutely, you should.<br />
Just watch the number of kind of dependencies you introduce.</p>
<h3>Back to services</h3>
<p>So, if we follow the above advice with services, we wouldn&#8217;t want domain specific services reusing each other.<br />
If we could get away with it, we probably wouldn&#8217;t even want them using each other either.</p>
<p>As use and reuse go down, we can see that service autonomy goes up. And vice-versa.<br />
Luckily, we have service interaction mechanisms from Event-Driven Architecture that enable use without breaking autonomy.<br />
Autonomy is actually very similar to the principle of encapsulation that drove object-orientation in the first place.<br />
Interesting, isn&#8217;t it?</p>
<h3>In summary</h3>
<p>We all want to get done faster.</p>
<p>Way back when, someone told us reuse was the way to do that.</p>
<p>They were wrong.</p>
<p>Reuse may make sense in the most tightly coupled pieces of code you have, but not very much anywhere else.</p>
<p>When designing services in your SOA, stay away from reuse, and minimize use (with EDA patterns).</p>
<p>The next time someone pulls the &#8220;reuse excuse&#8221;, you&#8217;ll be ready.</p>
<hr size="1" />
<h3>Further Reading</h3>
<ul>
<li><a href="http://www.udidahan.com/2008/10/22/additional-logic-required-for-service-autonomy/">Additional logic required for service autonomy</a></li>
<li><a href="http://www.udidahan.com/2008/12/13/self-contained-events-and-soa/">Self-contained events &#038; SOA</a></li>
<li><a href="http://msdn2.microsoft.com/en-us/arcjournal/bb245672">Autonomous Services and Enterprise Entity Aggregation</a> [MS Architecture Journal]</li>
<li><a href="http://udidahan.weblogs.us/2006/05/26/podcast-does-soa-mean-the-end-of-oo/">Does SOA mean the end of OO?</a> [Podcast]</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2009/06/07/the-fallacy-of-reuse/feed/</wfw:commentRss>
		<slash:comments>49</slash:comments>
		</item>
		<item>
		<title>Saga Persistence and Event-Driven Architectures</title>
		<link>http://www.udidahan.com/2009/04/20/saga-persistence-and-event-driven-architectures/</link>
		<comments>http://www.udidahan.com/2009/04/20/saga-persistence-and-event-driven-architectures/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 11:50:44 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[Messaging]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/?p=992</guid>
		<description><![CDATA[When working with clients, I run into more than a couple of people that have difficulty with event-driven architecture (EDA). Even more people have difficulty understanding what sagas really are, let alone why they need to use them. I&#8217;d go so far to say that many people don&#8217;t realize the importance of how sagas are [...]]]></description>
			<content:encoded><![CDATA[<p><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 10px 10px; border-right-width: 0px" height="128" alt="image" src="http://www.udidahan.com/wp-content/uploads/saga_persistence.jpg" width="200" align="right" border="0" />When working with clients, I run into more than a couple of people that have difficulty with event-driven architecture (EDA). Even more people have difficulty understanding what sagas really are, let alone why they need to use them. I&#8217;d go so far to say that many people don&#8217;t realize the importance of how sagas are persisted in making it all work (including the Workflow Foundation team).</p>
<h3>The common e-commerce example</h3>
<p>We accept orders, bill the customer, and then ship them the product.</p>
<p>Fairly straight-forward.</p>
<p>Since each part of that process can be quite complex, let&#8217;s have each step be handled by a service:</p>
<p>Sales, Billing, and Shipping. Each of these services will publish an event when it&#8217;s done its part. Sales will publish OrderAccepted containing all the order information &#8211; order Id, customer Id, products, quantities, etc. Billing will publish CustomerBilledForOrder containing the customer Id, order Id, etc. And Shipping will publish OrderShippedToCustomer with its data.</p>
<p>So far, so good. EDA and SOA seem to be providing us some value.</p>
<h3>Where&#8217;s the saga?</h3>
<p>Well, let&#8217;s consider the behavior of the Shipping service. It shouldn&#8217;t ship the order to the customer until it has received the CustomerBilledForOrder event as well as the OrderAccepted event. In other words, Shipping needs to hold on to the state that came in the first event until the second event comes in. And this is exactly what sagas are for.</p>
<p>Let&#8217;s take a look at the saga code that implements this. In order to simplify the sample a bit, I&#8217;ll be omitting the product quantities.</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> ShippingSaga : Saga&lt;ShippingSagaData&gt;,</pre>
<pre><span class="lnum">   2:  </span>        ISagaStartedBy&lt;OrderAccepted&gt;,</pre>
<pre class="alt"><span class="lnum">   3:  </span>        ISagaStartedBy&lt;CustomerBilledForOrder&gt;</pre>
<pre><span class="lnum">   4:  </span>    {</pre>
<pre class="alt"><span class="lnum">   5:  </span>        <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(OrderAccepted message)</pre>
<pre><span class="lnum">   6:  </span>        {</pre>
<pre class="alt"><span class="lnum">   7:  </span>            <span class="kwrd">this</span>.Data.ProductIdsInOrder = message.ProductIdsInOrder;</pre>
<pre><span class="lnum">   8:  </span>        }</pre>
<pre class="alt"><span class="lnum">   9:  </span>&nbsp;</pre>
<pre><span class="lnum">  10:  </span>        <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(CustomerBilledForOrder message)</pre>
<pre class="alt"><span class="lnum">  11:  </span>        {</pre>
<pre><span class="lnum">  12:  </span>             <span class="kwrd">this</span>.Bus.Send&lt;ShipOrderToCustomer&gt;(</pre>
<pre class="alt"><span class="lnum">  13:  </span>                (m =&gt;</pre>
<pre><span class="lnum">  14:  </span>                {</pre>
<pre class="alt"><span class="lnum">  15:  </span>                    m.CustomerId = message.CustomerId;</pre>
<pre><span class="lnum">  16:  </span>                    m.OrderId = message.OrderId;</pre>
<pre class="alt"><span class="lnum">  17:  </span>                    m.ProductIdsInOrder = <span class="kwrd">this</span>.Data.ProductIdsInOrder;</pre>
<pre><span class="lnum">  18:  </span>                }</pre>
<pre class="alt"><span class="lnum">  19:  </span>                ));</pre>
<pre><span class="lnum">  20:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  21:  </span>            <span class="kwrd">this</span>.MarkAsComplete();</pre>
<pre><span class="lnum">  22:  </span>        }</pre>
<pre class="alt"><span class="lnum">  23:  </span>&nbsp;</pre>
<pre><span class="lnum">  24:  </span>        <span class="kwrd">public</span> <span class="kwrd">override</span> <span class="kwrd">void</span> Timeout(<span class="kwrd">object</span> state)</pre>
<pre class="alt"><span class="lnum">  25:  </span>        {</pre>
<pre><span class="lnum">  26:  </span>            </pre>
<pre class="alt"><span class="lnum">  27:  </span>        }</pre>
<pre><span class="lnum">  28:  </span>    }</pre>
</div>
<p>First of all, this looks fairly simple and straightforward, which is good.<br/><br />
It&#8217;s also wrong, which is not so good.</p>
<p>One problem we have here is that events may arrive out of order &#8211; first CustomerBilledForOrder, and only then OrderAccepted. What would happen in the above saga in that case? Well, we wouldn&#8217;t end up shipping the products to the customer, and customers tend not to like that (for some reason).</p>
<p>There&#8217;s also another problem here. See if you can spot it as I go through the explanation of ISagaStartedBy&lt;T&gt;.</p>
<h3>Saga start up and correlation</h3>
<p>The &#8220;ISagaStartedBy&lt;T&gt;&#8221; that is implemented for both messages indicates to the infrastructure (NServiceBus) that when a message of that type arrives, if an existing saga instance cannot be found, that a new instance should be started up. Makes sense, doesn&#8217;t it? For a given order, when the OrderAccepted event arrives first, Shipping doesn&#8217;t currently have any sagas handling it, so it starts up a new one. After that, when the CustomerBilledForOrder event arrives for that same order, the event should be handled by the saga instance that handled the first event &#8211; not by a new one.</p>
<p>I&#8217;ll repeat the important part: &#8220;the event should be handled by the saga instance that handled the first event&#8221;.</p>
<p>Since the only information we stored in the saga was the list of products, how would we be able to look up that saga instance when the next event came in containing an order Id, but no saga Id?</p>
<p>OK, so we need to store the order Id from the first event so that when the second event comes along we&#8217;ll be able to find the saga based on that order Id. Not too complicated, but something to keep in mind.</p>
<p>Let&#8217;s look at the updated code:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> ShippingSaga : Saga&lt;ShippingSagaData&gt;,</pre>
<pre><span class="lnum">   2:  </span>        ISagaStartedBy&lt;OrderAccepted&gt;,</pre>
<pre class="alt"><span class="lnum">   3:  </span>        ISagaStartedBy&lt;CustomerBilledForOrder&gt;</pre>
<pre><span class="lnum">   4:  </span>    {</pre>
<pre class="alt"><span class="lnum">   5:  </span>        <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(CustomerBilledForOrder message)</pre>
<pre><span class="lnum">   6:  </span>        {</pre>
<pre class="alt"><span class="lnum">   7:  </span>            <span class="kwrd">this</span>.Data.CustomerHasBeenBilled = <span class="kwrd">true</span>;</pre>
<pre><span class="lnum">   8:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">   9:  </span>            <span class="kwrd">this</span>.Data.CustomerId = message.CustomerId;</pre>
<pre><span class="lnum">  10:  </span>            <span class="kwrd">this</span>.Data.OrderId = message.OrderId;</pre>
<pre class="alt"><span class="lnum">  11:  </span>&nbsp;</pre>
<pre><span class="lnum">  12:  </span>            <span class="kwrd">this</span>.CompleteIfPossible();</pre>
<pre class="alt"><span class="lnum">  13:  </span>        }</pre>
<pre><span class="lnum">  14:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  15:  </span>        <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(OrderAccepted message)</pre>
<pre><span class="lnum">  16:  </span>        {</pre>
<pre class="alt"><span class="lnum">  17:  </span>            <span class="kwrd">this</span>.Data.ProductIdsInOrder = message.ProductIdsInOrder;</pre>
<pre><span class="lnum">  18:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  19:  </span>            <span class="kwrd">this</span>.Data.CustomerId = message.CustomerId;</pre>
<pre><span class="lnum">  20:  </span>            <span class="kwrd">this</span>.Data.OrderId = message.OrderId;</pre>
<pre class="alt"><span class="lnum">  21:  </span>&nbsp;</pre>
<pre><span class="lnum">  22:  </span>            <span class="kwrd">this</span>.CompleteIfPossible();</pre>
<pre class="alt"><span class="lnum">  23:  </span>        }</pre>
<pre><span class="lnum">  24:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  25:  </span>        <span class="kwrd">private</span> <span class="kwrd">void</span> CompleteIfPossible()</pre>
<pre><span class="lnum">  26:  </span>        {</pre>
<pre class="alt"><span class="lnum">  27:  </span>            <span class="kwrd">if</span> (<span class="kwrd">this</span>.Data.ProductIdsInOrder != <span class="kwrd">null</span> &amp;&amp; <span class="kwrd">this</span>.Data.CustomerHasBeenBilled)</pre>
<pre><span class="lnum">  28:  </span>            {</pre>
<pre><span class="lnum">  29:  </span>                <span class="kwrd">this</span>.Bus.Send&lt;ShipOrderToCustomer&gt;(</pre>
<pre class="alt"><span class="lnum">  30:  </span>                   (m =&gt;</pre>
<pre><span class="lnum">  31:  </span>                   {</pre>
<pre class="alt"><span class="lnum">  32:  </span>                       m.CustomerId = <span class="kwrd">this</span>.Data.CustomerId;</pre>
<pre><span class="lnum">  33:  </span>                       m.OrderId = <span class="kwrd">this</span>.Data.OrderId;</pre>
<pre class="alt"><span class="lnum">  34:  </span>                       m.ProductIdsInOrder = <span class="kwrd">this</span>.Data.ProductIdsInOrder;</pre>
<pre><span class="lnum">  35:  </span>                   }</pre>
<pre class="alt"><span class="lnum">  36:  </span>                   ));</pre>
<pre><span class="lnum">  37:  </span>                <span class="kwrd">this</span>.MarkAsComplete();</pre>
<pre class="alt"><span class="lnum">  38:  </span>            }</pre>
<pre><span class="lnum">  39:  </span>        }</pre>
<pre class="alt"><span class="lnum">  40:  </span>    }</pre>
</div>
<p>And that brings us to&#8230;</p>
<h3>Saga persistence</h3>
<p>We already saw why Shipping needs to be able to look up its internal sagas using data from the events, but what that means is that simple blob-type persistence of those sagas is out. NServiceBus comes with an NHibernate-based saga persister for exactly this reason, though any persistence mechanism which allows you to query on something other than saga Id would work just as well.</p>
<p>Let&#8217;s take a quick look at the saga data that we&#8217;ll be storing and see how simple it is:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> ShippingSagaData : ISagaEntity</pre>
<pre><span class="lnum">   2:  </span>    {</pre>
<pre class="alt"><span class="lnum">   3:  </span>        <span class="kwrd">public</span> <span class="kwrd">virtual</span> Guid Id { get; set; }</pre>
<pre><span class="lnum">   4:  </span>        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">string</span> Originator { get; set; }</pre>
<pre class="alt"><span class="lnum">   5:  </span>        <span class="kwrd">public</span> <span class="kwrd">virtual</span> Guid OrderId { get; set; }</pre>
<pre><span class="lnum">   6:  </span>        <span class="kwrd">public</span> <span class="kwrd">virtual</span> Guid CustomerId { get; set; }</pre>
<pre class="alt"><span class="lnum">   7:  </span>        <span class="kwrd">public</span> <span class="kwrd">virtual</span> List&lt;Guid&gt; ProductIdsInOrder { get; set; }</pre>
<pre><span class="lnum">   8:  </span>        <span class="kwrd">public</span> <span class="kwrd">virtual</span> <span class="kwrd">bool</span> CustomerHasBeenBilled { get; set; }</pre>
<pre class="alt"><span class="lnum">   9:  </span>    }</pre>
</div>
<p>You might have noticed the &#8220;Originator&#8221; property in there and wondered what it is for. First of all, the ISagaEntity interface requires the two properties Id and Originator. Originator is used to store the return address of the message that started the saga. Id is for what you think it&#8217;s for. In this saga, we don&#8217;t need to send any messages back to whoever started the saga, but in many others we do. In those cases, we&#8217;ll often be handling a message from some other endpoint when we want to possibly report some status back to the client that started the process. By storing that client&#8217;s address the first time, we can then &#8220;ReplyToOriginator&#8221; at any point in the process.</p>
<p>The manufacturing sample that comes with <a href="http://www.NServiceBus.com">NServiceBus</a> shows how this works.</p>
<h3>Saga Lookup</h3>
<p>Earlier, we saw the need to search for sagas based on order Id. The way to hook into the infrastructure and perform these lookups is by implementing &#8220;IFindSagas&lt;T&gt;.Using&lt;M&gt;&#8221; where T is the type of the saga data and M is the type of message. In our example, doing this using NHibernate would look like this:</p>
<p><!-- code formatted by http://manoli.net/csharpformat/ --></p>
<div class="csharpcode">
<pre class="alt"><span class="lnum">   1:  </span>    <span class="kwrd">public</span> <span class="kwrd">class</span> ShippingSagaFinder : </pre>
<pre><span class="lnum">   2:  </span>        IFindSagas&lt;ShippingSagaData&gt;.Using&lt;OrderAccepted&gt;,</pre>
<pre class="alt"><span class="lnum">   3:  </span>        IFindSagas&lt;ShippingSagaData&gt;.Using&lt;CustomerBilledForOrder&gt;</pre>
<pre><span class="lnum">   4:  </span>    {</pre>
<pre class="alt"><span class="lnum">   5:  </span>        <span class="kwrd">public</span> ShippingSagaData FindBy(CustomerBilledForOrder message)</pre>
<pre><span class="lnum">   6:  </span>        {</pre>
<pre class="alt"><span class="lnum">   7:  </span>            <span class="kwrd">return</span> FindBy(message.OrderId)</pre>
<pre><span class="lnum">   8:  </span>        }</pre>
<pre class="alt"><span class="lnum">   9:  </span>&nbsp;</pre>
<pre><span class="lnum">  10:  </span>        <span class="kwrd">public</span> ShippingSagaData FindBy(OrderAccepted message)</pre>
<pre class="alt"><span class="lnum">  11:  </span>        {</pre>
<pre><span class="lnum">  12:  </span>            <span class="kwrd">return</span> FindBy(message.OrderId)</pre>
<pre class="alt"><span class="lnum">  13:  </span>        }</pre>
<pre><span class="lnum">  14:  </span>&nbsp;</pre>
<pre class="alt"><span class="lnum">  15:  </span>        <span class="kwrd">private</span> ShippingSagaData FindBy(Guid orderId)</pre>
<pre><span class="lnum">  16:  </span>        {</pre>
<pre class="alt"><span class="lnum">  17:  </span>            <span class="kwrd">return</span> sessionFactory.GetCurrentSession().CreateCriteria(<span class="kwrd">typeof</span>(ShippingSagaData))</pre>
<pre><span class="lnum">  18:  </span>                .Add(Expression.Eq(<span class="str">"OrderId"</span>, orderId))</pre>
<pre class="alt"><span class="lnum">  19:  </span>                .UniqueResult&lt;ShippingSagaData&gt;();</pre>
<pre><span class="lnum">  20:  </span>        }</pre>
<pre class="alt"><span class="lnum">  21:  </span>&nbsp;</pre>
<pre><span class="lnum">  22:  </span>        <span class="kwrd">private</span> ISessionFactory sessionFactory;</pre>
<pre class="alt"><span class="lnum">  23:  </span>&nbsp;</pre>
<pre><span class="lnum">  24:  </span>        <span class="kwrd">public</span> <span class="kwrd">virtual</span> ISessionFactory SessionFactory</pre>
<pre class="alt"><span class="lnum">  25:  </span>        {</pre>
<pre><span class="lnum">  26:  </span>            get { <span class="kwrd">return</span> sessionFactory; }</pre>
<pre class="alt"><span class="lnum">  27:  </span>            set { sessionFactory = <span class="kwrd">value</span>; }</pre>
<pre><span class="lnum">  28:  </span>        }</pre>
<pre class="alt"><span class="lnum">  29:  </span>    }</pre>
</div>
<p>For a performance boost, we&#8217;d probably index our saga data by order Id.</p>
<h3>On concurrency</h3>
<p>Another important note is that for this saga, if both messages were handled in parallel on different machines, the saga could get stuck. The persistence mechanism here needs to prevent this. When using NHibernate over a database with the appropriate isolation level (Repeatable Read &#8211; the default in NServiceBus), this &#8220;just works&#8221;. If/When implementing your own saga persistence mechanism, it is important to understand the kind of concurrency your business logic can live with.</p>
<p>Take a look at Ayende&#8217;s example for <a href="http://ayende.com/Blog/archive/2009/01/23/rhino-dht-concurrency-handling-example-ndash-the-phone-billing-system.aspx">mobile phone billing</a> to get a feeling for what that&#8217;s like.</p>
<h3>Summary</h3>
<p>In almost any event-driven architecture, you&#8217;ll have services correlating multiple events in order to make decisions. The saga pattern is a great fit there, and not at all difficult to implement. You do need to take into account that events may arrive out of order and implement the saga logic accordingly, but it&#8217;s really not that big a deal. Do take the time to think through what data will need to be stored in order for the saga to be fault-tolerant, as well as a persistence mechanism that will allow you to look up that data based on event data.</p>
<p>If you feel like giving this approach a try, but don&#8217;t have an environment handy for this, download <a href="http://www.NServiceBus.com">NServiceBus</a> and take a look at the samples. It&#8217;s really quick and easy to get set up.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2009/04/20/saga-persistence-and-event-driven-architectures/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Backwards-Compatibility: Why Most Versioning Problems Aren&#8217;t</title>
		<link>http://www.udidahan.com/2009/04/10/backwards-compatibility-why-most-versioning-problems-arenrsquot/</link>
		<comments>http://www.udidahan.com/2009/04/10/backwards-compatibility-why-most-versioning-problems-arenrsquot/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 13:17:17 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/2009/04/10/backwards-compatibility-why-most-versioning-problems-arenrsquot/</guid>
		<description><![CDATA[
I’ve been to too many clients where I’ve been brought in to help them with their problems around service versioning when the solution I propose is simply to have version N+1 of the system be backwards-compatible with version N. If two adjacent versions of a given system aren’t compatible with each other, it is practically [...]]]></description>
			<content:encoded><![CDATA[<p><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 10px 10px; border-right-width: 0px" height="244" alt="image" src="http://www.udidahan.com/wp-content/ServicesVersioningPubSubandMultipleInher_11E4C/image.png" width="244" align="right" border="0" />
<p>I’ve been to too many clients where I’ve been brought in to help them with their problems around service versioning when the solution I propose is simply to have version N+1 of the system be backwards-compatible with version N. If two adjacent versions of a given system aren’t compatible with each other, it is practically impossible to solve versioning issues.</p>
<p>Here’s what happens when versions aren’t compatible:</p>
<blockquote><p>Admins stop the system from accepting any new requests, and wait until all current requests are done processing. They take a backup/snapshot of all relevant parts of the system (like data in the DB). Then, bring down the system – all of it. Install the new version on all machines. Bring everything back up. Let the users back in.</p></blockquote>
<p>If, heaven-forbid, problems were uncovered with the new version (since some problems only appear in production), the admins have to roll back to the previous version – once again bringing everything down.</p>
<p>This scenario is fairly catastrophic for any company that requires not-even high availability, but pretty continuous availability – like public facing web apps.</p>
<p>If adjacent versions were compatible with each other, we could upgrade the system piece-meal – machine by machine, where both the old and new versions will be running side by side, communicating with each other. While the system’s performance may be sub-optimal, it will continue to be available throughout upgrades as well as downgrades.</p>
<p>This isn’t trivial to do.</p>
<p>It impacts how you decide what is (and more importantly, what isn’t) nullable.</p>
<p>It may force you to spread certain changes to features across more versions (aka releases).</p>
<p>As such, you can expect this to affect how you do release and feature planning.</p>
<p>However, if you do not take these factors into account, it’s almost a certainty that your versioning problems will persist and no technology (new or old) will be able to solve them.</p>
<p>Coming next… Units of versioning – inside and outside a service.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2009/04/10/backwards-compatibility-why-most-versioning-problems-arenrsquot/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Self-Contained Events and SOA</title>
		<link>http://www.udidahan.com/2008/12/13/self-contained-events-and-soa/</link>
		<comments>http://www.udidahan.com/2008/12/13/self-contained-events-and-soa/#comments</comments>
		<pubDate>Sat, 13 Dec 2008 23:35:08 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[Master Data Management]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/2008/12/13/self-contained-events-and-soa/</guid>
		<description><![CDATA[In the architectural principle of fully self contained messages, events &#8220;can &#8211; instantly and in future &#8211; be interpreted as the respective event without the need to rely on additional data stores that would need to be in time-sync with the event during message-processing.&#8221;
Also, &#8220;passing reference data in a message makes the message-consuming systems dependent [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right: 0px; border-top: 0px; margin: 0px 0px 10px 10px; border-left: 0px; border-bottom: 0px" height="237" alt="diamond" src="http://www.udidahan.com/wp-content/uploads/diamond.jpg" width="214" align="right" border="0">In <a href="http://soa-eda.blogspot.com/2008/11/architectural-principle-of-fully-self.html">the architectural principle of fully self contained messages</a>, events &#8220;can &#8211; instantly and in future &#8211; be interpreted as the respective event without the need to rely on additional data stores that would need to be in time-sync with the event during message-processing.&#8221;</p>
<p>Also, &#8220;passing reference data in a message makes the message-consuming systems dependent on the knowledge and availability of actual persistent data that is stored “somewhere”. This data must separately be accessed for the sake of understanding the event that is represented by the message.&#8221; </p>
<p>The discussion of self-contained events can be compared to <a href="http://martinfowler.com/bliki/IntegrationDatabase.html">integration databases</a> vs <a href="http://martinfowler.com/bliki/ApplicationDatabase.html">application databases</a>. </p>
<h3>Centralized Integration &#8211; Pros &amp; Cons</h3>
<p>If everything in a system can access a central datastore, it is enough for one party to publish an event containing only the ID of an entity that that party previously entered/updated. Upon receiving that event, a subscriber would go to the central datastore and get the fields its interested in for that ID. The advantage of this approach is that the minimal amount of data necessary crosses the network, as subscribers only retrieve the fields that interest them. Martin Fowler describes the disadvantages as:</p>
<blockquote><p>&#8220;An integration database needs a schema that takes all its client applications into account. The resulting schema is either more general, more complex or both. The database usually is controlled by a separate group to the applications and database changes are more complex because they have to be negotiated between the database group and the various applications.&#8221;</p>
</blockquote>
<p>This is far from being aligned with the principle of autonomy so important to SOA. In that respect, the architectural principle of self-contained messages points us away from those problems and towards more autonomous services.</p>
<p>However, once we have these autonomous business services in place, we may find that we don&#8217;t need 100% fully self-contained messages anymore. </p>
<h3>A Real-World Example</h3>
<p>Let&#8217;s say we have 3 business services, Sales, Fulfillment, and Billing.</p>
<p>Sales publishes an OrderAccepted event when it accepts an order. That event contains all the order information.</p>
<p>Both Fulfillment and Billing are subscribed to this event, and thus receive it. </p>
<p>Fulfillment does not ship products to the customer until the customer has been billed, so it just stores the order information internally, and is done.</p>
<p>Billing starts the process of billing the customer for their order, possibly joining several orders into a single bill. After completing this process, it publishes a CustomerBilled event containing all billing information, as well as the IDs of the orders in that bill. It does not put all the order information in that event, as it is not the authoritative owner of that data.</p>
<p>When Fulfillment receives the CustomerBilled event, it uses the IDs of the orders contained in the event to find the order information it previously stored internally. It does not need to call the Sales service for this information or contact some central Master Data Management system. It uses the data it has, and goes about fulfilling the orders and shipping the products to the customer, finally publishing its own OrderShipped event.</p>
<p>Notice, as well, that in the original OrderAccepted event there were the IDs of products the customer ordered. These product IDs originated from another service, Merchandising, responsible for the product catalog. The same thing can be said for the customer ID originating from another service &#8211; Customer Care.</p>
<h3>The Issue of Time</h3>
<p>One could argue that since subscribers use previously cached data when processing new events, that data might not be up to date. Also, we may have race conditions between our services. In the above example, if Billing was extremely fast and more highly available than Fulfillment. Billing could have received the OrderAccepted event, processed it, and published the CustomerBilled event before Fulfillment had received the OrderAccepted event. In short, the CustomerBilled and OrderAccepted messages could be out of order in Fulfillment’s queue.</p>
<p>What would Fulfillment do when trying to process the CustomerBilled message when it doesn’t have the order information?
<p>Well, it knows that the world is parallel and non-sequential, so it does NOT return/log an error, but rather puts that message in the back of the queue to be processed again later (or maybe in some other temporary holding area). This enables the OrderAccepted message to be processed before the CustomerBilled message is retried. When the retry occurs, well, everything’s OK – it’s worked itself out over time.
<p>In the case where we retry again and again and things don’t work themselves out (maybe the OrderAccepted event was lost), we move that message off to a different queue for something else to resolve the conflict (maybe a person, maybe software). If/when the conflict is resolved (got the Sales system / messaging system to replay the OrderAccepted event), the conflict resolver returns the CustomerBilled message to the queue, and now everything works just fine.
<p>As all of this is occurring, the only thing that’s visible to external parties is that it happens to be taking longer than usual for the OrderShipped event to be published. In other words, time is the only difference.<br />
<h3>&nbsp;</h3>
<h3>Summary</h3>
<p>The problem of non-self-contained events is mitigated first and foremost by business services in SOA, and the apparent issue of time-synchronization by business logic inside these services.</p>
<p>Don&#8217;t be afraid to put IDs in your messages and events.</p>
<p>Do be afraid of using those IDs to access datastores shared by multiple &#8220;services&#8221;.</p>
<p>Using IDs to correlated current events to data from previous events is not only OK, it&#8217;s to be expected.</p>
<p>The architectural principle of fully self-contained messages steers us away from the problems of Integration Databases and towards Application Databases, autonomous services, and a better SOA implementation. From there, following the principle of autonomy from a business perspective, will lead us to services not publishing data in their messages that is owned by other services, taking us the next step of our journey to SOA.</p>
<hr size="1">
<h3> Related Content</h3>
<blockquote><p><a href="http://www.udidahan.com/2008/01/01/podcast-message-ordering-is-it-cost-effective/">[Podcast] Message Ordering &#8211; Is it cost effective?</a></p>
<p><a href="http://www.udidahan.com/2007/08/16/dont-eda-between-existing-systems/">Don&#8217;t EDA between existing systems</a></p>
<p><a href="http://www.udidahan.com/2007/05/31/podcast-handling-dependencies-between-subscribers-in-soa/">[Podcast] Handling dependencies between subscribers in SOA</a></p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/12/13/self-contained-events-and-soa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lost Notifications? No Problem.</title>
		<link>http://www.udidahan.com/2008/12/07/lost-notifications-no-problem/</link>
		<comments>http://www.udidahan.com/2008/12/07/lost-notifications-no-problem/#comments</comments>
		<pubDate>Sun, 07 Dec 2008 09:46:05 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[Messaging]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[Reliability]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/2008/12/07/lost-notifications-no-problem/</guid>
		<description><![CDATA[ One of the most common questions I get on the topic of pub/sub messaging is what happens if a notification is lost. Interestingly enough, there are some who almost entirely write-off this pattern because of this issue, preferring the control of request/response-exception. So, what should be done about lost messages? The short answer is [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right: 0px; border-top: 0px; margin: 0px 0px 10px 10px; border-left: 0px; border-bottom: 0px" height="148" alt="" src="http://www.udidahan.com/wp-content/uploads/image48.png" width="240" align="right" border="0"> One of the most common questions I get on the topic of pub/sub messaging is what happens if a notification is lost. Interestingly enough, there are some who almost entirely write-off this pattern because of this issue, preferring the control of request/response-exception. So, what should be done about lost messages? The short answer is durable messaging. The long answer is design.</p>
<h3>Durable Messaging</h3>
<p>In order to prevent a message from being lost when it is sent from a publisher to a subscriber, the message is written to disk on the publisher side, and then forwarded to the subscriber, where it is also written to disk. This store-and-forward mechanism enables our systems to gracefully recover from either side being temporarily unavailable.</p>
<p>In my <a href="http://msdn.microsoft.com/en-us/magazine/cc663023.aspx">MSDN article on this topic</a>, I outlined some problems with this approach. These problems are exacerbated for publishers. Imagine a publisher with 40 subscribers, publishing 10 messages a second, each containing 1MB of XML. If 10 of the subscribers are unavailable, that&#8217;s 100MB of data being written to the publisher&#8217;s disk every second, 6GB every minute. That&#8217;s liable to bring down a publisher before an administrator brews a cup of coffee.</p>
<p>Publishers have no choice but to throw away messages after a certain period of time.</p>
<h3>Publisher Contracts</h3>
<p>The whole issue of contracts and schema is considered one of the better understand parts of SOA. Unfortunately, the operational aspects of service contracts is hardly ever taken into account.</p>
<p>On top of the schema of the messages a service publishers, additional information is needed in the contract:</p>
<ol>
<li>How big will this message be?
<li>How often will it be published?
<li>How long will this message be stored if a subscriber is unavailable?</li>
</ol>
<p>This first two pieces of information are important for subscribers to do load and capacity planning. The last one is the most important as it dictates the required availability and fault-tolerance characteristic of subscribers.</p>
<h3>For Example</h3>
<p>In the canonical retail scenario, when our sales service accepts an order, it publishes an order accepted event. Other services subscribed to this event include shipping, billing, and business intelligence.</p>
<p>While shipping and billing are highly available and able to keep up with the rate at which orders are accepted, the business intelligence service is not. BI has two main parts to it &#8211; a nightly batch that does the number crunching, and a UI for reporting off of the results of that number crunching. Some even do the reporting in a semi-offline fashion, emailing reports back to the user when they&#8217;re ready.</p>
<p>Furthermore, nobody&#8217;s going to invest in servers for making BI highly available.</p>
<p>And wasn&#8217;t the whole point of this publish/subscribe messaging to keep our services autonomous? That not all services have to have the same level uptime?</p>
<p>Houston, do we have a problem.?</p>
<h3>Data Freshness</h3>
<p>There is a glimmer of light in all this doom and gloom.</p>
<p>Not all services have the same data freshness requirements.</p>
<p>The business intelligence service above doesn&#8217;t need to know about orders the second they&#8217;re accepted. A daily roll-up would be fine, and an hourly roll-up bring us that much closer to &#8220;real time business intelligence&#8221;.</p>
<p>So, while BI is ready to accept the sales message schema, it would like a slightly different contract around it &#8211; less messages per unit of time, more data in each message.</p>
<p>From the operational perspective of the sales service, it would be cost effective to have less &#8220;online&#8221; subscribers. It could even take things a few steps further. Instead of using the regular messaging backbone for transmitting these hourly messages, it could use FTP. The data could even be zipped to take up even less space. Since the total data size is less than the corresponding online stream, is stored on cheaper, large storage, and the number of subscribers for this zipped, hourly update is fairly small, these messages can be kept around far longer.</p>
<p>If you&#8217;ve heard about <a href="http://martinfowler.com/articles/consumerDrivenContracts.html">consumer-driven contracts</a>, this is it.</p>
<p>Note that we&#8217;re still talking about the same logical message schema.</p>
<h3>Summary</h3>
<p>It&#8217;s not that lost notifications aren&#8217;t a problem.</p>
<p><a href="http://en.wikipedia.org/wiki/Tesseract"><img style="margin: 0px 0px 10px 10px" src="http://upload.wikimedia.org/wikipedia/commons/5/55/Tesseract.gif" align="right"></a>
<p>It&#8217;s that they feed the design process in such a way that the resulting service ecosystem is set up in such a way that notifications won&#8217;t get lost. I know that that sounds kind of recursive, but that&#8217;s how it works. Either subscribers take care of their SLA allowing them to process the online stream of events, or they should subscribe to a different pipe (which will have different SLA requirements, but maybe they can deal with those).</p>
<p>It make sense to have multiple pipes for the same logical schema.</p>
<p>It&#8217;s practically a necessity to make pub/sub a feasible solution.</p>
<p>&nbsp;</p>
<hr size="1">
<h3>Related Content</h3>
<blockquote><p><a href="http://msdn.microsoft.com/en-us/magazine/cc663023.aspx">MSDN article on messaging and lost messages</a></p>
<p><a href="http://www.udidahan.com/2008/07/17/durable-messaging-dilemmas/">Durable messaging dilemmas</a></p>
<p><a href="http://www.udidahan.com/2008/10/22/additional-logic-required-for-service-autonomy/">Additional logic required for service autonomy</a></p>
<p><a href="http://www.udidahan.com/2008/11/01/soa-eda-and-cep-a-winning-combo/">More in depth example on events and pub/sub between services</a></p>
<p><a href="http://martinfowler.com/articles/consumerDrivenContracts.html">Consumer-Driven Contracts</a></p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/12/07/lost-notifications-no-problem/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SOA, EDA, and CEP a winning combo</title>
		<link>http://www.udidahan.com/2008/11/01/soa-eda-and-cep-a-winning-combo/</link>
		<comments>http://www.udidahan.com/2008/11/01/soa-eda-and-cep-a-winning-combo/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 22:57:14 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/2008/11/01/soa-eda-and-cep-a-winning-combo/</guid>
		<description><![CDATA[ There&#8217;s been some discussion on the SOA yahoo group around the connection between SOA, EDA, and CEP (complex event processing) since Jack&#8217;s original post on the topic. I&#8217;ve been waiting for the right opportunity to jump in and it seems to have come.
Dennis asked this:

There are different design choices in a SOA, even when [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right: 0px; border-top: 0px; margin: 0px 0px 10px 10px; border-left: 0px; border-bottom: 0px" height="240" alt="jump in" src="http://www.udidahan.com/wp-content/uploads/image46.png" width="320" align="right" border="0"> There&#8217;s been some discussion on the SOA yahoo group around the connection between SOA, EDA, and CEP (complex event processing) since Jack&#8217;s <a href="http://soa-eda.blogspot.com/2008/10/eda-versus-cep-and-soa.html">original post</a> on the topic. I&#8217;ve been waiting for the right opportunity to jump in and it seems to have come.
<p>Dennis asked this:<br />
<blockquote>
<p>There are different design choices in a SOA, even when you already have identified the services. I have a simple example that I would like to share:</p>
<p>Imagine a order-to-cash process. One part of that process is to register an order. Suppose we have two services, Order Service and Inventory Service. The task is to register the order and make a corresponding reservation of the stock level. I would be pleased to have the groups view on the following 3 design options (A, B, C):</p>
<p>A.<br />1. The &#8220;process/application&#8221; sends a message (sync or async) to &#8220;registerOrder&#8221; on the Order Service.<br />2. The &#8220;process/application&#8221; sends another message (sync or async) to &#8220;reserveStock&#8221; on the the Inventory Service.</p>
<p>B.<br />1. The &#8220;process/application&#8221; sends a message (sync or async) to &#8220;registerOrder&#8221; on the Order Service.<br />2. The Order Service sends a message (sync or async) to &#8220;reserveStock&#8221; on the the Inventory Service.</p>
<p>C.<br />1. The &#8220;process/application&#8221; sends a message (sync or async) to &#8220;registerOrder&#8221; on the Order Service.<br />2. The Order Service publishes an &#8220;orderReceived&#8221; event.<br />3. The Inventory Service subscribes to the &#8220;orderReceived&#8221; event .</p>
</blockquote>
<p>On the whole &#8220;already identified the services&#8221; thing &#8211; naming a service doesn&#8217;t mean much. It&#8217;s all about allocating responsibility, and until that&#8217;s been done, those &#8220;services&#8221; don&#8217;t give us very much information.
<p>&nbsp;<br />
<h3>Business Services</h3>
<p>If we were to view this example in light of business services, and look at the business events that make up this process, maybe we’d get a different perspective.<br />
<blockquote>
<p>Three business services: <strong>Sales</strong>, <strong>Inventory</strong>, and <strong>Shipping</strong>.</p>
</blockquote>
<p>In Sales, many applications and people may operate, including the person and the application he used to submit the order. When the order is submitted and goes through all the internal validation stuff, Sales raises an OrderTentativelyAccepted event.<br />
<h4>Inventory and Orders</h4>
<p>Inventory, which is subscribed to this event, checks if it has everything in stock for the order. For every item in the order on stock, it allocates that stock to the order and publishes the InventoryAllocatedToOrder event for it. For items/quantities not in stock, it starts a long running process which watches for inventory changes.
<p>When an InventoryChanged event occurs, it matches that against orders requiring allocation – if it finds one that requires stock, based on some logic to choose which order gets precedence, it publishes the InventoryAllocatedToOrder event.
<p>Sales, which is subscribed to the InventoryAllocatedToOrder event, upon receiving all events pertaining to the order tentatively accepted, will publish an OrderAccepted event.<br />
<h4>Orders and Shipping</h4>
<p>When Inventory receives the OrderAccepted event, it generates the pick list to bring all the stock from the warehouses to the loading docks, finally publishing the PickListGenerated event containing target docks.
<p>When Shipping receives the PickListGenerated event, it starts the yard management necessary to bring the needed kinds of trucks to the docks.
<p>&nbsp;<br />
<h3>What else is possible</h3>
<p>I could go on, talking about things like the maximum amount of time stock of various kinds can wait to be loaded on trucks, subscribing to earlier events to employ all kinds of optimization and prediction algorithms, having a Customer Care service notifying the customer about what’s going on with their order (probably different for different kinds of customers and preferred communication definitions). Obviously, we&#8217;d need a Billing service to handle the various kinds of billing procedures, whether or not the customer has credit, pays upon delivery, etc.
<p>It turns out that many business domains map very well to this join of SOA and EDA.
<p>&nbsp;<br />
<h3>What an ESB is for</h3>
<p>When we have these kinds of business services primarily publishing events and subscribing to those of other services, you don&#8217;t need much else from your &#8220;enterprise service bus&#8221;. All sorts of transformation, routing, and orchestration capabilities don&#8217;t come into play at all.
<p>In all truthfullness, those bits of functionality are really just a historical artifact of their broker heritage.
<p>Don&#8217;t get me wrong, sometimes a broker is a nice thing to have &#8211; behind a service boundary in order to perform some complex integration between existing legacy applications.
<p>Just keep that stuff in its place &#8211; not between services.<br />
<h3>&nbsp;</h3>
<h3>Complex Event Processing</h3>
<p>We can look at how Sales transitions an order from being tentatively accepted to being accepted as requiring event correlation around InventoryAllocatedToOrder events. This isn&#8217;t exactly &#8220;complex&#8221; in its own right. If there were some kind of CEP engine that did this for us out of the box, it might be a possible technology choice for implementing this logic within our service.
<p>As we add more concerns, like time, we may find new ways to make use of this engine. For instance, if the time to provide the order to the customer is approaching, we may choose to split the order into two &#8211; accepting one for which we have all the stock allocated, and leaving the second as tentatively accepted.<br />
<h3>&nbsp;</h3>
<h3>Summary</h3>
<p>While it is difficult to move forward on service responsibility without discussing the events it raises and those it subscribe to, the whole issue of CEP can be postponed for a while.
<p>Although there aren&#8217;t many who would say that EDA is necessary for driving down coupling in SOA, or that SOA won&#8217;t likely provide much value without EDA, or that SOA is necessary for providing the right boundaries for EDA, it&#8217;s been my experience that that is exactly the case.
<p>CEP, while being a challenging engineering field, and managing the technical risks around it necessary for a project to succeed in some circumstances, and really shines when used under the SOA/EDA umbrella, it should not be taken by itself and used at the topmost architectural levels.
<p>&nbsp;</p>
<hr size="1">
<h3>Related Content</h3>
<blockquote><p><a href="http://www.udidahan.com/2008/04/23/visual-cobol-enterprise-processes-and-soa/">SOA and Enterprise Processes</a></p>
<p><a href="http://www.udidahan.com/2008/08/11/command-query-separation-and-soa/">How client interaction fits with SOA</a></p>
<p><a href="http://www.udidahan.com/2008/04/20/time-dimension-necessary-for-successful-soa-data-strategy/">Time and SOA</a></p>
<p><a href="http://www.udidahan.com/2008/01/09/durable-messaging-is-not-enough/">Durable Messaging for Fault-Tolerant Services</a></p>
</blockquote>
<p>And if you&#8217;re wondering about how to handle all that complexity inside services (different kinds of billing, periodic tests for electronics inventory, etc), you might like listening to this <a href="http://www.udidahan.com/2006/08/28/podcast-business-and-autonomous-components-in-soa/">podcast about business components</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/11/01/soa-eda-and-cep-a-winning-combo/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Additional Logic Required For Service Autonomy</title>
		<link>http://www.udidahan.com/2008/10/22/additional-logic-required-for-service-autonomy/</link>
		<comments>http://www.udidahan.com/2008/10/22/additional-logic-required-for-service-autonomy/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 22:12:06 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/2008/10/22/additional-logic-required-for-service-autonomy/</guid>
		<description><![CDATA[Of the tenets of Service Orientation, the tenet of Autonomy is one that many understand intuitively. Interestingly enough, many in that same intuitive category don&#8217;t see pub/sub as a necessity for that autonomy.
Watch that first step
Although sometimes described as the first step of an organization moving to SOA, web-service-izing everything results in synchronous, blocking, request/response [...]]]></description>
			<content:encoded><![CDATA[<p>Of the tenets of Service Orientation, the tenet of Autonomy is one that many understand intuitively. Interestingly enough, many in that same intuitive category don&#8217;t see pub/sub as a necessity for that autonomy.</p>
<h3>Watch that first step</h3>
<p>Although sometimes described as the first step of an organization moving to SOA, web-service-izing everything results in synchronous, blocking, request/response interaction between services. The problem being that if one service were to become unavailable, all consumers of that service would not be able to perform any work. With the deep service &#8220;call stacks&#8221; this architectural style condones, the availability and performance of the entire organization will be dictated by the weakest link.</p>
<p>&nbsp;<img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; margin: 0px 0px 0px 100px; border-right-width: 0px" height="93" alt="weak link" src="http://www.udidahan.com/wp-content/uploads/image45.png" width="382" border="0"> </p>
<p>So, while I&#8217;d agree that many organizations do need to take this step, I&#8217;d caution against going into production at this step.</p>
<h3>Pub/Sub Considered Helpful</h3>
<p>When services interact with each other using publish/subscribe semantics we don&#8217;t have that technical problem of blocking. Subscribers cache the data published to them (either in memory or durably depending on their fault-tolerance requirements) thus enabling them to function and process requests even if the publisher is unavailable.</p>
<p>Consider the following scenario:</p>
<p>Let&#8217;s say we have an e-commerce site, a part of our Sales service responsible for selling products. Another service, let&#8217;s call it merchandising, is responsible for the catalog of products, and how much each product costs. Sales is subscribed to price update events published by Merchandising and saves (caches) those prices in its own database. When a customer orders some products on the site, Sales does not need to call Merchandising to get the price of the product and just uses the previously saved (cached) price. Thus, even if Merchandising is unavailable, Sales is able to accept orders. This is a big win as our merchandising application is not nearly as robust as our sales systems.</p>
<p>Yet, there are scenarios where data freshness requirements prevent this.</p>
<h3>Too Much of a Good Thing?</h3>
<p>Technically, the above story is accurate. There is nothing technically preventing Sales from accepting orders. Yet consider a scenario where Merchandising is down or unavailable for an extended period of time. While this may not be entirely likely for two servers in the same data center, consider physical kiosks which customers can use to buy products. Those kiosks may not receive updates for days. Should they accept orders?</p>
<p>That&#8217;s really a question to the business. If pricing data is stale for a time period greater than X, do not sell that item. The value of X may even be different for different kinds of products. Keep in mind that this issue only arose since we architected our services to be fully autonomous. In a synchronous systems architecture, this issue would not come up. As such, it is our responsibility as architects to go digging for these requirements as well as explaining to the business what the tradeoffs are.</p>
<p>In order to have more up to date data, we need to invest in more available hardware, networks, and infrastructure. This needs to be balanced against the predicted increase in revenue that more up to date (read higher) prices would give us.</p>
<h3>You Can Get What You Pay For</h3>
<p>Beyond the additional cost of writing that additional logic, and the perceived increased complexity, another difference to note between this architectural style and the synchronous/traditional one is that it puts control of spending back in the hands of business. </p>
<p>In a synchronous architecture, in order to achieve required performance and availability, all systems need to be performant requiring across the board investments in servers, networks, and storage. Without investing everywhere, the weakest link is liable to undo all other investments. In other words, your developers have made your investment choices for you. Scary, isn&#8217;t it.</p>
<p>A more prudent investment strategy would prefer spending on services that give the biggest bang for the buck, better known as return on investment. A pub/sub based architecture allows investing in data-freshness where it makes the most sense. For example, in sales of high profit products to strategic customers rather than inventory management of raw materials for products slated to be decommissioned. </p>
<p>That sounds a lot like IT-Business Alignment.</p>
<p>Maybe there&#8217;s something to this SOA thing after all&#8230;</p>
<hr size="1">
<p> Read more about:</p>
<blockquote><p><a href="http://www.udidahan.com/2008/05/16/7-simple-questions-for-service-selection/">7 Questions for Service Selection</a></p>
<p><a href="http://www.udidahan.com/2008/04/20/time-dimension-necessary-for-successful-soa-data-strategy/">7 Questions around data freshness</a>&nbsp;</p>
<p><a href="http://www.udidahan.com/2007/08/16/dont-eda-between-existing-systems/">Event-Driven Architecture and Legacy Applications</a></p>
<p><a href="http://www.udidahan.com/2007/02/20/autonomous-services-and-enterprise-entity-aggregation/">Autonomous Services and Enterprise Entity Aggregation</a></p>
</blockquote>
<p>Or listen to a podcast describing Business Components, <a href="http://www.udidahan.com/2006/08/28/podcast-business-and-autonomous-components-in-soa/">the connection of pub/sub and SOA</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/10/22/additional-logic-required-for-service-autonomy/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Services Don&#8217;t Serve</title>
		<link>http://www.udidahan.com/2008/08/23/services-dont-serve/</link>
		<comments>http://www.udidahan.com/2008/08/23/services-dont-serve/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 14:42:36 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/2008/08/23/services-dont-serve/</guid>
		<description><![CDATA[Another prominent SOA practitioner and blogger, Steve Jones, shows that, when you&#8217;re identifying your top level business services you shouldn&#8217;t be thinking about who&#8217;s going to consume them.
&#8220;We have three high level business services: Engagement, Management, [and] Production. [...] they represent different operational ambitions. Engagement is all about quantity and then filtering. Management is about [...]]]></description>
			<content:encoded><![CDATA[<p><img style="border-right: 0px; border-top: 0px; margin: 0px 0px 10px 10px; border-left: 0px; border-bottom: 0px" height="412" alt="image" src="http://www.udidahan.com/wp-content/uploads/image42.png" width="227" align="right" border="0">Another prominent SOA practitioner and blogger, Steve Jones, <a href="http://service-architecture.blogspot.com/2008/08/setting-high-level-services.html">shows that</a>, when you&#8217;re identifying your top level business services you shouldn&#8217;t be thinking about who&#8217;s going to consume them.</p>
<blockquote><p>&#8220;We have three high level business services: Engagement, Management, [and] Production. [...] they represent <i>different operational ambitions</i>. Engagement is all about quantity and then filtering. Management is about the quality and Production is about realising the benefits.&#8221;</p>
</blockquote>
<p>Services are not about &#8220;are you being served?&#8221;</p>
<p>They&#8217;re not about re-use, and barely about use. Events are what it&#8217;s all about.</p>
<p>Each service has its own responsibility and does what it needs to do, business-wise, to achieve its goals. Whether it&#8217;s about increasing the number of leads, ensuring high-profile clients get good service, or maximizing equipment utilization, services take responsibility.</p>
<p>I know I harp on this a lot.</p>
<p>It&#8217;s because it&#8217;s <em>that</em> important.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/08/23/services-dont-serve/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Command Query Separation and SOA</title>
		<link>http://www.udidahan.com/2008/08/11/command-query-separation-and-soa/</link>
		<comments>http://www.udidahan.com/2008/08/11/command-query-separation-and-soa/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 13:18:40 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Messaging]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Smart Client]]></category>

		<guid isPermaLink="false">http://www.udidahan.com/2008/08/11/command-query-separation-and-soa/</guid>
		<description><![CDATA[One of the common questions I receive from people starting to use nServiceBus is how one-way messaging fits with showing the user a grid (or list) of data. Thinking about publish/subscribe usually just gets them even more confused. Trying to resolve all this with Service Oriented Architecture leaves them wondering &#8211; why bother?

In regular client-server [...]]]></description>
			<content:encoded><![CDATA[<p>One of the common questions I receive from people starting to use nServiceBus is how one-way messaging fits with showing the user a grid (or list) of data. Thinking about publish/subscribe usually just gets them even more confused. Trying to resolve all this with Service Oriented Architecture leaves them wondering &#8211; why bother?</p>
<p><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="267" alt="client server" src="http://www.udidahan.com/wp-content/uploads/image38.png" width="477" border="0" /></p>
<p>In regular client-server development, the server is responsible for providing the client with all CRUD (create, read, update, and delete) capabilities. However, when users look at data they do not often require it to be up to date to the second (given that they often look at the same screen for several seconds to minutes at a time). As such, retrieving data from the same table as that being used for highly consistent transaction processing creates contention resulting in poor performance for all CRUD actions under higher load.</p>
<h4>A Scalable Solution </h4>
<p>One of the common answers to this question is for the server/service to publish a message when data changes (say, as the result of processing a message) and for clients to subscribe to these messages. When such a notification arrives at a client, the client would cache the data it needs. Then, when the user wants to see a grid of data, that data is already on the client. Of course, this solution doesn&#8217;t work so well for older client machines (like some point of service devices) or if there are millions of rows of data.</p>
<p>The thing is that this solution is one implementation of a more general pattern &#8211; command query separation (CQS).</p>
<h4>Command Query Separation</h4>
<p>Wikipedia <a href="http://en.wikipedia.org/wiki/Command-query_separation">describes</a> CQS as a pattern where &quot;&#8230; every method should either be a <i>command</i> that performs an action, or a <i>query</i> that returns data to the caller, but not both. More formally, methods should return a value only if they are referentially transparent and hence possess no side effects.&quot;</p>
<p>Martin Fowler is less strict about the use of CQS <a href="http://martinfowler.com/bliki/CommandQuerySeparation.html">allowing for exceptions</a>: &quot;Popping a stack is a good example of a modifier that modifies state. Meyer correctly says that you can avoid having this method, but it is a useful idiom. So I prefer to follow this principle when I can, but I&#8217;m prepared to break it to get my pop.&quot;</p>
<p>So, how does separating commands from queries and SOA help at all in getting data to and from a UI? The answer is based on Pat Helland&#8217;s thinking as described in his article <a href="http://msdn.microsoft.com/en-us/library/ms954587.aspx">Data on the Inside vs. Data on the Outside</a>.</p>
<h4>Services Cross Boxes </h4>
<p>The biggest lie around SOA is that services run.</p>
<p>Let that sink in a second.</p>
<p>Sure services have runnable components, but that&#8217;s not why they&#8217;re important. </p>
<p>I&#8217;ll skip the <a href="http://www.udidahan.com/first-time-here/#soa">books of background</a> and cut to the chase:</p>
<blockquote><p>Services communicate with each other using publish/subscribe and one-way messaging. Services have components inside them. Inside a service, these components can communicate with each using synchronous RPC, or any other mechanism. Also, <em>these components can reside on different machines</em>.</p>
</blockquote>
<p>This is broader than just scaling out a service. There can be service components running on the client as well as the server.</p>
<h4>SOA &amp; CQS</h4>
<p>Combining these two concepts together, here&#8217;s what comes out:</p>
<p><img src="http://www.nservicebus.com/img/CQS.png" /> </p>
<p>In this solution there are two services that span both client and server &#8211; one in charge of commands (create, update, delete), the other in charge of queries (read). These services communicate only via messages &#8211; one cannot access the database of the other. </p>
<p>The command service publishes messages about changes to data, to which the query service subscribes. When the query service receives such notifications, it saves the data in its own data store which may well have a different schema (optimized for queries like a star schema).</p>
<p>The client component which is in charge of showing grids of data to the user behaves the same as it would in a regular layered/tiered architecture, using synchronous blocking request/response to get its data &#8211; SOA doesn&#8217;t change that.</p>
<h4>Composite Applications </h4>
<p>Although the client side components of both the command and query services are hosted in the same process, they are very much independent of each other. That being said, from an interoperability perspective (the one that most people attribute to SOA), all of the client-side components will likely be developed using the same technology &#8211; although there are already ways to <a href="http://www.udidahan.com/2007/05/28/netjava-interop-is-not-a-reason-for-soa/">host Java code in .NET</a> and vice-versa. </p>
<p>Of course, once we talk about web UI&#8217;s things are a bit different &#8211; but still similar. While web-server-side there may be a level of independence, for browser side inter-component communications we&#8217;re still likely to target javascript. There, I&#8217;ve managed to say something technical supporting mashups and SOA without lying through my teeth.</p>
<p>On the Microsoft side with the recent release of the Composite Application Guidance &amp; Library (pronounced &quot;<a href="http://www.codeplex.com/CompositeWPF">prism</a>&quot;) I hope that more of these principles will be reaching the &quot;smart client&quot;. The command pattern is especially critical in maintaining the separation while enabling communication to still occur so I&#8217;m glad that, as one of the Prism advisors, I was able to simplify that part (<a href="http://codebetter.com/blogs/glenn.block/">Glenn</a> still has nightmares about that rooftop conversation).</p>
<h4>Publish / Subscribe</h4>
<p>In the &quot;scalable solution&quot; section up top I mentioned how publish/subscribe to the smart client is really just one implementation of CQS and SOA. So, how different is it really?</p>
<p><img style="border-right: 0px; border-top: 0px; border-left: 0px; border-bottom: 0px" height="241" alt="smart client pub/sub" src="http://www.udidahan.com/wp-content/uploads/image39.png" width="554" border="0" /> </p>
<p>Well, there will probably be a different technology mapping. Instead of a star-schema OLAP product, we might simply store the published data in memory on the client. That is, if you designed your components to be technology agnostic.</p>
<p>In terms of the use of nServiceBus, the same component is going to be subscribing to the same type of message &#8211; all that&#8217;s different is that now every client will be having data pushed to them rather than this occurring server-side only. </p>
<p>You could have the same code deployed differently in the same system &#8211; stronger clients subscribing themselves, weaker ones using a remote server. Web servers would probably be considered stronger clients. This kind of flexible deployment has proven to be extremely valuable for my larger clients. The added benefit of enabling users to work (view data) even while offline (somewhere there&#8217;s no WIFI) is just icing on the cake.</p>
<h4>A Word of Warning</h4>
<p>Once the client starts receiving notifications, and handling those on a background thread (as it should) the code becomes susceptible to deadlocks and data races. Juval does a good job of outlining <a href="http://www.udidahan.com/2008/04/11/wcf-smart-clients-and-deadlocks/">some of those</a> with respect to the use of WCF. Prism <a href="http://www.udidahan.com/2008/06/09/prism-occasionally-connected/">doesn&#8217;t provide any assurances</a> in this area either.</p>
<h4>Summary</h4>
<p>NServiceBus is not designed to be used for any and all types of communication in a given architecture. In the examples above, nServiceBus handles the publish/subscribe but leaves the synchronous RPC to existing solutions like WCF. Not only that, but synchronous RPC does have its place in architecture, just not across service boundaries. In all cases, data is served to users from a store different from that which transaction processing logic uses.</p>
<p>Command Query Separation is not only a good idea at the method/class level but has advantages at the SOA/System level as well &#8211; yet another good idea from 20 years ago that services build upon. Making use of CQS requires understanding your data and its uses &#8211; SOA builds on that by looking into data volatility and the freshness business requirements around it.</p>
<p>Finally, designing the components of your services in such a way that their dependency on technology is limited buys a lot of flexibility in terms of deployment and, consequently, significant performance and scalability gains.</p>
<p>Simple, it is. Easy, it is not.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/08/11/command-query-separation-and-soa/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>7 Simple Questions for Service Selection</title>
		<link>http://www.udidahan.com/2008/05/16/7-simple-questions-for-service-selection/</link>
		<comments>http://www.udidahan.com/2008/05/16/7-simple-questions-for-service-selection/#comments</comments>
		<pubDate>Fri, 16 May 2008 22:21:09 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2008/05/16/7-simple-questions-for-service-selection/</guid>
		<description><![CDATA[&#8220;So, which services do I need?&#8221;
This innocuous question comes up a lot. Usually I get this question after a short problem domain description. One of these came up on the nServiceBus discussion groups. Ayende took it and ran with it turning it into a nice blog post, An exercise in designing SOA systems. I&#8217;ve been [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;So, which services do I need?&#8221;</p>
<p>This innocuous question comes up a lot. Usually I get this question after a short problem domain description. One of these came up on the nServiceBus discussion groups. Ayende took it and ran with it turning it into a nice blog post, <a href="http://ayende.com/Blog/archive/2008/04/08/An-exercise-in-designing-SOA-systems.aspx">An exercise in designing SOA systems</a>. I&#8217;ve been meaning to write something myself. Bill put up a response already in his <a href="http://bill-poole.blogspot.com/2008/05/service-granularity-example.html">Service Granularity Example</a>. So, I&#8217;m late to the party, again, but here we go.</p>
<p>It&#8217;s almost impossible to know, right away, which services are appropriate.</p>
<p>So, I&#8217;m going to focus more on the process of getting there, rather than describing the solution itself.</p>
<p>The domain deals with a placement agency placing physicians in positions at hospitals. <a href="http://udidahan.weblogs.us/wp-content/uploads/doctor.png"><img style="border-right: 0px; border-top: 0px; margin: 0px 0px 10px 10px; border-left: 0px; border-bottom: 0px" height="244" alt="doctor" src="http://udidahan.weblogs.us/wp-content/uploads/doctor-thumb.png" width="225" align="right" border="0"></a> </p>
<h3>1. So, what does it actually <em>do</em>?</h3>
<p>In Ayende&#8217;s post, he describes several services, but I&#8217;d rather look at them as use cases: registering an open position, registering a candidate, verifying their credentials, etc. It&#8217;s worth going through this <em>requirements</em> process. It doesn&#8217;t necessarily translate immediately to services, but there&#8217;s value in it.</p>
<h3>2. What does it do it <em>to</em>?</h3>
<p>We should also be looking at the data model, an entity relationship diagram (ERD) , where we see that we may have placed a certain physician at a number of positions. It&#8217;s also important for us to know about under which circumstances a physician finished their employment at a previous position before, say, trying to place them at a position in the same hospital or chain of hospitals. Don&#8217;t go thinking that this what the database schema will look like, it&#8217;s all about understanding connections between various bits of data.</p>
<h3>3. When does that happen?</h3>
<p>The next step is to map the uses cases above to the entities in the ERD, which entity is used in which use case. It&#8217;s also important to differentiate between entities (or even more importantly, specific fields of entities) that are used in a read-only fashion within a given use case. For instance, when registering a new position, we&#8217;ll want to check that against other open positions in the same hospital so we don&#8217;t end up registering the same position twice. Also, we might want to suggest verified physicians whose credentials match the position&#8217;s requirements. Data we wouldn&#8217;t be interested in might be which other physicians we placed at that hospital.</p>
<h3>4. What just happened?</h3>
<p>Another valuable perspective on the problem domain is the business process view &#8211; what are the interesting business events in the system and how they unfold over time. For instance, physician registered, position opened, physician&#8217;s credentials verified, and physician placed in position (or position filled by physician) are events that describe a different business perspective than use cases.<a href="http://udidahan.weblogs.us/wp-content/uploads/image20.png"><img style="border-right: 0px; border-top: 0px; margin: 0px 0px 0px 10px; border-left: 0px; border-bottom: 0px" height="241" alt="image" src="http://udidahan.weblogs.us/wp-content/uploads/image-thumb17.png" width="244" align="right" border="0"></a></p>
<h3>5. How do I decide? </h3>
<p>Once we know what events there are, we can start looking at what kind of decisions we might want to make when those events occur and what data we&#8217;d need to make those decisions. These decisions may be as simple as updating a database or sending an email to a user. They also may include more advanced logic like when the profitability of an agreement with a specific hospital chain changes, prefer placing physicians in positions in that chain over others.</p>
<h3>6. How do I deal with all this information?</h3>
<p>After we have all of this information, we can start looking for cohesive bunching across all of these axes using these rules:</p>
<ul>
<li>Data that is modified by a use case gets published as an event.</li>
<li>Data that is required by a use case for read-only purposes, arrives as the result of subscribing to some event.</li>
</ul>
<p>Look for rules that differentiate behaviour based on the properties of data. Look for a correlation to some business concept. For instance, physicians probably won&#8217;t be changing their specialization, and open positions often deal with a certain specialization. Therefore, specific data instances tied to two different specializations can be said to be loosely coupled.</p>
<h3><strong>7. Which property slices across the domain?<a href="http://udidahan.weblogs.us/wp-content/uploads/image21.png"><img style="border-right: 0px; border-top: 0px; margin: 0px 0px 10px 10px; border-left: 0px; border-bottom: 0px" height="161" alt="image" src="http://udidahan.weblogs.us/wp-content/uploads/image-thumb18.png" width="244" align="right" border="0"></a> </strong></h3>
<p>Even though the ERD may not have made it clear, and the use cases didn&#8217;t show any particular break-down, nor did the events call out this point, the key to finding the way a business domain decomposes into services lies in decoupling specific data instances.</p>
<p>Actually, at this point we can clump autonomous components (mere technical bits) that handle a single message, into more granular business components.</p>
<blockquote><p>If you think about it, it makes a lot of sense. The kind of credential checking you&#8217;d do for physicians specializing in brain surgery would likely be different than for general practitioners. The kind of information you&#8217;d store would, therefore, also be different.</p>
</blockquote>
<h3>But, which services do I need?</h3>
<p>Quite frankly, I don&#8217;t have enough information to know. </p>
<p>But if we had continued this conversation, going through issues like transactional consistency, availability requirements, and other non-functional issues we could have&nbsp; gotten there. </p>
<p>If there&#8217;s one thing that I hope you got out of this, it&#8217;s that the questions are what&#8217;s important. The iterative process of looking at the problem domain from various perspectives, incorporating the new-found knowledge, and asking more questions is what leads us to a solution. But we don&#8217;t stop there. We keep looking for characteristics which split services apart into business components, and for consistency requirements that brings autonomous components together into services.</p>
<p>It&#8217;s not easy, but by focusing on these simple questions, you can get to a coherent service oriented architecture.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/05/16/7-simple-questions-for-service-selection/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Visual Cobol, Enterprise Processes, and SOA</title>
		<link>http://www.udidahan.com/2008/04/23/visual-cobol-enterprise-processes-and-soa/</link>
		<comments>http://www.udidahan.com/2008/04/23/visual-cobol-enterprise-processes-and-soa/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 15:15:08 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2008/04/23/visual-cobol-enterprise-processes-and-soa/</guid>
		<description><![CDATA[There&#8217;s a fairly intense discussion going on these days amongst the SOA illuminati. In the hopes that people will see me standing beside them and conclude that I too know something, I&#8217;ve decided to chip in.
Jim brought the concept of cohesion to the regular SOA discussions around loose coupling in his post Anemic Service Model, [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s a fairly intense discussion going on these days amongst the SOA illuminati. In the hopes that people will see me standing beside them and conclude that I too know something, I&#8217;ve decided to chip in.</p>
<p>Jim brought the concept of cohesion to the regular SOA discussions around loose coupling in his post <a href="http://jim.webber.name/2008/04/19/30b4f0e9-f67a-4310-bf38-ca0a3423206e.aspx">Anemic Service Model</a>, which I think, all in all, is a very good idea.</p>
<h3>Naïve Service Composition</h3>
<p><a href="http://udidahan.weblogs.us/wp-content/uploads/image15.png"><img style="border-right: 0px; border-top: 0px; margin: 0px 10px; border-left: 0px; border-bottom: 0px" height="173" alt="image" src="http://udidahan.weblogs.us/wp-content/uploads/image-thumb12.png" width="124" align="right" border="0"></a> Jim first calls out a common anti-pattern that seems to have become quite rampant &#8211; I&#8217;d call it <a href="http://jim.webber.name/?img=77cfd6f8-b2e0-4abe-bbbd-94c09036a5d4">naïve service composition</a> if only the things being composed could even be called services. And I think the tone being set is correct &#8211; a service needs to meet a stronger set of criteria than just being able to be composed. Multiple services sharing the same logical data store (in that the same actual rows/data elements are managed by multiple services) probably means there&#8217;s an encapsulation problem here. I agree with Jim sentiment here:</p>
<blockquote><p>&#8220;On the one hand we&#8217;re inclined, and indeed encouraged by the SOA brigade, to think of this architecture as a good fit for purpose because it is very loosely coupled. Since every component or service is decoupled from every other component or service it should be possible to arrange and re-arrange them in a Lego-style in a myriad of useful ways. Building out &#8220;business services&#8221; from some more fundamental set of services is how the books tell us to do it. In fact we could even do that quite easily with point-and-[click] BPM tools, ruling out such overheads as developers and change management along the way. Right?&#8221;</p>
</blockquote>
<h3>MVC? There are, like, 6 of them!<a href="http://udidahan.weblogs.us/wp-content/uploads/image16.png"><img style="border-right: 0px; border-top: 0px; margin: 0px 10px; border-left: 0px; border-bottom: 0px" height="146" alt="image" src="http://udidahan.weblogs.us/wp-content/uploads/image-thumb13.png" width="133" align="right" border="0"></a> </h3>
<p> However, I disagree with some of the conclusions that Jim draws from that point. Jim states &#8220;build your services to implement business processes&#8221;, and that services are &#8220;just an instance of MVC&#8221;. I&#8217;m going to leave alone the MVC statement since there are like 6 documented kinds of MVC not including the Front Controller stuff that the web guys are now calling MVC. I&#8217;m going to focus on the business process advice. JJ also <a href="http://www.ebpml.org/blog/75.htm">doesn&#8217;t seem to agree with this advice</a>. As Savas has already <a href="http://savas.parastatidis.name/2008/04/22/0a938298-7e90-42e5-9ab0-64e0fd7c7184.aspx">taken issue</a> with the tone of JJ&#8217;s response, I&#8217;ll keep my focus on the content.</p>
<h3>Visual Cobol</h3>
<p>First of all, in my previous conversations with Jim he had already denounced the procedural nature of composing higher-level business processes out of smaller services which implement small bits of common activities. Visual Cobol was how he described it. In JJ&#8217;s <a href="http://www.ebpml.org/blog/76.htm">follow-up post</a>, he called out the necessary aspect of autonomy that jives with Jim&#8217;s cohesion principle.</p>
<p>I&#8217;m a bit concerned about the way JJ tends to version what SOA means over time. It might make it impossible to have intelligent design discussions without tagging each sentence with &#8220;as SOA meant in 2006&#8243;. I acknowledge that the accepted meaning of SOA by various vendors has changed over the years. However, I&#8217;ve found that meanings rooted in decades of computer science tend to last and provide value that outlasts much of the industry-buzzword-bingo (SOA 2.0 anyone?).</p>
<h3>Cohesion, Business Domains, and Business Processes</h3>
<p><a href="http://udidahan.weblogs.us/wp-content/uploads/image17.png"><img style="border-right: 0px; border-top: 0px; margin: 0px 10px; border-left: 0px; border-bottom: 0px" height="204" alt="image" src="http://udidahan.weblogs.us/wp-content/uploads/image-thumb14.png" width="204" align="right" border="0"></a> My view of the original cohesion principles Steve discusses in his 2005 article <a href="http://steve.vinoski.net/pdf/IEEE-Old_Measures_for_New_Services.pdf">Old Measures for New Services</a> takes a business spin to Functional Cohesion:</p>
<blockquote><p>A service should be responsible for one business domain.</p>
</blockquote>
<p>If we jump off from this point, we&#8217;ll see that certain business processes which occur entirely in one business domain are fully encapsulated, whereas those macro-processes which cross many domains (like Order to Cash) cross multiple services &#8211; they do not become a service since that would break the &#8220;one business domain&#8221; rule. Given that services are loosely coupled, avoiding temporal coupling leads to services raising events. Thus, macro-processes are really just a series of events of various services where each service does its own internal business processes.</p>
<h3>Enterprise Processes &gt;&gt; Business Processes</h3>
<p>I think that maybe some of the difficulty in discussing concrete SOA guidance has to do with granularity. I&#8217;ve started calling those macro-processes something different from business processes, and that may just bring me full circle to Jim&#8217;s guidance.</p>
<blockquote><p>An Enterprise Process is any process which involves multiple business domains.</p>
</blockquote>
<p>Under that definition, a service may be responsible for multiple business processes in the same business domain. But still, one business process is usually not a service by itself.</p>
<h3>Business Components &amp; Autonomous Components to the Rescue</h3>
<p><a href="http://udidahan.weblogs.us/wp-content/uploads/image18.png"><img style="border-right: 0px; border-top: 0px; margin: 0px 10px; border-left: 0px; border-bottom: 0px" height="242" alt="image" src="http://udidahan.weblogs.us/wp-content/uploads/image-thumb15.png" width="183" align="right" border="0"></a> Finally, by introducing the additional levels of decomposition of business components and autonomous components I&#8217;ve found that we can focus the discourse on one concern at a time. My presentation on the topic can be found <a href="http://cid-c8ad44874742a74d.skydrive.live.com/self.aspx/Blog/Avoid_a_failed_SOA.ppsx">here</a>. The 30 second pitch is this:</p>
<blockquote><p>Business domains are inherently partitionable &#8211; data and rules. A business component represents one partition. An example of this is the domain of Sales being partitioned by strategic and non-strategic customers. Although the data structure might be similar or the same, the actual rows/data elements are not shared. Rules around discounts are different.</p>
<p>Within a business component, different activities should not interfere with each other. An autonomous component represents one activity. In our example, reporting on orders from strategic customers should not interfere with accepting their orders. As such, those activities should have different messages coming in on different endpoints. Each endpoint could have different characteristics, like durability. Losing a request for a report when a server restarts isn&#8217;t a big deal, however not a good idea for orders.</p>
</blockquote>
<p>For more information you could check out these episodes from my podcast:</p>
<blockquote><h4><b></b><a href="http://udidahan.weblogs.us/2006/08/28/podcast-business-and-autonomous-components-in-soa/">Business and Autonomous Components in SOA</a></h4>
<h4><a href="http://udidahan.weblogs.us/2007/06/02/podcast-using-autonomous-components-for-slas-in-soa/">Using Autonomous Components for SLAs in SOA</a></h4>
</blockquote>
<p>Questions and comments are always welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/04/23/visual-cobol-enterprise-processes-and-soa/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Sundblad Mistaken on Services</title>
		<link>http://www.udidahan.com/2008/03/16/sundblad-mistaken-on-services/</link>
		<comments>http://www.udidahan.com/2008/03/16/sundblad-mistaken-on-services/#comments</comments>
		<pubDate>Sun, 16 Mar 2008 13:29:39 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[Master Data Management]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2008/03/16/sundblad-mistaken-on-services/</guid>
		<description><![CDATA[The brilliant guys at 2xSundbland have launched their architect academy and it looks quite promising. I haven&#8217;t yet taken the trial lesson, but its in the queue. I have taken a look at the articles they have on the site as well, and they&#8217;re quite good. I especially like the Software Architecture vs. Software Engineering [...]]]></description>
			<content:encoded><![CDATA[<p>The brilliant guys at 2xSundbland have launched their <a href="http://academy.2xsundblad.com/">architect academy</a> and it looks quite promising. I haven&#8217;t yet taken the trial lesson, but its in the queue. I have taken a look at the articles they have on the site as well, and they&#8217;re quite good. I especially like the <a href="http://academy.2xsundblad.com/articles/Software_Architecture_vs_Software_Engineering.pdf">Software Architecture vs. Software Engineering</a> one. There is one topic in that article where I beg to differ, and it&#8217;s around services. The article (on page 7) describes the following scenario:</p>
<blockquote><p>Typically, in such an environment [SOA], services tend to be parts of multiple systems. For example, consider a Products service! It might start its life as part of a sales system. Later it might be involved in a purchasing system, a product development system, a marketing system, a warehousing system, and perhaps in several other systems too. This process may take years, and it really never ends. The service is the same, but its responsibilities and its external exposure are increased with each system it&#8217;s enrolled in.</p>
</blockquote>
<p>One of the core tenets of SOA that all vendors and analysts agree upon is that there should be <strong>loose coupling</strong> between services. If you were to design such a product service, it&#8217;s clear that changing part of its interface could break almost every system in the enterprise. That doesn&#8217;t sound like loose coupling to me.</p>
<p>If there&#8217;s one place that is the source of loose coupling &#8211; it&#8217;s the business. Warehousing is viewed by the business as being fairly independent of Marketing. While Sales might make use of data created in Product Development, business wouldn&#8217;t want any problems in IT related to Product Development to inhibit Sales ability to accept orders. That is another kind of loose coupling &#8211; the ability of one service to make use of &#8220;not-accurate-up-to-the-millisecond&#8221; data created by another service. That&#8217;s known as loose &#8220;temporal&#8221; coupling, as in <strong>loose coupling in the dimension of time</strong>.</p>
<h3>Loosely-Coupled Services</h3>
<p>So, in the example described we&#8217;d see the following services:</p>
<ul>
<li>Sales</li>
<li>Purchasing</li>
<li>Product Development</li>
<li>Marketing</li>
<li>Warehousing / Inventory</li>
</ul>
<p>Product data would flow between the services but each would have a very different internal view of it. </p>
<ul>
<li>Product Development would be more interested in managing the schedule and risk around a product&#8217;s development. </li>
<li>Marketing would probably be more focused on its relation to competing products and pricing. </li>
<li>Purchasing would be maintaining data as to which suppliers are being used to supply raw materials for the production of the product. </li>
<li>Sales would be looking at actually accepting orders and giving discounts.</li>
<li>Warehousing would be focused on the storage and transportation aspects of the product.</li>
</ul>
<p>As you can see, there is very little overlap in the data between these services even on something similar like product data. The logic of each service around the management of its data would be even more different. This leads to services with a high level of <strong>autonomy</strong>.</p>
<h3>There Be Dragons&#8230;</h3>
<p>Without starting at this business-level loose coupling, I doubt that any technical effort will succeed. That is to say every time I&#8217;ve seen this style implemented it has failed, but that&#8217;s no proof. Conversely, every time that we did start our SOA efforts by identifying the clear business fracture lines, we were able to maintain loose coupling all the way down. That is not to say that it always will succeed, but the logic is sound.</p>
<p>I suppose that the difference between my view on SOA and Sundblad&#8217;s stems from the fact that they put systems at a higher level of abstraction than services, and I put <strong>services on top</strong>. Regardless, I do agree with their views about architecture and engineering and consider them quite valuable. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/03/16/sundblad-mistaken-on-services/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>NServiceBus implements Erlang Concurrency</title>
		<link>http://www.udidahan.com/2008/02/08/nservicebus-implements-erlang-concurrency/</link>
		<comments>http://www.udidahan.com/2008/02/08/nservicebus-implements-erlang-concurrency/#comments</comments>
		<pubDate>Fri, 08 Feb 2008 14:19:07 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2008/02/08/nservicebus-implements-erlang-concurrency/</guid>
		<description><![CDATA[Going over the concurrency features of Erlang, the language famed for nine 9&#8217;s of uptime, I find that nServiceBus covers almost every single one.
Here&#8217;s the core list from Joe Armstrong&#8217;s book, Programming Erlang:
“In Erlang:

Creating and destroying processes is very fast.
Sending messages between processes is very fast.
Processess behave the same way on all operating systems.
We can [...]]]></description>
			<content:encoded><![CDATA[<p>Going over <a href="http://ulf.wiger.net/weblog/?p=10">the concurrency features of Erlang</a>, the language famed for nine 9&#8217;s of uptime, I find that nServiceBus covers almost every single one.</p>
<p>Here&#8217;s the core list from Joe Armstrong&#8217;s book, <a href="http://www.amazon.com/Programming-Erlang-Software-Concurrent-World/dp/193435600X/ref=pd_bbs_sr_1/105-5162226-7304414?ie=UTF8&amp;s=books&amp;qid=1184837752&amp;sr=8-1">Programming Erlang</a>:</p>
<blockquote><p>“In Erlang:</p>
<ul>
<li>Creating and destroying processes is very fast.</li>
<li>Sending messages between processes is very fast.</li>
<li>Processess behave the same way on all operating systems.</li>
<li>We can have very large numbers of processes.</li>
<li>Processes share no memory and are completely independent.</li>
<li>The only way for processes to interact is through message passing.”</li>
</ul>
</blockquote>
<p>In nServiceBus, we don&#8217;t create or destroy processes &#8211; that&#8217;s a Windows issue. Instead, we just do messaging with endpoints. If there&#8217;s a process behind that endpoint, and it responds, then other interesting things can occur.</p>
<p>In the continued list:</p>
<blockquote>
<ul>
<li>Message passing is asynchronous.</li>
<li>Processes can monitor each other.</li>
<li>It is possible to selectively receive messages.</li>
<li>Remote processes appear largely the same as local processes.</li>
</ul>
</blockquote>
<p>All of this is part of the design philosophy of nServiceBus. While I have yet to see a carrier-grade implementation of nServiceBus, we are enjoying very impressive system-wide uptimes in production. Oh, and the programming model is still plain-old .NET, so you don&#8217;t have to learn any new languages or environments (even though I think that you might learn something &#8211; I know I did).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/02/08/nservicebus-implements-erlang-concurrency/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sagas and Unit Testing &#8211; Business Process Verification Made Easy</title>
		<link>http://www.udidahan.com/2008/02/04/sagas-and-unit-testing-business-process-verification-made-easy/</link>
		<comments>http://www.udidahan.com/2008/02/04/sagas-and-unit-testing-business-process-verification-made-easy/#comments</comments>
		<pubDate>Mon, 04 Feb 2008 13:09:51 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Business Rules]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2008/02/04/sagas-and-unit-testing-business-process-verification-made-easy/</guid>
		<description><![CDATA[Sagas have always been designed with unit testing in mind. By keeping them disconnected from any communications or persistence technology, it was my belief that it should be fairly easy to use mock objects to test them. I&#8217;ve heard back from projects using nServiceBus this way that they were pleased with their ability to test [...]]]></description>
			<content:encoded><![CDATA[<p>Sagas have always been designed with unit testing in mind. By keeping them disconnected from any communications or persistence technology, it was my belief that it should be fairly easy to use mock objects to test them. I&#8217;ve heard back from projects using nServiceBus this way that they were pleased with their ability to test them, and thought all was well.</p>
<p>Not so.</p>
<p>The other day I sat down to implement and test a non-trivial business process, and the testing was far from easy. Now as developers go, I&#8217;m not great, or an expert on unit testing or TDD, but I&#8217;m above average. It should not have been this hard. And I tried doing it with <a href="http://www.ayende.com/projects/rhino-mocks.aspx">Rhino.Mocks</a>, <a href="http://www.typemock.com/">TypeMock</a>, and finally <a href="http://code.google.com/p/moq/">Moq</a>. It seemed like I was in a no-mans-land, between trying to do state-based testing, and setting expectations on the messages being sent (as well as correct values in those messages), nothing flowed.</p>
<p>Until I finally stopped trying to figure out how to test, and focused on what needed to be tested. I mean, it&#8217;s not like I was trying to build a generic mocking framework like <a href="http://feeds.feedburner.com/~r/DanielCazzulino/~3/228130195/NewMoqfeaturesformockverificationandcreation.aspx">Daniel</a>.</p>
<p>Here&#8217;s an example business process, or actually, part of one, and then we&#8217;ll see how that can be tested. By the way, there will be a post coming soon which describes how we go about analysing a system, coming up with these message types, and how these sagas come into being, so stay tuned. Either that, or just come to <a href="http://qcon.infoq.com/london/presentation/Build+Scalable%2C+Maintainable%2C+Distributed+Enterprise+.NET+Solutions+with+nServiceBus">my tutorial at QCon.</a></p>
<p>On with the process:</p>
<blockquote><p>1. When we receive a CreateOrderMessage, whose “Completed” flag is true, we’ll send 2 AuthorizationRequestMessages to internal systems (for managers to authorize the order), one OrderStatusUpdatedMessage to the caller with a status “Received”, and a TimeoutMessage to the TimeoutManager requesting to be notified – so that the process doesn’t get stuck if one or both messages don’t get a response.</p>
<p>2. When we receive the first AuthorizationResponseMessage, we notify the initiator of the Order by sending them a OrderStatusUpdatedMessage with a status “Authorized1”.</p>
<p>3. When we get “timed out” from the TimeoutManager, we check if at least one AuthorizationResponseMessage has arrived, and if so, publish an OrderAcceptedMessage, and notify the initator (again via the OrderStatusUpdatedMessage) this time with a status of “Accepted”.</p></blockquote>
<p>And here&#8217;s the test:</p>
<div style="overflow: scroll; width: 95%"><!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">            .csharpcode, .csharpcode pre  {  	font-size: small;  	color: black;  	font-family: consolas, "Courier New", courier, monospace;  	background-color: #ffffff;  	/*white-space: pre;*/  }  .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt   {  	background-color: #f4f4f4;  	width: 100%;  	margin: 0em;  } .csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode">    <span class="kwrd">public</span> <span class="kwrd">class</span> OrderSagaTests
    {
        <span class="kwrd">private</span> OrderSaga orderSaga = <span class="kwrd">null</span>;
        <span class="kwrd">private</span> <span class="kwrd">string</span> timeoutAddress;
        <span class="kwrd">private</span> Saga Saga;     

        [SetUp]
        <span class="kwrd">public</span> <span class="kwrd">void</span> Setup()
        {
            timeoutAddress = <span class="str">"timeout"</span>;
            Saga = Saga.Test(<span class="kwrd">out</span> orderSaga, timeoutAddress);
        }     

        [Test]
        <span class="kwrd">public</span> <span class="kwrd">void</span> OrderProcessingShouldCompleteAfterOneAuthorizationAndOneTimeout()
        {
            Guid externalOrderId = Guid.NewGuid();
            Guid customerId = Guid.NewGuid();
            <span class="kwrd">string</span> clientAddress = <span class="str">"client"</span>;     

            CreateOrderMessage createOrderMsg = <span class="kwrd">new</span> CreateOrderMessage();
            createOrderMsg.OrderId = externalOrderId;
            createOrderMsg.CustomerId = customerId;
            createOrderMsg.Products = <span class="kwrd">new</span> List&lt;Guid&gt;(<span class="kwrd">new</span> Guid[] { Guid.NewGuid() });
            createOrderMsg.Amounts = <span class="kwrd">new</span> List&lt;<span class="kwrd">float</span>&gt;(<span class="kwrd">new</span> <span class="kwrd">float</span>[] { 10.0F });
            createOrderMsg.Completed = <span class="kwrd">true</span>;     

            TimeoutMessage timeoutMessage = <span class="kwrd">null</span>;     

            Saga.WhenReceivesMessageFrom(clientAddress)
                .ExpectSend&lt;AuthorizeOrderRequestMessage&gt;(
                    <span class="kwrd">delegate</span>(AuthorizeOrderRequestMessage m)
                    {
                        <span class="kwrd">return</span> m.SagaId == orderSaga.Id;
                    })
                .ExpectSend&lt;AuthorizeOrderRequestMessage&gt;(
                    <span class="kwrd">delegate</span>(AuthorizeOrderRequestMessage m)
                    {
                        <span class="kwrd">return</span> m.SagaId == orderSaga.Id;
                    })
                .ExpectSendToDestination&lt;OrderStatusUpdatedMessage&gt;(
                    <span class="kwrd">delegate</span>(<span class="kwrd">string</span> destination, OrderStatusUpdatedMessage m)
                    {
                        <span class="kwrd">return</span> m.OrderId == externalOrderId &amp;&amp; destination == clientAddress;
                    })
                .ExpectSendToDestination&lt;TimeoutMessage&gt;(
                    <span class="kwrd">delegate</span>(<span class="kwrd">string</span> destination, TimeoutMessage m)
                    {
                        timeoutMessage = m;
                        <span class="kwrd">return</span> m.SagaId == orderSaga.Id &amp;&amp; destination == timeoutAddress;
                    })
                .When(<span class="kwrd">delegate</span> { orderSaga.Handle(createOrderMsg); });     

            Assert.IsFalse(orderSaga.Completed);     

            AuthorizeOrderResponseMessage response = <span class="kwrd">new</span> AuthorizeOrderResponseMessage();
            response.ManagerId = Guid.NewGuid();
            response.Authorized = <span class="kwrd">true</span>;
            response.SagaId = orderSaga.Id;     

            Saga.ExpectSendToDestination&lt;OrderStatusUpdatedMessage&gt;(
                    <span class="kwrd">delegate</span>(<span class="kwrd">string</span> destination, OrderStatusUpdatedMessage m)
                    {
                        <span class="kwrd">return</span> (destination == clientAddress &amp;&amp;
                                m.OrderId == externalOrderId &amp;&amp;
                                m.Status == OrderStatus.Authorized1);
                    })
                .When(<span class="kwrd">delegate</span> { orderSaga.Handle(response); });     

            Assert.IsFalse(orderSaga.Completed);     

            Saga.ExpectSendToDestination&lt;OrderStatusUpdatedMessage&gt;(
                    <span class="kwrd">delegate</span>(<span class="kwrd">string</span> destination, OrderStatusUpdatedMessage m)
                    {
                        <span class="kwrd">return</span> (destination == clientAddress &amp;&amp;
                                m.OrderId == externalOrderId &amp;&amp;
                                m.Status == OrderStatus.Accepted);
                    })
                .ExpectPublish&lt;OrderAcceptedMessage&gt;(
                    <span class="kwrd">delegate</span>(OrderAcceptedMessage m)
                    {
                        <span class="kwrd">return</span> (m.CustomerId == customerId);
                    })
                .When(<span class="kwrd">delegate</span> { orderSaga.Timeout(timeoutMessage.State); });     

            Assert.IsTrue(orderSaga.Completed);
        }
    }</pre>
</div>
<p>You might notice that this style is a bit similar to the fluent testing found in Rhino Mocks. That&#8217;s not coincidence. It actually makes use of Rhino Mocks internally. The thing that I discovered was that in order to test these sagas, you don&#8217;t need to actually see a mocking framework. All you should have to do is express how messages get sent, and under what criteria those messages are valid.</p>
<p>If you&#8217;re wondering what the OrderSaga looks like, you can find the code right here. It&#8217;s not a complete business process implementation, but its enough to understand how one would look like:</p>
<div style="overflow: scroll; width: 95%"><!-- code formatted by http://manoli.net/csharpformat/ --><br />
<style type="text/css">            .csharpcode, .csharpcode pre  {  	font-size: small;  	color: black;  	font-family: consolas, "Courier New", courier, monospace;  	background-color: #ffffff;  	/*white-space: pre;*/  }  .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt   {  	background-color: #f4f4f4;  	width: 100%;  	margin: 0em;  } .csharpcode .lnum { color: #606060; }</style>
<pre class="csharpcode"><span class="kwrd">using</span> System;
<span class="kwrd">using</span> System.Collections.Generic;
<span class="kwrd">using</span> ExternalOrderMessages;
<span class="kwrd">using</span> NServiceBus.Saga;
<span class="kwrd">using</span> NServiceBus;
<span class="kwrd">using</span> InternalOrderMessages;     

<span class="kwrd">namespace</span> ProcessingLogic
{
    [Serializable]
    <span class="kwrd">public</span> <span class="kwrd">class</span> OrderSaga : ISaga&lt;CreateOrderMessage&gt;,
        ISaga&lt;AuthorizeOrderResponseMessage&gt;,
        ISaga&lt;CancelOrderMessage&gt;
    {
        <span class="preproc">#region</span> config info     

        [NonSerialized]
        <span class="kwrd">private</span> IBus bus;
        <span class="kwrd">public</span> IBus Bus
        {
            set { <span class="kwrd">this</span>.bus = <span class="kwrd">value</span>; }
        }     

        [NonSerialized]
        <span class="kwrd">private</span> Reminder reminder;
        <span class="kwrd">public</span> Reminder Reminder
        {
            set { <span class="kwrd">this</span>.reminder = <span class="kwrd">value</span>; }
        }     

        <span class="preproc">#endregion</span>     

        <span class="kwrd">private</span> Guid id;
        <span class="kwrd">private</span> <span class="kwrd">bool</span> completed;
        <span class="kwrd">public</span> <span class="kwrd">string</span> clientAddress;
        <span class="kwrd">public</span> Guid externalOrderId;
        <span class="kwrd">public</span> <span class="kwrd">int</span> numberOfPendingAuthorizations = 2;
        <span class="kwrd">public</span> List&lt;CreateOrderMessage&gt; orderItems = <span class="kwrd">new</span> List&lt;CreateOrderMessage&gt;();     

        <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(CreateOrderMessage message)
        {
            <span class="kwrd">this</span>.clientAddress = <span class="kwrd">this</span>.bus.SourceOfMessageBeingHandled;
            <span class="kwrd">this</span>.externalOrderId = message.OrderId;     

            <span class="kwrd">this</span>.orderItems.Add(message);     

            <span class="kwrd">if</span> (message.Completed)
            {
                <span class="kwrd">for</span> (<span class="kwrd">int</span> i = 0; i &lt; <span class="kwrd">this</span>.numberOfPendingAuthorizations; i++)
                {
                    AuthorizeOrderRequestMessage req = <span class="kwrd">new</span> AuthorizeOrderRequestMessage();
                    req.SagaId = <span class="kwrd">this</span>.id;
                    req.OrderData = orderItems;     

                    <span class="kwrd">this</span>.bus.Send(req);
                }
            }     

            <span class="kwrd">this</span>.SendUpdate(OrderStatus.Recieved);     

            <span class="kwrd">this</span>.reminder.ExpireIn(message.ProvideBy - DateTime.Now, <span class="kwrd">this</span>, <span class="kwrd">null</span>);
        }     

        <span class="kwrd">public</span> <span class="kwrd">void</span> Timeout(<span class="kwrd">object</span> state)
        {
            <span class="kwrd">if</span> (<span class="kwrd">this</span>.numberOfPendingAuthorizations &lt;= 1)
                <span class="kwrd">this</span>.Complete();
        }     

        <span class="kwrd">public</span> Guid Id
        {
            get { <span class="kwrd">return</span> id; }
            set { id = <span class="kwrd">value</span>; }
        }     

        <span class="kwrd">public</span> <span class="kwrd">bool</span> Completed
        {
            get { <span class="kwrd">return</span> completed; }
        }     

        <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(AuthorizeOrderResponseMessage message)
        {
            <span class="kwrd">if</span> (message.Authorized)
            {
                <span class="kwrd">this</span>.numberOfPendingAuthorizations--;     

                <span class="kwrd">if</span> (<span class="kwrd">this</span>.numberOfPendingAuthorizations == 1)
                    <span class="kwrd">this</span>.SendUpdate(OrderStatus.Authorized1);
                <span class="kwrd">else</span>
                {
                    <span class="kwrd">this</span>.SendUpdate(OrderStatus.Authorized2);
                    <span class="kwrd">this</span>.Complete();
                }
            }
            <span class="kwrd">else</span>
            {
                <span class="kwrd">this</span>.SendUpdate(OrderStatus.Rejected);
                <span class="kwrd">this</span>.Complete();
            }
        }     

        <span class="kwrd">public</span> <span class="kwrd">void</span> Handle(CancelOrderMessage message)
        {     

        }     

        <span class="kwrd">private</span> <span class="kwrd">void</span> SendUpdate(OrderStatus status)
        {
            OrderStatusUpdatedMessage update = <span class="kwrd">new</span> OrderStatusUpdatedMessage();
            update.OrderId = <span class="kwrd">this</span>.externalOrderId;
            update.Status = status;     

            <span class="kwrd">this</span>.bus.Send(<span class="kwrd">this</span>.clientAddress, update);
        }     

        <span class="kwrd">private</span> <span class="kwrd">void</span> Complete()
        {
            <span class="kwrd">this</span>.completed = <span class="kwrd">true</span>;     

            <span class="kwrd">this</span>.SendUpdate(OrderStatus.Accepted);     

            OrderAcceptedMessage accepted = <span class="kwrd">new</span> OrderAcceptedMessage();
            accepted.Products = <span class="kwrd">new</span> List&lt;Guid&gt;(<span class="kwrd">this</span>.orderItems.Count);
            accepted.Amounts = <span class="kwrd">new</span> List&lt;<span class="kwrd">float</span>&gt;(<span class="kwrd">this</span>.orderItems.Count);     

            <span class="kwrd">this</span>.orderItems.ForEach(<span class="kwrd">delegate</span>(CreateOrderMessage m)
                                        {
                                            accepted.Products.AddRange(m.Products);
                                            accepted.Amounts.AddRange(m.Amounts);
                                            accepted.CustomerId = m.CustomerId;
                                        });     

            <span class="kwrd">this</span>.bus.Publish(accepted);
        }
    }
}</pre>
</div>
<p>All this code is online in the subversion repository under /Samples/Saga.</p>
<p>Questions, comments, and general thoughts are always appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/02/04/sagas-and-unit-testing-business-process-verification-made-easy/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>[Podcast] Message Ordering: Is it Cost Effective?</title>
		<link>http://www.udidahan.com/2008/01/01/podcast-message-ordering-is-it-cost-effective/</link>
		<comments>http://www.udidahan.com/2008/01/01/podcast-message-ordering-is-it-cost-effective/#comments</comments>
		<pubDate>Tue, 01 Jan 2008 23:01:16 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Ask Udi Podcast]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[MSMQ]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Threading]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2008/01/01/podcast-message-ordering-is-it-cost-effective/</guid>
		<description><![CDATA[In this podcast we&#8217;ll be discussing the issues around multi-threaded processing of messages by a service, specifically that the processing of message received second may be finished before that of the first. This scenario tends to rear its ugly head at higher levels of load and is critical for correctness in high-scalability environments.
Our long time [...]]]></description>
			<content:encoded><![CDATA[<p>In this podcast we&#8217;ll be discussing <span class="greenBlurb">the issues around multi-threaded processing of messages by a service, specifically that the processing of message received second may be finished before that of the first. This scenario tends to rear its ugly head at higher levels of load and is critical for correctness in high-scalability environments.</span></p>
<p>Our long time listener Bill asks:</p>
<blockquote><p> Hi Udi,</p>
<p>I have a question  around processing of messages in proper order.  When leveraging multiple  threads to process messages in a message queue, it is possible for the  second message in the queue to get processed before the first &#8211; especially  if the first message is considerably larger than the second.  I have taken  a lot of care to make sure that messages are sent in the correct order, only to  find that the receiving system can process them out of order  anyway.</p>
<p>Consider a  Policy Created notification, which must come before a Policy Approved  notification.  If both messages are sitting in the queue when the receiving  service starts up, the approval message can be processed before the creation  message. How can I make sure that message ordering is respected by the receiving  system?  I am using WCF/MSMQ as the underlying transport by the way.   The only way I have found so far is to limit the receiving service to a single  thread, which is by no means desirable.</p>
<p>Best  Regards,</p>
<p>Bill</p></blockquote>
<h3>Download</h3>
<p><a href="http://www.ddj.com/architect/205206017">Download via the Dr. Dobb&#8217;s site</a></p>
<p>Or download directly <a href="http://www.dobbsprojects.com/media/newengine/dynamp.php/071231ud01.mp3?podcast=071231ud01.mp3">here</a>.</p>
<h3>Additional References</h3>
<ul>
<li>Blog post: <a href="http://udidahan.weblogs.us/2007/12/09/in-order-messaging-a-myth/">In-Order Messaging a Myth?</a></li>
<li>Blog post: <a href="http://udidahan.weblogs.us/2007/12/15/handling-messages-out-of-order/">Handling Messages out of Order</a></li>
</ul>
<h3>Want more?</h3>
<p>Check out the <a href="/ask-udi/">“Ask Udi”</a> archives.</p>
<h3>Got a question?</h3>
<p><a href="mailto:podcast@UdiDahan.com">Send Udi your question to answer on the show.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2008/01/01/podcast-message-ordering-is-it-cost-effective/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://www.dobbsprojects.com/media/newengine/dynamp.php/071231ud01.mp3?podcast=071231ud01.mp3" length="0" type="audio/mp3" />
		</item>
		<item>
		<title>Asynchronous, High-Performance Login for Web Farms</title>
		<link>http://www.udidahan.com/2007/11/10/asynchronous-high-performance-login-for-web-farms/</link>
		<comments>http://www.udidahan.com/2007/11/10/asynchronous-high-performance-login-for-web-farms/#comments</comments>
		<pubDate>Sat, 10 Nov 2007 16:08:46 +0000</pubDate>
		<dc:creator>udidahan</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Availability]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[Data Access]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Services]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/11/10/asynchronous-high-performance-login-for-web-farms/</guid>
		<description><![CDATA[Often during my consulting engagements I run into people who say, &#34;some things just can&#8217;t be made asynchronous&#34; even after they agree about the inherent scalability that asynchronous communications pattern bring. One often-cited example is user authentication &#8211; taking a username and password combo and authenticating it against some back-end store. For the purpose of [...]]]></description>
			<content:encoded><![CDATA[<p>Often during my consulting engagements I run into people who say, &quot;some things just can&#8217;t be made asynchronous&quot; even after they agree about the inherent scalability that asynchronous communications pattern bring. One often-cited example is user authentication &#8211; taking a username and password combo and authenticating it against some back-end store. For the purpose of this post, I&#8217;m going to assume a database. Also, I&#8217;m not going to be showing more advanced features like ETags to further improve the solution.</p>
<h3>The Setup</h3>
<p>Just so that the example is in itself secure, we&#8217;ll assume that the password is one-way hashed before being stored. Also, given a reasonable network infrastructure our web servers will be isolated in the <a href="http://en.wikipedia.org/wiki/Demilitarized_zone_(computing)">DMZ</a> and will have to access some application server which, in turn, will communicate with the DB. There&#8217;s also a good chance for something like round-robin load-balancing between web servers, especially for things like user login.</p>
<p>Before diving into the meat of it, I wanted to preface with a few words. One of the commonalities I&#8217;ve found when people dismiss asynchrony is that they don&#8217;t consider a real deployment environment, or scaling up a solution to multiple servers, farms, or datacenters.</p>
<h3>The Synchronous Solution</h3>
<p>In the synchronous solution, each one of our web servers will be contacting the app server for each user login request. In other words, the load on the app server and, consequently, on the database server will be proportional to the number of logins. One property of this load is its data locality, or rather, the lack of it. Given that user U logged in, the DB won&#8217;t necessarily gain any performance benefits by loading all username/password data into memory for the same page as user U. Another property is that this data is very non-volatile &#8211; it doesn&#8217;t change that often.</p>
<p>I won&#8217;t go to far into the synchronous solution since its been <a href="http://www.michaelnygard.com/blog/2007/11/two_ways_to_boost_your_flaggin.html">analysed</a> numerous times before. The bottom line is that the database is the bottleneck. You could use sharding solutions. Many of the large sites have numerous read-only databases for this kind of data, with one master for updates &#8211; replicating out to the read-only replicas. That&#8217;s <a href="http://www.michaelnygard.com/blog/2007/11/two_quick_observations.html">great</a> if you&#8217;re using a nice cheap database like mySql (of LAMP), not so nice if you&#8217;re running Oracle or MS Sql Server.</p>
<p>Regardless of what you&#8217;re doing in your data tier, you&#8217;re there. Wouldn&#8217;t it be nice to close the loop in the web servers? Even if you are using Apache, that&#8217;s going to be less iron, electricity, and cooling all around. That&#8217;s what the asynchronous solution is all about &#8211; capitalizing on the low cost of memory to save on other things.</p>
<h3>The Asynchronous Solution</h3>
<p>In the asynchronous solution, we cache username/hashed-password pairs in memory on our web servers, and authenticate against that. Let&#8217;s analyse how much memory that takes:</p>
<p>Usernames are usually 12 characters or less, but let&#8217;s take an average of 32 to be sure. Using Unicode we get to 64 bytes for the username. Hashed passwords can run between 256 and 512 <em>bits</em> depending on the algorithm, divide by 8 and you have 64 bytes. That&#8217;s about 128 bytes altogether. So we can safely cache 8 million of these with 1GB of memory per web server. If you&#8217;ve got a million users, first of all, good for you <img src='http://www.udidahan.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  Second, that&#8217;s just 128 MB of memory &#8211; relatively nothing even for a cheap 2GB web server. </p>
<p>Also, consider the fact that when registering a new user we can check if such a username is already taken at the web server level. That doesn&#8217;t mean it won&#8217;t be checked again in the DB to account for <a href="http://udidahan.weblogs.us/2007/01/22/realistic-concurrency/">concurrency issues</a>, but that the load on the DB is further reduced. Other things to notice include no read-only replicas and no replication. Simple. Our web servers are the &quot;replicas&quot;.</p>
<h3>The Authentication Service</h3>
<p>What makes it all work is the &quot;Authentication Service&quot; on the app server. This was always there in the synchronous solution. It is what used to field all the login requests from the web servers, and, of course, allowed them to register new users and all the regular stuff. The difference is that now it publishes a message when a new user is registered (or rather, is validated &#8211; all a part of the internal long-running workflow). It also allows subscribers to receive the list of all username/hashed-password pairs. It&#8217;s also quite likely that it would keep the same data in memory too.</p>
<p>The same message can be used to publish both single updates, and returning the full list when using <a href="http://www.NServiceBus.com">NServiceBus</a>. Let&#8217;s define the message:</p>
<div style="border-right: black 1px solid; padding-right: 1em; border-top: black 1px solid; padding-left: 1em; padding-bottom: 0em; overflow: auto; border-left: black 1px solid; padding-top: 0em; border-bottom: black 1px solid; font-family: courier; background-color: beige">
<p>[Serializable]      <br />public class UsernameInUseMessage : IMessage       <br />{       <br />&#160;&#160;&#160; private string username;       <br />&#160;&#160;&#160; public string Username       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return username; }       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { username = value; }       <br />&#160;&#160;&#160; } </p>
</p>
<p>&#160;&#160;&#160; private byte[] hashedPassword;      <br />&#160;&#160;&#160; public byte[] HashedPassword       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return hashedPassword; }       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { hashedPassword = value; }       <br />&#160;&#160;&#160; }       <br />} </p>
</p></div>
<p>And the message that the web server sends when it wants the full list:</p>
</p>
<div style="border-right: black 1px solid; padding-right: 1em; border-top: black 1px solid; padding-left: 1em; padding-bottom: 0em; overflow: auto; border-left: black 1px solid; padding-top: 0em; border-bottom: black 1px solid; font-family: courier; background-color: beige">
<p>[Serializable]      <br />public class GetAllUsernamesMessage : IMessage       <br />{ </p>
<p>} </p>
</p></div>
<p>And the code that the web server runs on startup looks like this (assuming constructor injection):</p>
<p>&#160;</p>
</p>
<div style="border-right: black 1px solid; padding-right: 1em; border-top: black 1px solid; padding-left: 1em; padding-bottom: 0em; overflow: auto; border-left: black 1px solid; padding-top: 0em; border-bottom: black 1px solid; font-family: courier; background-color: beige">
<p>public class UserAuthenticationServiceAgent      <br />{&#160; <br />&#160;&#160;&#160; public UserAuthenticationServiceAgent(IBus bus)&#160; <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.bus = bus;       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; bus.Subscribe(typeof(UsernameInUseMessage));&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; bus.Send(new GetAllUsernamesMessages());       <br />&#160;&#160;&#160; } </p>
<p> }</p></div>
<p>And the code that runs in the Authentication Service when the GetAllUsernamesMessage is received:</p>
</p>
<p>&#160;</p>
</p>
<div style="border-right: black 1px solid; padding-right: 1em; border-top: black 1px solid; padding-left: 1em; padding-bottom: 0em; overflow: auto; border-left: black 1px solid; padding-top: 0em; border-bottom: black 1px solid; font-family: courier; background-color: beige">
<p>public class GetAllUsernamesMessageHandler : BaseMessageHandler&lt;GetAllUsernamesMessage&gt;      <br />{       <br />&#160;&#160;&#160; public override void Handle(GetAllUsernamesMessage message)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.Bus.Reply(Cache.GetAll&lt;UsernameInUseMessage&gt;());       <br />&#160;&#160;&#160; }       <br />}</p>
</p></div>
<p>&#160;</p>
<p>And the class on the web server that handles a UsernameInUseMessage when it arrives:</p>
</p>
<p>&#160;</p>
</p>
<div style="border-right: black 1px solid; padding-right: 1em; border-top: black 1px solid; padding-left: 1em; padding-bottom: 0em; overflow: auto; border-left: black 1px solid; padding-top: 0em; border-bottom: black 1px solid; font-family: courier; background-color: beige">
<p>public class UsernameInUseMessageHandler : BaseMessageHandler&lt;UsernameInUseMessage&gt;      <br />{       <br />&#160;&#160;&#160; public override void Handle(UsernameInUseMessage message)       <br />&#160;&#160;&#160; {&#160; <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; WebCache.SaveOrUpdate(message.Username, message.HashedPassword);&#160; <br />&#160;&#160;&#160; }       <br />}</p>
</p></div>
<p>When the app server sends the full list, multiple objects of the type UsernameInUseMessage are sent in one physical message to that web server. However, the bus object that runs on the web server dispatches each of these logical messages one at a time to the message handler above.</p>
<p>So, when it comes time to actually authenticate a user, this the web page (or controller, if you&#8217;re doing MVC) would call:</p>
</p>
<div style="border-right: black 1px solid; padding-right: 1em; border-top: black 1px solid; padding-left: 1em; padding-bottom: 0em; overflow: auto; border-left: black 1px solid; padding-top: 0em; border-bottom: black 1px solid; font-family: courier; background-color: beige">
<p>public class UserAuthenticationServiceAgent      <br />{       <br />&#160;&#160;&#160; public bool Authenticate(string username, string password)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; byte[] existingHashedPassword = WebCache[username];       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; if (existingHashedPassword != null)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; return existingHashedPassword == this.Hash(password); </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; return false;      <br />&#160;&#160;&#160; }       <br />}</p>
</p></div>
<p>&#160;</p>
<p>When registering a new user, the web server would of course first check its cache, and then send a RegisterUserMessage that contained the username and the hashed password.</p>
</p>
<div style="border-right: black 1px solid; padding-right: 1em; border-top: black 1px solid; padding-left: 1em; padding-bottom: 0em; overflow: auto; border-left: black 1px solid; padding-top: 0em; border-bottom: black 1px solid; font-family: courier; background-color: beige">
<p>[Serializable]      <br />[StartsWorkflow]       <br />public class RegisterUserMessage : IMessage       <br />{       <br />&#160;&#160;&#160; private string username;       <br />&#160;&#160;&#160; public string Username       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return username; }       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { username = value; }       <br />&#160;&#160;&#160; } </p>
</p>
<p>&#160;&#160;&#160; private string email;      <br />&#160;&#160;&#160; public string Email       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return email; }       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { email = value; }       <br />&#160;&#160;&#160; } </p>
</p>
<p>&#160;&#160;&#160; private byte[] hashedPassword;      <br />&#160;&#160;&#160; public byte[] HashedPassword       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; get { return hashedPassword; }       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; set { hashedPassword = value; }       <br />&#160;&#160;&#160; }       <br />} </p>
</p></div>
<p>&#160;</p>
<p>When the RegisterUserMessage arrives at the app server, a new long-running workflow is kicked off to handle the process:</p>
</p>
<div style="border-right: black 1px solid; padding-right: 1em; border-top: black 1px solid; padding-left: 1em; padding-bottom: 0em; overflow: auto; border-left: black 1px solid; padding-top: 0em; border-bottom: black 1px solid; font-family: courier; background-color: beige">
<p>public class RegisterUserWorkflow :      <br />&#160;&#160;&#160; BaseWorkflow&lt;RegisterUserMessage&gt;, IMessageHandler&lt;UserValidatedMessage&gt;       <br />{       <br />&#160;&#160;&#160; public void Handle(RegisterUserMessage message)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; //send validation request to message.Email containing this.Id (a guid)       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // as a part of the URL       <br />&#160;&#160;&#160; } </p>
<p>&#160;&#160;&#160; /// &lt;summary&gt;      <br />&#160;&#160;&#160; /// When a user clicks the validation link in the email, the web server       <br />&#160;&#160;&#160; /// sends this message (containing the workflow Id)       <br />&#160;&#160;&#160; /// &lt;/summary&gt;       <br />&#160;&#160;&#160; /// &lt;param name=&quot;message&quot;&gt;&lt;/param&gt;       <br />&#160;&#160;&#160; public void Handle(UserValidatedMessage message)       <br />&#160;&#160;&#160; {       <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160; // write user to the DB </p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; this.Bus.Publish(new UsernameInUseMessage(      <br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; message.Username, message.HashedPassword));       <br />&#160;&#160;&#160; }       <br />}</p>
</p></div>
<p>That UsernameInUseMessage would eventually arrive at all the web servers subscribed.</p>
<h3>Performance/Security Trade-Offs</h3>
<p>When looking deeper into this workflow we realize that it could be implemented as two separate message handlers, and have the email address take the place of the workflow Id. The problem with this alternate, better performing solution has to do with security. By removing the dependence on the workflow Id, we&#8217;ve in essence stated that we&#8217;re willing to receive a UserValidatedMessage without having previously received the RegisterUserMessage. </p>
<p>Since the processing of the UserValidatedMessage is relatively expensive &#8211; writing to the DB and publishing messages to <em>all</em> web servers, a malicious user could perform a denial of service (<a href="http://en.wikipedia.org/wiki/Denial-of-service_attack">DOS</a>) attack without that many messages, thus flying under the radar of many detection systems. Spoofing a guid that would result in a valid workflow instance is much more difficult. Also, since workflow instances would probably be stored in some in-memory, replicated data grid the relative cost of a lookup would be quite small &#8211; small enough to avoid a DOS until a detection system picked it up.</p>
<h3>Improved Bandwidth &amp; Latency</h3>
<p>The bottom line is that you&#8217;re getting much more out of your web tier this way, rather than hammering your data tier and having to scale it out much sooner. Also, notice that there is much less network traffic this way. Not such a big deal for usernames and passwords, but other scenarios built in the same way may need more data. Of course, the time it takes us to log a user in is much shorter as well since we don&#8217;t have to cross back and forth from the web server (in the DMZ) to the app server, to the db server.</p>
<p>The important thing to remember in this solution is doing pub/sub. NServiceBus merely provides a simple API for designing the system around pub/sub. And publishing is where you get the serious scalability. As you get more users, you&#8217;ll obviously need to get more web servers. The thing is that you probably won&#8217;t need more database servers <em>just to handle logins</em>. In this case, you also get <a href="http://www.michaelnygard.com/blog/2007/11/architecting_for_latency.html">lower latency</a> per request since all work needed to be done can be done locally on the server that received the request. </p>
<h3>ETags make it even better</h3>
<p>For the more advanced crowd, I&#8217;ll wrap it up with the <a href="http://en.wikipedia.org/wiki/HTTP_ETag">ETags</a>. Since web servers do go down, and the cache will be cleared, what we can do is to write that cache to disk (probably in a background thread), and &quot;tag&quot; it with something that the server gave us along with the last UsernameInUseMessage we received. That way, when the web server comes back up, it can send that ETag along with its GetAllUsernamesMessage so that the app server will only send the changes that occurred since. This drives down network usage even more at the insignificant cost of some disk space on the web servers.</p>
<h3>And in closing&#8230;</h3>
<p>Even if you don&#8217;t have anything more than a single physical server today, and it acts as your web server and database server, this solution won&#8217;t slow things down. If anything, it&#8217;ll speed it up. Regardless, you&#8217;re much better prepared to scale out than before &#8211; no need to rip and replace your entire architecture just as you get 8 million Facebook users banging down your front door.</p>
<p>So, go check out <a href="http://www.NServiceBus.com">NServiceBus</a> and get the most out of your iron.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/11/10/asynchronous-high-performance-login-for-web-farms/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Creating Stateful Services with NServiceBus</title>
		<link>http://www.udidahan.com/2007/10/04/creating-stateful-services-with-nservicebus/</link>
		<comments>http://www.udidahan.com/2007/10/04/creating-stateful-services-with-nservicebus/#comments</comments>
		<pubDate>Thu, 04 Oct 2007 23:40:58 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Caching]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/10/04/creating-stateful-services-with-nservicebus/</guid>
		<description><![CDATA[On one of the projects I&#8217;m consulting on they needed some special behavior to handle the following scenario:

Since the service needs to perform all request processing in near-real-time, it caches all data from the DB in memory (yes, that&#8217;s a lot of memory). Since the service needs to handle multiple requests concurrently, we&#8217;re using multiple [...]]]></description>
			<content:encoded><![CDATA[<p>On one of the projects I&#8217;m consulting on they needed some special behavior to handle the following scenario:</p>
<blockquote><p>
Since the service needs to perform all request processing in near-real-time, it caches all data from the DB in memory (yes, that&#8217;s a lot of memory). Since the service needs to handle multiple requests concurrently, we&#8217;re using multiple threads (so far, so good). The problem is that we don&#8217;t want the service to handle messages received until it&#8217;s finished caching everything. Also, we don&#8217;t want that check to show up in every message handler (important when you have lots of message types).
</p></blockquote>
<p>This is actually quite easy to do with <a href="http://www.NServiceBus.com">NServiceBus</a>. Here&#8217;s how:</p>
<p>Have a thread-safe class, let&#8217;s call it Loader, for the API to the caching. Something along the lines of:</p>
<p>If (!Loader.HasCachedEverything)<br />
&nbsp;&nbsp;Loader.CacheEverything();</p>
<p>Obviously, the Loader will have internal logic for checking if it has already started loading things from the DB, so that it won&#8217;t do the same thing twice. </p>
<p>OK, now on to the interesting stuff.</p>
<p>We&#8217;d like to have the above code run no matter which kind of message we&#8217;ve received, so we just write a &#8220;generic&#8221; message handler &#8211; which handles &#8220;IMessage&#8221; like so:</p>
<div style="border: solid black 1px; background-color:beige; padding: 0em 1em; overflow:auto; width:550; font-family:courier">
public class CachingMessageHandler : BaseMessageHandler&lt;IMessage&gt;<br />
{<br />
&nbsp;&nbsp;public void Handle(IMessage message)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;If (!Loader.HasCachedEverything)<br />
&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Loader.CacheEverything();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.bus.HandleCurrentMessageLater();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;this.CanContinue = false;<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;}<br />
}
</div>
<p>When the message handler calls &#8220;HandleCurrentMessageLater&#8221;, the bus puts the current message in the back of the queue. If you&#8217;ve configured a transactional transport, this will be safe even in the case of a server restart.</p>
<p>Also, notice the &#8220;CanContinue = false&#8221;. This tells the bus that the message should not be passed on to any other message handlers, even if there are those that are configured to handle it.</p>
<p>We&#8217;ll also package this class up by itself, keeping it separate from the core logic of the service &#8211; making it easier to version these cross cutting concerns and the service logic. Let&#8217;s put it in &#8220;CrossCuttingConcerns.dll&#8221;</p>
<p>The final thing needed in order to achieve the behavior described above is to configure this message handler to run before any other handler. This is done in the config file of the process, under the &#8220;bus&#8221; object, in the &#8220;MessageHandlerAssemblies&#8221; property like so:</p>
<pre>
        &lt;property name="MessageHandlerAssemblies"&gt;
          &lt;list&gt;
            &lt;value&gt;CrossCuttingConcerns&lt;/value&gt;
            &lt;value>ServiceLogic&lt;/value&gt;
          &lt;/list&gt;
        &lt;/property&gt;
</pre>
<p>This is similar to the way HttpHandlers are (were?) configured in IIS &#8211; the order of the handlers defines the order in which the bus dispatches messages to them.</p>
<p>And that&#8217;s it.</p>
<p>We&#8217;re done.</p>
<p>If you have any questions you&#8217;d like to ask about NServiceBus, please feel free to send them my way: <a href="mailto:Questions@NServiceBus.com">Questions@NServiceBus.com</a>.</p>
<p>And just in closing I&#8217;d like to say that I don&#8217;t necessarily think you should be creating stateful services, but that there&#8217;s a time and place for everything.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/10/04/creating-stateful-services-with-nservicebus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Podcast] Shared subscriptions between autonomous components</title>
		<link>http://www.udidahan.com/2007/09/09/podcast-shared-subscriptions-between-autonomous-components/</link>
		<comments>http://www.udidahan.com/2007/09/09/podcast-shared-subscriptions-between-autonomous-components/#comments</comments>
		<pubDate>Mon, 10 Sep 2007 05:30:15 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Ask Udi Podcast]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/09/09/podcast-shared-subscriptions-between-autonomous-components/</guid>
		<description><![CDATA[This week we&#8217;re discussing scenarios involving the use of multiple autonomous components handling the same event. We also get into the topics of component hosting as well as solution development structure.
Our long-time listener Bill asks the following:

Hi Udi,
Thank you for your podcast clarifying the concept of autonomous components.  It certainly cleared up a lot [...]]]></description>
			<content:encoded><![CDATA[<p>This week we&#8217;re discussing scenarios involving the use of multiple autonomous components handling the same event. We also get into the topics of component hosting as well as solution development structure.</p>
<p>Our long-time listener Bill asks the following:</p>
<blockquote><p>
Hi Udi,</p>
<p>Thank you for your podcast clarifying the concept of autonomous components.  It certainly cleared up a lot in terms of how you define an autonomous component and helped position the concept better in my mind.</p>
<p>I am considering building our Policy Administration service with 3 autonomous components as you previously suggested &#8211; one for each insurance product family.  As you previously mentioned, these autonomous components could either share a database instance or have separate database instances, even though they may share schema (being a part of the same service).</p>
<p>What concerns me however is that there is some data that must be shared between these autonomous components.  A perfect example is Region.  If a new Region is defined somewhere in the enterprise, a RegionCreatedNotification is published onto the bus.  If I have 3 autonomous components sharing the same database, is it best I just choose one to be the subscriber for this event?  Or should I create a new separate queue to receive these notifications and put a message handler for it in a separate MessageHandlers assembly?  Or should I subscribe all 3 autonomous components and have them each check if the Region has already been created in the database before inserting a new one?</p>
<p>Option (1) seems presumptuous because it assumes all 3 autonomous components are sharing the same database.  Option (2) seems a bit strange because it is like creating a 4th autonomous component only to receive the RegionCreatedNotification messages.  And Option (3) seems wasteful since there is redundant code and the system is doing extra unnecessary lookups.  At the moment it looks like Option (2) is my best bet, but I&#8217;m very interested to get your take on it.</p>
<p>Another question is whether you would say that autonomous components should be hosted in different processes.  Since I don&#8217;t need to run these autonomous components on separate servers at this stage, it would seem wasteful to create a service host for each component.  I could always create separate service hosts at a later time if I needed to host one or more autonomous components on other servers.</p>
<p>And the final question I have is in terms of solution structure.  I was contemplating the following structure:</p>
<p>ProductFamily1<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Company.PolicyAdministration.ProductFamily1.Domain<br />
Company.PolicyAdministration.ProductFamily1.MessageHandlers<br />
Company.PolicyAdministration.ProductFamily1.Messages<br />
Company.PolicyAdministration.ProductFamily1.Persistence<br />
Company.PolicyAdministration.ProductFamily1.Persistence.Implementation<br />
Company.PolicyAdministration.ProductFamily1.Etc&#8230;</p>
<p>ProductFamily2<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Company.PolicyAdministration.ProductFamily2.Domain<br />
Company.PolicyAdministration.ProductFamily2.MessageHandlers<br />
Company.PolicyAdministration.ProductFamily2.Messages<br />
Company.PolicyAdministration.ProductFamily2.Persistence<br />
Company.PolicyAdministration.ProductFamily2.Persistence.Implementation<br />
Company.PolicyAdministration.ProductFamily2.Etc&#8230;</p>
<p>ProductFamily3<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Company.PolicyAdministration.ProductFamily3.Domain<br />
Company.PolicyAdministration.ProductFamily3.MessageHandlers<br />
Company.PolicyAdministration.ProductFamily3.Messages<br />
Company.PolicyAdministration.ProductFamily3.Persistence<br />
Company.PolicyAdministration.ProductFamily3.Persistence.Implementation<br />
Company.PolicyAdministration.ProductFamily3.Etc&#8230;</p>
<p>Common<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
Company.PolicyAdministration.Common.Domain<br />
Company.PolicyAdministration.Common.Persistence<br />
Company.PolicyAdministration.Common.Messages<br />
Company.PolicyAdministration.Common.ServiceHost<br />
Company.PolicyAdministration.Common.Etc&#8230;</p>
<p>Do you have any thoughts on the above structure?</p>
<p>Once again thank you very much for your extremely valuable advice!</p>
<p>Best Regards,<br />
Bill
</p></blockquote>
<p><a href="http://www.ddj.com/architect/201804009">Download via the Dr. Dobbs&#8217; site.</a></p>
<p>Or download directly <a href="http://www.dobbsprojects.com/media/newengine/dynamp.php/070904ud01.mp3?podcast=070904ud01.mp3">here</a>.</p>
<p><u>Additional References:</u></p>
<ul>
<li><a href="http://udidahan.weblogs.us/2007/06/02/podcast-using-autonomous-components-for-slas-in-soa/">Ask Udi Podcast #017 &#8211; Using Autonomous Components for SLAs in SOA</a></li>
<li><a href="http://udidahan.weblogs.us/2007/04/18/podcast-how-to-structure-net-solutions-and-components/">Ask Udi Podcast #020 &#8211; How to structure .NET solutions and components</a></li>
</ul>
<p><b>Want More?</b></p>
<p>Check out the <a href="/ask-udi/">“Ask Udi” archives</a>.</p>
<p><b>Got a question?</b></p>
<p>Send Udi your question and have him answer it on the show: <a href="mailto:podcast@UdiDahan.com">podcast@UdiDahan.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/09/09/podcast-shared-subscriptions-between-autonomous-components/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
<enclosure url="http://www.dobbsprojects.com/media/newengine/dynamp.php/070904ud01.mp3?podcast=070904ud01.mp3" length="14630852" type="audio/mp3" />
		</item>
		<item>
		<title>On rising data volumes</title>
		<link>http://www.udidahan.com/2007/08/20/on-rising-data-volumes/</link>
		<comments>http://www.udidahan.com/2007/08/20/on-rising-data-volumes/#comments</comments>
		<pubDate>Mon, 20 Aug 2007 07:40:47 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[NServiceBus]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[Space-Based Architecture]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/08/20/on-rising-data-volumes/</guid>
		<description><![CDATA[Larry&#8217;s post Data Volumes Trumping Core Multiplication? Interesting Thought raises some interesting questions as to what will have a larger impact on the way we use program computers &#8211; rising data volumes or more cores:

It seems to me that nowadays we work more and more with data streams and not data sets. On a transaction-to-transaction [...]]]></description>
			<content:encoded><![CDATA[<p>Larry&#8217;s post <a href="http://www.knowing.net/PermaLink,guid,7075ce1b-fa59-4bca-926f-79fb45f9670e.aspx">Data Volumes Trumping Core Multiplication? Interesting Thought</a> raises some interesting questions as to what will have a larger impact on the way we use program computers &#8211; rising data volumes or more cores:</p>
<blockquote><p>
It seems to me that nowadays we work more and more with data streams and not data sets. On a transaction-to-transaction basis, I think it&#8217;s an uncommon application that uses more data than can fit into several gigabytes of RAM (obvious exception: multimedia data).
</p></blockquote>
<p>While data stream processing is the heartbeat of many verticals, I&#8217;m seeing another trend there as well &#8211; the use of historical data as a part of that data stream processing. Some people have begun calling this Complex Event-Stream Processing (CEP), and the analysts are already beginning to eat it up. Regardless, the problem is that it is difficult to hold all historical data in memory so that when events arrive we can process them quickly.</p>
<p>So, my bottom line is that we&#8217;re being hit on multiple fronts &#8211; both the rate at which we need to process events and the amount of data required to process each event. Multiple cores help a bit, but probably not enough to discount scaling up to more machines. All this at the end of the day points out that we should not treat multiple cores any differently than multiple machines.</p>
<p>So, we either need languages to handle this (<a href="http://www.erlang.org/">Erlang</a> for one) or possibly frameworks (<a href="http://www.NServiceBus.com">NServiceBus</a> is my contribution). All I know is that Layered (Tiered) Architectures won&#8217;t cut it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/08/20/on-rising-data-volumes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t EDA between existing systems</title>
		<link>http://www.udidahan.com/2007/08/16/dont-eda-between-existing-systems/</link>
		<comments>http://www.udidahan.com/2007/08/16/dont-eda-between-existing-systems/#comments</comments>
		<pubDate>Thu, 16 Aug 2007 12:54:21 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[BPM]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Simplicity]]></category>
		<category><![CDATA[Workflow]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/08/16/dont-eda-between-existing-systems/</guid>
		<description><![CDATA[In Nick Malik&#8217;s great post, EDA: Avoiding coupling on the name he describes additional &#8220;handshakes&#8221; to be used to avoid the following problems:

Let&#8217;s say I have a system to handle a call center for financial services or telco.  When a customer calls on the phone and asks to be enrolled in &#8220;Heavily Advertised Program [...]]]></description>
			<content:encoded><![CDATA[<p>In Nick Malik&#8217;s great post, <a href="http://blogs.msdn.com/nickmalik/archive/2007/08/12/eda-avoiding-coupling-on-the-name.aspx">EDA: Avoiding coupling on the name</a> he describes additional &#8220;handshakes&#8221; to be used to avoid the following problems:</p>
<blockquote><p>
Let&#8217;s say I have a system to handle a call center for financial services or telco.  When a customer calls on the phone and asks to be enrolled in &#8220;Heavily Advertised Program ABC,&#8221; there may need to be three or four systems that interact to make that real.</p>
<p>&#8230;</p>
<p>Harry asks me to consider using a &#8216;logical name&#8217; of the receiver.  The sender contacts a logical end point, the addressing infrastructure turns that into a physical end point, and we still have decoupling.  </p>
<p>Honestly, I like it but I think it is insufficient.  What if we need to contact 20 downstream systems in a complex workflow, but I don&#8217;t want a single &#8220;orchestration coordinator&#8221; to be a bottleneck (or single point of failure).  I don&#8217;t want to hand the orchestration off from my app to a central orchestration hub.
</p></blockquote>
<p>Let me propose a different approach.</p>
<p>When we use SOA/EDA (the same thing as far as I&#8217;m concerned), the top-level building block used is the Service. A service may make use of a number of existing systems to perform its work. The business-level events that we publish (and subscribe to) are done by the service, not the existing systems.</p>
<p>If there&#8217;s any orchestration/workflow that needs to be done as a result of a service receiving an event, it is done entirely internal to that service. Inter-service orchestrations don&#8217;t really exist, as in there is no orchestration coordinator that is not in a service. And the orchestration coordinators within a service don&#8217;t touch other services&#8217; back-end systems &#8211; if anything, they publish other business level events.</p>
<p>Be aware: when just starting out on an SOA, you&#8217;ll find that multiple Services make use of the same backend systems. This may be necessary, but not a desirable state to stay in for too long since it embodies the most insidious and invisible kind of inter-service coupling there is.</p>
<p>I want to go back to Nick&#8217;s original question:</p>
<blockquote><p>So what if no one picks the message up?  Is that an error? </p></blockquote>
<p>The answer is mu.</p>
<p>If a service publishes a business-event (message) and no other services currently care, that&#8217;s fine. It&#8217;s not an error. Actually, you&#8217;d probably have some kind of infrastructure &#8220;queue&#8221; where messages that haven&#8217;t been received more than X time get sent to, so that the event isn&#8217;t &#8220;lost&#8221;. On the other hand, within a service &#8211; if an existing system sends out a message that <i>needs</i> to arrive at another system, and that message doesn&#8217;t arrive or isn&#8217;t picked up &#8220;in time&#8221;, that is an error.</p>
<p>This is one of the advantages SOA brings to the table in terms of EDA (again, the same as far as I&#8217;m concerned). You get simple messaging semantics between services, while within the &#8220;sphere of control&#8221; of a service you need, and more importantly can do more complex messaging and orchestration.</p>
<p>Bottom line: you need higher abstractions than your existing systems to employ EDA effectively.</p>
<p>You might also want to check out my podcast on this topic: <a href="http://udidahan.weblogs.us/2006/06/13/podcast-soa-esb-and-events-no-20/">SOA, ESB, and Events</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/08/16/dont-eda-between-existing-systems/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Podcast] Can We Do Away with Services and Just Leave the Messaging?</title>
		<link>http://www.udidahan.com/2007/08/11/podcast-can-we-do-away-with-services-and-just-leave-the-messaging/</link>
		<comments>http://www.udidahan.com/2007/08/11/podcast-can-we-do-away-with-services-and-just-leave-the-messaging/#comments</comments>
		<pubDate>Sat, 11 Aug 2007 09:18:38 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Ask Udi Podcast]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/08/11/podcast-can-we-do-away-with-services-and-just-leave-the-messaging/</guid>
		<description><![CDATA[This week we have a comment from a fellow SOA blogger, Jack van Hoof:

ESB&#8217;s are a lot about messaging and therefore a better name might be &#8220;Enterprise Data Bus&#8221;. It&#8217;s the asynchronous messaging that needs such an infrastructure with persistency and mediation facilities. All the WS-* standards are about messaging as well, leveraging the message [...]]]></description>
			<content:encoded><![CDATA[<p>This week we have a comment from a fellow SOA blogger, <a href="http://soa-eda.blogspot.com">Jack van Hoof</a>:</p>
<blockquote><p>
ESB&#8217;s are a lot about messaging and therefore a better name might be &#8220;Enterprise Data Bus&#8221;. It&#8217;s the asynchronous messaging that needs such an infrastructure with persistency and mediation facilities. All the WS-* standards are about messaging as well, leveraging the message itself to tell the infrastructure how it has to be handled. </p>
<p>I think WS-* will make it possible to have the ESB evolve from a vendor-product to a concept implemented in the operating systems an network devices that understand WS-*. Then you can leave the prefix &#8220;Enterprise&#8221; and we will be ready for an univeral asynchronous data bus over the Internet (or any other network you like). This will help breaking the current &#8220;services centric&#8221; idea of SOA into a &#8220;messages centric&#8221; perspective.</p>
<p>What are your thoughts?
</p></blockquote>
<p><a href="http://www.ddj.com/web-development/201306152">Download via the Dr. Dobb&#8217;s site</a></p>
<p>Or download directly <a href="http://www.dobbsprojects.com/media/newengine/dynamp.php/070808ud01.mp3?podcast=070808ud01.mp3">here</a>.</p>
<p><u>Additional References:</u></p>
<ul>
<li><a href="http://udidahan.weblogs.us/2006/06/02/podcast-does-an-soa-require-an-esb/">Podcast on if you need an ESB for SOA</a></li>
<li><a href="http://udidahan.weblogs.us/2007/03/29/podcast-enterprise-service-discovery/">Podcast on Enterprise Service Discovery</a></li>
<li><a href="http://soa-eda.blogspot.com/2006/11/esb-as-global-dataspace.html">Blog post on ESBs as a global dataspace</a></li>
<li><a href="http://soa-eda.blogspot.com/2006/06/brave-new-world-with-ws.html">Blog post about what the brave new world of WS-* brings us</a></li>
</ul>
<p><b>Want more?</b> Check out the <a href="/ask-udi/">&#8220;Ask Udi&#8221; archives</a>.</p>
<p><b>Got a question?</b> Have Udi answer it on the podcast &#8211; <a href="mailto:podcast@UdiDahan.com">podcast@UdiDahan.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/08/11/podcast-can-we-do-away-with-services-and-just-leave-the-messaging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.dobbsprojects.com/media/newengine/dynamp.php/070808ud01.mp3?podcast=070808ud01.mp3" length="13990964" type="audio/mp3" />
		</item>
		<item>
		<title>[Podcast] Using WCF for Entity and Activity Services to Implement Business Services</title>
		<link>http://www.udidahan.com/2007/07/17/podcast-using-wcf-for-entity-and-activity-services-to-implement-business-services/</link>
		<comments>http://www.udidahan.com/2007/07/17/podcast-using-wcf-for-entity-and-activity-services-to-implement-business-services/#comments</comments>
		<pubDate>Tue, 17 Jul 2007 14:00:08 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Ask Udi Podcast]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[WCF]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/07/17/podcast-using-wcf-for-entity-and-activity-services-to-implement-business-services/</guid>
		<description><![CDATA[This week we return to the topic of Entity, Activity, and Process services and compares their usages as top-level SOA elements and as implementation details of the application architecture inside a business service.
And the question that this answers is:

Hi Udi,
We&#8217;ve been having some discussions about how to implement our latest project using SOA and this [...]]]></description>
			<content:encoded><![CDATA[<p>This week we return to the topic of Entity, Activity, and Process services and compares their usages as top-level SOA elements and as implementation details of the application architecture inside a business service.</p>
<p>And the question that this answers is:</p>
<blockquote><p>
Hi Udi,</p>
<p>We&#8217;ve been having some discussions about how to implement our latest project using SOA and this is what we came up with: </p>
<p>Every activity is a method, which is broken into a class ( Think separation of concerns ), so we get high reusability.<br />
On top of those classes we have decided to put a WCF layer, so you can expose the method as a web method. If an activity needs data, then it will access a entity service via WCF. To make the activities useful for the business we put them in a class which we have called processes ( a process layer). A process contains one or more activities and is able to call other processes and activities aren&#8217;t allowed to call processes or other activities.  On top of each process we have decided to put a WCF so the UI can access them. </p>
<p>So it&#8217;s pretty close to what you wrote about in the Microsoft Architecture Journal except that we don&#8217;t have direct call to the entity services, we wrap it up in an activity before the call, which is wrapped in a WCF-host. Much like the definitions in Ontology and Taxonomy of Services in a Service-Oriented Architecture</p>
<p>I would love to hear your comments and thoughts about this architecture. </p>
<p>With thanks, Ingo
</p></blockquote>
<p><a href="http://www.ddj.com/dept/webservices/201001690">Download via the Dr. Dobbs&#8217; site</a>.</p>
<p>Or download directly <a href="http://www.dobbsprojects.com/media/newengine/dynamp.php/070716ud01.mp3?podcast=070716ud01.mp3">here</a>.</p>
<p><u>Additional References:</u></p>
<ul>
<li><a href="http://msdn2.microsoft.com/en-us/arcjournal/bb491121.aspx">Ontology and Taxonomy of Services in a Service-Oriented Architecture</a></li>
<li><a href="http://udidahan.weblogs.us/2007/02/20/autonomous-services-and-enterprise-entity-aggregation/">Udi&#8217;s Architecture Journal article on Autonomous Services<br />
</a></li>
<li><a href="http://udidahan.weblogs.us/2007/04/18/podcast-how-to-structure-net-solutions-and-components/">Podcast on how to structure .NET solutions and components</a></li>
<li><a href="http://udidahan.weblogs.us/2007/06/08/entity-services-rollup/">Blog post covering a discussion on Entity Services</a></li>
</ul>
<p><b>Want More?</b></p>
<p>Check out the <a href="/ask-udi/">&#8220;Ask Udi&#8221; archives</a>.</p>
<p><b>Got a question?</b></p>
<p>Send Udi your question and have him answer it on the show: <a href="mailto:podcast@UdiDahan.com">podcast@UdiDahan.com</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/07/17/podcast-using-wcf-for-entity-and-activity-services-to-implement-business-services/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://www.dobbsprojects.com/media/newengine/dynamp.php/070716ud01.mp3?podcast=070716ud01.mp3" length="10951162" type="audio/mp3" />
		</item>
		<item>
		<title>No such thing as a centralized ESB</title>
		<link>http://www.udidahan.com/2007/06/30/no-such-thing-as-a-centralized-esb/</link>
		<comments>http://www.udidahan.com/2007/06/30/no-such-thing-as-a-centralized-esb/#comments</comments>
		<pubDate>Sat, 30 Jun 2007 13:09:55 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Availability]]></category>
		<category><![CDATA[BizTalk]]></category>
		<category><![CDATA[EDA]]></category>
		<category><![CDATA[ESB]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[REST]]></category>
		<category><![CDATA[SCA & SDO]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Scalability]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/30/no-such-thing-as-a-centralized-esb/</guid>
		<description><![CDATA[Via David McGhee&#8217;s Q&#038;A with Dr. Don Ferguson, but read the whole thing.

Q: Could you tell you your thoughts or preference for a distributed or centralized ESB? 
DON: there is no such thing as a centralized ESB.

This is the problem with a lot of the products that call themselves ESBs. They are centralized brokers which [...]]]></description>
			<content:encoded><![CDATA[<p>Via <a href="http://blogs.msdn.com/davidmcg/archive/2007/06/28/soa-esb-integration-in-the-real-world.aspx">David McGhee&#8217;s Q&#038;A</a> with <a href="http://www.microsoft.com/presspass/exec/techfellow/Ferguson/default.mspx">Dr. Don Ferguson</a>, but read the whole thing.</p>
<blockquote><p>
Q: Could you tell you your thoughts or preference for a distributed or centralized ESB? </p>
<p>DON: there is no such thing as a centralized ESB.
</p></blockquote>
<p>This is the problem with a lot of the products that call themselves ESBs. They are centralized brokers which may be clustered for availability. But they are in no way an implementation of the Bus Architectural Pattern. Please check this before cutting a check to your vendor.</p>
<p>Also, understand that if you do security related things in your ESB, possibly as a part of your routing rules, that if the security infrastructure is centralized that means your ESB is too. Even if it really was distributed to begin with.</p>
<p>Buyer beware.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/06/30/no-such-thing-as-a-centralized-esb/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[Podcast] Asynch Communication and the User Experience</title>
		<link>http://www.udidahan.com/2007/06/21/podcast-asynch-communication-and-the-user-experience/</link>
		<comments>http://www.udidahan.com/2007/06/21/podcast-asynch-communication-and-the-user-experience/#comments</comments>
		<pubDate>Thu, 21 Jun 2007 19:40:29 +0000</pubDate>
		<dc:creator>thesoftwaresimplist</dc:creator>
				<category><![CDATA[Ask Udi Podcast]]></category>
		<category><![CDATA[Autonomous Services]]></category>
		<category><![CDATA[Pub/Sub]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[Web Services]]></category>

		<guid isPermaLink="false">http://udidahan.weblogs.us/2007/06/21/podcast-asynch-communication-and-the-user-experience/</guid>
		<description><![CDATA[In this podcast we answer questions about how web presentation layers can communicate asynchronously with services, Service Level Agreements with respect to asynchronous user interaction, and if using compiled DLLs for message schemas creates tight coupling.
Download via the Dr. Dobbs&#8217; site
Or download directly here.
And here&#8217;s the original question:

Hi Udi,
I thought I&#8217;d ask a question about [...]]]></description>
			<content:encoded><![CDATA[<p>In this podcast we answer questions about how web presentation layers can communicate asynchronously with services, Service Level Agreements with respect to asynchronous user interaction, and if using compiled DLLs for message schemas creates tight coupling.</p>
<p><a href="http://ddj.com/dept/webservices/199601132">Download via the Dr. Dobbs&#8217; site</a></p>
<p>Or download directly <a href="http://www.dobbsprojects.com/media/newengine/dynamp.php/070515ud01.mp3?podcast=070515ud01.mp3">here</a>.</p>
<p>And here&#8217;s the original question:</p>
<blockquote><p>
Hi Udi,</p>
<p>I thought I&#8217;d ask a question about an implementation that seems to be bouncing off my head. We have been thinking about services that can, at the business owners discretion based on SLA expectations, be synchronous, async but within a &#8220;human&#8221; timeframe ie, the gui could still wait and just fail gracefully if the response took too long, or async where the client must check back later. </p>
<p>Client abc is using application xyz and sends a message via the bus to do something. Logically, client abc is waiting for a response even though application xyz sent it asynchronously. Client abc may wait with the gui in front of them, with a progress bar running or a little ajaxy polling widget. They may wait for an email or an message on their web site for long running operations. How would you arrange that the response to this particular message would get routed to only client abc? If the answer is you shouldn&#8217;t think that way, then what would a subscriber to that message type, as shown in your example, do with the client abc&#8217;s response? Imagine a password reset example where the result is a temporary password but the service consults or updates multiple systems as a result of the request.</p>
<p>You also use a shared message type library. As we have been studying WCF, we have focused mostly on the features that would help us allow service consumers and suppliers move independently. We have been looking at message versioning and loose coupling techniques. We have settled on the idea that a shared message library would make our message too brittle, once again forcing each consumer to sync up with each service update. What is your take on that?</p>
<p>Philip
</p></blockquote>
<p><u>Additional Resources</u></p>
<ul>
<li><a href="http://www.joelonsoftware.com/items/2007/01/26.html">Joel Spolsky&#8217;s posts about how they do asynchronous callbacks over the Web</a></li>
<li><a href="http://labs.biztalk.net/">Microsoft Biztalk Internet Service Bus for asynchronous callbacks over the Web</a></li>
<li><a href="http://udidahan.weblogs.us/2007/03/23/podcast-autonomy-loose-coupling-chicken-egg/">Podcast on loose coupling</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.udidahan.com/2007/06/21/podcast-asynch-communication-and-the-user-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
