<?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>Tayyab Bin Tariq &#187; Workflow Foundation</title>
	<atom:link href="http://tayyab.xenoglaux-solutions.com/category/microsoft-technologies/workflow-foundation/feed/" rel="self" type="application/rss+xml" />
	<link>http://tayyab.xenoglaux-solutions.com</link>
	<description>I like sharing what i know</description>
	<lastBuildDate>Fri, 21 May 2010 20:59:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Writing Unified Scalable Application Logic: Windows Workflow Foundation</title>
		<link>http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/</link>
		<comments>http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/#comments</comments>
		<pubDate>Sat, 23 May 2009 19:55:31 +0000</pubDate>
		<dc:creator>tayyabtariq</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Workflow Foundation]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Scalable Application Logic]]></category>
		<category><![CDATA[Scalable Applications]]></category>
		<category><![CDATA[Unified Application Logic]]></category>
		<category><![CDATA[Unified Logic]]></category>
		<category><![CDATA[Unified Scalable]]></category>
		<category><![CDATA[Visual Studio.NET]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Windows Workflow Foundation]]></category>

		<guid isPermaLink="false">http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/</guid>
		<description><![CDATA[Everyone who writes applications or creates software wants to create scalable and easy to understand solutions. The problem however is that simple software is not scalable and scalable applications can get too hard to understand because of their distributed logic development. 
 
A simple application may be implemented as shown in the following figure.
 
Figure [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone who writes applications or creates software wants to create scalable and easy to understand solutions. The problem however is that simple software is not scalable and scalable applications can get too hard to understand because of their distributed logic development. </p>
<p> <span id="more-99"></span>
<p>A simple application may be implemented as shown in the following figure.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image3.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="363" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb3.png" width="644" border="0" /></a> </p>
<p><strong>Figure 1: Simple unified logic that runs in a single process and thread (Courtesy MSDN).</strong></p>
<p>The above pseudo-code takes input from the client and based on the input executed different paths. Note that the input is taken at different points in the code. The state of the application/process is represented here by a simple string. Although this application development style is simple and easy to understand, it is not scalable. Imagine you are using such application logic for a hiring process where the inputs can come after days and even weeks. Your server would have to keep the process alive and running for this whole period. Imagine how much resources it would take to cater for thousands of users. What if the server fails during this period?</p>
<p>Considering these problems, lets look at another solution. This time round we separate the application logic at the freezing points (the input). Breaking the application logic allows the application to run as two different threads. This can solve a few of the problems described above.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image4.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="368" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb4.png" width="644" border="0" /></a> </p>
<p><strong>Figure 2: Breaking the application logic (Courtesy MSDN).</strong></p>
<p>Note that this time round the state is stored outside of the process in a database. The reason is that whenever the second process starts it needs to get the current state from some “persistent” store. Also note that the two application parts can now run on two different machines. Can you see a problem with this? The problem comes from the fact that it is hard for the second process to know whether the if was executed in the first part or the else (of course you would have to make this a part of the state). The point here is that the state becomes complex and we have to introduce a number of checks in the second part of the application. </p>
<p>The first figure is how our usual desktop applications run. they have their state stored in some memory variables that vanish as soon as the application ends. The applications which remember what you did last time have to save this state in some persistent storage. The second example is how ASP.NET applications work. The application logic is implemented in a distributed manner (on different pages). This not only makes it difficult for people to understand the process but also the programmer has to perform a series of checks whenever a page loads. It is also to be noted that the first type provides us unified logic whereas the second provides us scalability. </p>
<h2>The Solution</h2>
<p>Using windows workflows can help us solve these problems. WF function just as a normal program providing mechanism for input, output, control flow etc. However, all these are done with the help of activities, see diagram below.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image5.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb5.png" width="552" border="0" /></a> </p>
<p><strong>Figure 3: In a workflow all the things are done with the help of activities (Courtesy MSDN)</strong></p>
<p>As you can probably already see that unified logic is provided by workflows, let us see how WF solve the problem of scalability. All the work in the WF is done using activates, and as seen the WF provides all the elements of a usual programming language. The difference however is that all these activities are classes themselves, and they are executed on a WF Runtime which knows how to run these classes (activities).</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image6.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb6.png" width="545" border="0" /></a> </p>
<p><strong>Figure 3: WF Runtime executes activities in order (Courtesy MSDN).</strong></p>
<p>When it begins the workflow runtime executes the outer most activity first, which in this case is a sequential workflow. Then it executes the activities one after the other in order determined by the workflow. One thing to note here is that the activities are objects, and therefore can be described in any language, making the workflow independent of the language. Also that the WF Runtime does not know anything about the internals of the activity it is executing, allow the programmer to fill in what is to be done. WF provides a Base Activity Library (BAL) from which you can pick activities to include in your workflow. You can also create activates of your own, called custom activities. </p>
<p>The big question arises, why go through all this pain? The first answer to this question has already been answered, it provides unified logic. However, to be scalable the server application cannot be stuck with one process. One solution to this is the ASP.NET way, i.a. to break the application logic down into small chunks, however this is something we are trying to avoid. Moreover, the programmer than has to explicitly deal with state. As you can probably notice this WF is already broken down into chunks, this allows the WF to persist (not block waiting for an event). When at the start of our example workflow, the workflow is waiting for input the WF Runtime realizes this and stores the state of the WF in a persistent storage (we say the WF persists). This allows for the server resources to be used elsewhere. When the input arrives the WF Runtime wakes up the WF.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image7.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="452" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb7.png" width="644" border="0" /></a> <strong>Figure 5: The workflow can persist (Courtesy MSDN).</strong></p>
<p>Another advantage of the workflow being broken down from the perspective of scalability is the ability of the WF to be run on different machines when it resumes, as shown in the following diagram.</p>
<p>&#160;<a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image8.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="434" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb8.png" width="644" border="0" /></a> </p>
<p><strong>Figure 6 Different parts of a workflow can run on different machines</strong></p>
<h3>Other Benefits</h3>
<p>Other benefits of using windows workflows include the following</p>
<h4>Coordinating Parallel Work</h4>
<p>The WF allows you to coordinate parallel work in a better way by using the parallel activity which is part of BAL (More on this in later articles).</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image9.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="482" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb9.png" width="644" border="0" /></a> </p>
<p><strong>Figure 7 Workflows can run parallel activates (Courtesy MSDN).</strong></p>
<h4>Providing Tracking</h4>
<p>Tracking processes is an important part of any business application. WF makes it extremely easy to do this by providing tracking services. The tracking services are extremely closely linked to persistence (state maintenance) because the state of the WF has all the information one needs for tracking a WF.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image10.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb10.png" width="577" border="0" /></a>&#160; </p>
<p><strong>Figure 8 You can track the WF using tracking services (Courtesy MSDN).</strong></p>
<h4>Creating custom activities</h4>
<p>WF allows you to create custom activities that you can re use as is suited to your business application, allowing to use OO concepts in WF.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image11.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="484" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb11.png" width="250" border="0" /></a> </p>
<p><strong>Figure 9 You can create custom activities (Courtesy MSDN).</strong></p>
<h4>Fully Declarative Language</h4>
<p>WFs are fully declarative as each workflow is represented by a corresponding XAML file.</p>
<p><a href="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image12.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="475" alt="image" src="http://tayyab.xenoglaux-solutions.com/wp-content/uploads/2009/05/image-thumb12.png" width="582" border="0" /></a> </p>
<p><strong>Figure 10 WFs are fully declarative (Courtesy MSDN).</strong></p>
<p>&#160;</p>
<h4>Related articles</h4>
<p><a title="http://msdn.microsoft.com/en-us/library/dd851337.aspx" href="http://msdn.microsoft.com/en-us/library/dd851337.aspx">http://msdn.microsoft.com/en-us/library/dd851337.aspx</a></p>
<p class="facebook"><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/" target="_blank"><img src="http://tayyab.xenoglaux-solutions.com/wp-content/plugins/add-to-facebook-plugin/facebook_share_icon.gif" alt="Share on Facebook" title="Share on Facebook" /></a><a href="http://www.facebook.com/share.php?u=http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/" target="_blank" title="Share on Facebook">Share on Facebook</a></p>]]></content:encoded>
			<wfw:commentRss>http://tayyab.xenoglaux-solutions.com/2009/05/24/writing-unified-scalable-application-logic-windows-workflow-foundation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

