<?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>Gridshore &#187; Architecture</title>
	<atom:link href="http://www.gridshore.nl/tag/architecture/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gridshore.nl</link>
	<description>A weblog about software engineering, Architecture, Technology an other things we like.</description>
	<lastBuildDate>Tue, 13 Dec 2011 15:36:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Axon Framework 0.6 released</title>
		<link>http://www.gridshore.nl/2010/08/08/axon-framework-0-6-released/</link>
		<comments>http://www.gridshore.nl/2010/08/08/axon-framework-0-6-released/#comments</comments>
		<pubDate>Sun, 08 Aug 2010 17:53:45 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[cqrs]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2010/08/08/axon-framework-0-6-released/</guid>
		<description><![CDATA[<p>Today, I released version 0.6 of the Axon Framework. 0.6 has many new features and is another step towards full production readiness. There is still some work to do, but first, let’s take a look at what has changed…</p> <p></p> <p>Test fixtures are now part of the axon-test module. These fixtures allow you to [...]]]></description>
			<content:encoded><![CDATA[<p>Today, I released version 0.6 of the Axon Framework. 0.6 has many new features and is another step towards full production readiness. There is still some work to do, but first, let’s take a look at what has changed…</p>
<p><span id="more-1070"></span></p>
<p>Test fixtures are now part of the axon-test module. These fixtures allow you to test your command handling logic based on events and commands. You define these tests in a given-when-then style: given these past events, when I execute this command, I expect these events to occur.</p>
<p>The <tt>CommandBus</tt> interface now allows for asynchronous command dispatching. Instead of using a return value, a Callback can be given to the command bus if you wish to be notified of the result of command execution.</p>
<p>The repositories make use of a <tt>UnitOfWork</tt> instance, which keeps track of changed aggregates and generated events. Instead of saving each aggregate separately, the <tt>UnitOfWork</tt> can be committed, causing changed aggregates to be stored, and events to be dispatched. With the new <tt>SimpleUnitOfWorkInterceptor</tt> or the <tt>SpringTransactionalInterceptor</tt>, it is no longer necessary to call <tt>repository.save()</tt>. In fact, you are discouraged from doing so.</p>
<p>Repositories are now capable of detecting conflicting modifications. When loading an aggregate, you may pass in the expected version of the aggregate. An exception is raised if that version does not match the actual version.</p>
<p>Event sourcing repositories allow for a more advanced way of detecting conflicts. Sometimes, not all concurrent modification are in conflict with each other. One user may very well change the shipping address of an order, while another user is adding items. Other modifications, however, are clearly conflicting, such as one user marking an order as shipped, and another one adding a product. For this purpose, you can register a <tt>ConflictResolver</tt> with the repository. This conflict resolver can, based on unseen and newly applied events, decide whether the changes made by the second user are accepted.</p>
<p>Axon now provides a mechanism to trigger snapshot creation based on the number of events needed to load to reconstitute an aggregate. When the number of events exceeds a given threshold, a snapshot is created and stored in the Event Store.</p>
<p>The <tt>SimpleCommandBus</tt> and <tt>SimpleEventBus</tt> now expose statistics over JMX. Although currently quite limited, the statistics will be improved in the coming versions.</p>
<p>All of these features help making applications with CQRS-based architectures even easier. But we’re not there yet. The coming months, we will try to make it even easier with features like Event versioning, support for aggregates with multiple entities, and whatever comes to mind in Axon’s growing community.</p>
<p>For more information about the Axon Framework, see <a href="http://www.axonframework.org">www.axonframework.org</a>.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F08%2F08%2Faxon-framework-0-6-released%2F&amp;title=Axon%20Framework%200.6%20released&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/08/08/axon-framework-0-6-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CQRS &#8211; Designing domain events</title>
		<link>http://www.gridshore.nl/2010/01/27/cqrs-designing-domain-events/</link>
		<comments>http://www.gridshore.nl/2010/01/27/cqrs-designing-domain-events/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 11:33:31 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[cqrs]]></category>
		<category><![CDATA[DDD]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2010/01/27/cqrs-designing-domain-events/</guid>
		<description><![CDATA[<p> Command-Query Responsibility Segregation (CQRS) is slowly but steadily gaining ground as an architecture that helps developers to develop scalable, extensible and maintainable applications. Events play a major role in this architecture, and the way you design these events greatly influence the extensibility of your application.</p> <p>In this post, I describe some CQRS event [...]]]></description>
			<content:encoded><![CDATA[<p><a title="AxonFramework logo" href="http://www.axonframework.org" target="_blank"><img style="border-right-width: 0px; margin: 5px 10px 10px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="logo" border="0" alt="logo" align="left" src="http://www.gridshore.nl/wp-content/uploads/logo.png" width="100" height="100" /></a> Command-Query Responsibility Segregation (CQRS) is slowly but steadily gaining ground as an architecture that helps developers to develop scalable, extensible and maintainable applications. Events play a major role in this architecture, and the way you design these events greatly influence the extensibility of your application.</p>
<p>In this post, I describe some CQRS event basics and design considerations that help keep your application extensible.</p>
<p>The full post is published on the JTeam blog. Continue to read here: <a title="http://blog.jteam.nl/2010/01/27/cqrs-designing-domain-events/" href="http://blog.jteam.nl/2010/01/27/cqrs-designing-domain-events/">http://blog.jteam.nl/2010/01/27/cqrs-designing-domain-events/</a></p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2010%2F01%2F27%2Fcqrs-designing-domain-events%2F&amp;title=CQRS%20%26ndash%3B%20Designing%20domain%20events&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2010/01/27/cqrs-designing-domain-events/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CQRS made easy with cqrs4j</title>
		<link>http://www.gridshore.nl/2009/12/21/cqrs-made-easy-with-cqrs4j/</link>
		<comments>http://www.gridshore.nl/2009/12/21/cqrs-made-easy-with-cqrs4j/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 08:37:00 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[cqrs]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/?p=954</guid>
		<description><![CDATA[<p>&#160;</p> <p>Command Query Responsibility Segregation (CQRS) is an architectural style that makes a clear distinction between commands, which tell an application to do something, and queries, which are requests for information from an application. This distinction comes from the fact that the requirements (and thus also the model) for the execution and validation of [...]]]></description>
			<content:encoded><![CDATA[<p>&#160;<img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; margin-left: 0px; border-left-width: 0px; margin-right: 0px" title="cqrs4j_logo" border="0" alt="cqrs4j_logo" align="left" src="http://www.gridshore.nl/wp-content/uploads/logo_large.png" width="100" height="100" /></p>
<p>Command Query Responsibility Segregation (CQRS) is an architectural style that makes a clear distinction between commands, which tell an application to do something, and queries, which are requests for information from an application. This distinction comes from the fact that the requirements (and thus also the model) for the execution and validation of commands are significantly different than those for queries. Events play an important role in the synchronization of application state resulting from executed command.</p>
<p>Applying a CQRS style architecture involves the development of quite a lot of “plumbing” code: event dispatching, asynchronous event processing, transactions, etc. <em>cqrs4j</em>, an Apache 2 licensed open source framework, takes care of all the plumbing for you. Read on to find out how…</p>
<p> <span id="more-954"></span><br />
<h2>A brief introduction to CQRS</h2>
<p>As I stated above, CQRS makes a distinction between the model that validates and executes commands and the model that is used for providing state information. This is quite significantly different than how most (web)app applications are build nowadays. In fact, the model used for commands (the box named “Domain” in the image below), does not expose any state, at all. You might wonder, but how do I know what to show in the front end? That comes directly from your data sources using a thin data layer. I’ll explain how the data gets there in a minute.<a href="http://www.gridshore.nl/wp-content/uploads/cqrs_architecture.jpg"><img style="border-bottom: 0px; border-left: 0px; display: block; float: none; margin-left: auto; border-top: 0px; margin-right: auto; border-right: 0px" title="cqrs_architecture" border="0" alt="cqrs_architecture" src="http://www.gridshore.nl/wp-content/uploads/cqrs_architecture_thumb1.jpg" width="404" height="281" /></a></p>
<p>When a command comes in, it will load an <a href="http://dddstepbystep.com/wikis/ddd/aggregate.aspx" target="_blank">aggregate</a> from the <a href="http://dddstepbystep.com/wikis/ddd/repository.aspx" target="_blank">repository</a> and execute certain operations on it. As a result of these operations, the aggregate produces events, which are picked up for storage by the repository and for dispatching by the event bus. The event bus will dispatch each event to all (interested) event handlers. Some of these event handlers will perform actions on other (related) aggregates, some others will update the database tables they manage.</p>
<p>Having handlers update the data in the database means that your tables do not have to be normalized anymore. Instead, CQRS allows you to optimize your tables for the way you want to query them. This makes the data layer processing your queries really simple, and maintainable. </p>
<p>Furthermore, since all state changes are initiated by events, these events become a reliable source for an audit trail. By storing these events, you have an audit trail that you can use to replay the entire application history. Instead of just seeing “current application state” only, you can see all the changes that have led to the current state, providing valuable information trying to find bugs or deal with customer complaints.</p>
<p>The asynchronous and event driven nature of CQRS makes it extremely valuable for complex applications that have different views on the information in the application. Integration with third party systems that need to be notified of certain changes in your application –and vice versa–&#160; is a lot easier if you use an event driven approach. And since event handling is done asynchronously, the application is more responsive and easier to scale. </p>
<p>But as you notice, there is quite a lot of processing and pushing around of events. When you have a customer breathing up your neck, you don’t want to be developing infrastructure code. You would want to be focusing on the business logic, which is quite complex by itself.</p>
<h2>cqrs4j</h2>
<p>cqrs4j is a Spring-oriented framework that provides the most important building blocks of a CQRS architecture. Creating an aggregate becomes really simple. You don’t have to worry about managing the storage and dispatching of (uncommitted) events. Event sourcing becomes as easy as wiring two beans in your application context.</p>
<p><strong>Annotation support</strong></p>
<p>cqrs4j comes with out-of-the-box annotation support. This makes is really easy to wire event handler methods. cqrs4j can automatically subscribe all your event handlers to the event bus and delegate all relevant events to the appropriate event handlers. Enabling annotation support is as easy as wiring a single bean in your application context.</p>
<p><strong>Spring Integration support</strong></p>
<p>Spring Integration is a framework that allows easy developments of a Messaging systems using the pipes-and-filters architecture. This fits nicely with most of the event dispatching process of CQRS. cqrs4j has support for Spring Integration, which allows you to publish all events as messages on a Spring Integration channel. Sending messages through JMS queues, via email, or through file system storage will only take a few lines of (XML) configuration.</p>
<p><strong>Transaction support</strong></p>
<p>If you update your database tables through incoming events, dealing with them one-by-one in a transaction can become time consuming and take up too much resources of your database. With cqrs4j, you can configure transactions just by setting the @Transactional annotation on your event handlers. You can also configure how many events should be handled in a single transaction.</p>
<h2>cqrs4j project page</h2>
<p>cqrs4j is an open source project, licensed under the Apache 2 license. Visit the project home page for the latest downloads, documentation and source code at <a href="http://code.google.com/p/cqrs4j" target="_blank">code.google.com/p/cqrs4j</a>.</p>
<p><strong>We welcome your feedback</strong></p>
<p>If you have any requests, remarks or other feedback, please let us know. You can report bugs and improvement requests on the <a href="http://code.google.com/p/cqrs4j/issues/" target="_blank">issues page</a>. You can also leave a message via the <a href="http://www.gridshore.nl/contact/" target="_blank">contact page</a> or by leaving a comment.</p>
<h2>Further reading</h2>
<p>I have some more CQRS related blog articles coming up, but there are already quite a few around. Here is a few that helped me get started:</p>
<ul>
<li><a href="http://www.infoq.com/presentations/greg-young-unshackle-qcon08" target="_blank">Greg Young @ QCon: Unshackle your domain</a> </li>
<li><a href="http://elegantcode.com/2009/11/11/cqrs-la-greg-young/" target="_blank">CQRS a la Greg Young</a> </li>
<li><a href="http://elegantcode.com/2009/11/20/cqrs-the-domain-events/" target="_blank">CQRS – The Domain Events</a> </li>
<li><a href="http://elegantcode.com/2009/12/08/cqrs-domain-state/" target="_blank">CQRS – Domain State</a> </li>
<li><a href="http://jonathan-oliver.blogspot.com/2009/10/dddd-why-i-love-cqrs.html" target="_blank">DDDD – Why I love CQRS</a> </li>
</ul>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2009%2F12%2F21%2Fcqrs-made-easy-with-cqrs4j%2F&amp;title=CQRS%20made%20easy%20with%20cqrs4j&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2009/12/21/cqrs-made-easy-with-cqrs4j/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bring some stability to your architecture</title>
		<link>http://www.gridshore.nl/2008/10/30/bring-some-stability-to-your-architecture/</link>
		<comments>http://www.gridshore.nl/2008/10/30/bring-some-stability-to-your-architecture/#comments</comments>
		<pubDate>Thu, 30 Oct 2008 20:44:56 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[software design]]></category>
		<category><![CDATA[stability]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2008/10/30/bring-some-stability-to-your-architecture/</guid>
		<description><![CDATA[<p>Applications have to run in high-consequence environments. They have to serve hundreds of thousands of users 24 / 7. Our clients spend millions in hard- and software and highly depend on the revenue generated by these applications. Unnecessary outage of these application is fatal.</p> <p>Software Architects play an important role in setting up an [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/uploads/circuitbreaker.jpg" alt="circuitbreaker" hspace="5" vspace="5" width="90" height="89" align="left" />Applications have to run in high-consequence environments. They have to serve hundreds of thousands of users 24 / 7. Our clients spend millions in hard- and software and highly depend on the revenue generated by these applications. Unnecessary outage of these application is fatal.</p>
<p>Software Architects play an important role in setting up an architecture that can cope with these high demands. At the JAOO, <a href="http://www.michaelnygard.com">Michael Nygard</a>&#8216; had a talk, &#8220;<a href="http://jaoo.dk/aarhus-2008/tracks/show_track.jsp?trackOID=187">Failure comes in Flavors</a>&#8220;, that gave very good insight in the risks and opportunities of today&#8217;s application. The talk was was divided into two sessions. The first session covered the bad news: the stability threats. He discussed several situations that pose a threat to the long and happy life of an application. The second session was a happier one. It covered the patterns that should be applied to the application architecture to prevent these threats.</p>
<p>In this post, I will elaborate on some of the stability threats and pick one specific pattern to resolve them: the circuit breaker.</p>
<p><span id="more-384"></span></p>
<p><strong>Stability</strong></p>
<p>Before we go on about the stability threats, we need a common understanding about what stability is.</p>
<p>Michael Nygard defines stability as &#8220;the consistent, long-term availability of features&#8221;, and can be divided into four different qualities:</p>
<ul>
<li>Severability; instead of crashing completely, only loose the functional area&#8217;s that are struck by failure</li>
<li>Resilience; automatically recover from failures</li>
<li>Recoverability; make sure only crashed components need to be restarted, not the entire application</li>
<li>Tolerance; absorb shocks from other components instead of propagating them</li>
</ul>
<p>Note that stability doesn&#8217;t mean that nothing will ever go wrong. It just states that when something does go wrong, only the features of the applications directly related to the struck component become unavailable, and only until the component comes up again.</p>
<p><strong>Stability threats</strong></p>
<p>The life of a web application developer is interesting. We build applications that are hosted in the most hostile environment imaginable: the internet. People can travel at light speed, nearly invisible and have all the power to bring your application down, willingly or accidentally. In fact, more application crash because of accidental abuse than of hackers.</p>
<p>This brings us to the first threat: the <em><span style="text-decoration: underline;">user</span></em>. Unfortunately, the user pays for our client&#8217;s income (and ours too). We&#8217;ll have to deal with them.</p>
<p>Several aspects of the users behavior pose a threat for our application:</p>
<ul>
<li>Users don&#8217;t wait. If a page doesn&#8217;t show up quickly enough, he&#8217;ll push the link again, starting two threads to work for him, only wonderings the situation</li>
<li>Users write about cool stuff and come to your site after reading that stuff. This may cause a sudden burst of users, possibly overloading your site</li>
<li>Buyers will use all integration points, causing traffic in every little corner of your application</li>
<li>Some users aren&#8217;t actually users, but bots, and may cause unused sessions to be created for them</li>
<li>Users only visit your site when they&#8217;re awake, causing traffic surges at daytime, while your processors wait for orders at night.</li>
</ul>
<p>A threat briefly mentioned above is the <span style="text-decoration: underline;"><em>integration point</em></span>. This is the point where your application meets another. An example of this is the database or an external payment provider.</p>
<p>Integration points are dangerous for a couple of reasons:</p>
<ul>
<li>External systems typically have to be reached over a network connection, making the integration dependent of ever more components</li>
<li>Ever had the problem of a firewall dropping your packets? It&#8217;s a nice way of not being able to set up a connection without getting any feedback about why this happens.</li>
<li>Some external systems just keep you waiting. If your payment provider is busy, they&#8217;ll be happy to keep you waiting. But will your user wait? How many threads will clog up and the integration point, waiting for a response?</li>
</ul>
<p>I could go on for a long time, but these are the two threats that I want to cover in this post. If you want more, read Michael Nygard&#8217;s book &#8220;Release It&#8221;.</p>
<p><strong>Stability patterns</strong></p>
<p>Fortunately, there is a series of patterns that can be applied to increase an application stability. One of these patterns is the <span style="text-decoration: underline;"><em>circuit breaker</em></span>. You&#8217;re most likely familiar with the electrical circuit breaker. When you have an electricity leak or high power throughput, the circuit breaker will open and stop the electrical current. You&#8217;ll be in the dark, but at least your television, washing machine and music installation are saved from destruction.</p>
<p>Now, imagine your database has a hard time keeping up with your amount of requests. It will probably take longer to process each request, causing even more requests to pile up. In the end, your database server might break, taking your application with it. That is the time where we need a circuit breaker to stop the current from going to our database. I&#8217;m talking about digital current here, not electricity. Let&#8217;s keep that fans turning on the hardware!</p>
<p>A software circuit breaker should do a few things. Most important is that is should monitor each call performed on a specific backend. When a certain amount of calls fail or take too long, the circuit breaker opens, blocking the current. Each request coming in when the circuit breaker is opened will result in an immediate failure, throwing the last exception that was received from the last call. This has two positive effects: your thread returns more quickly and the load on the external system is relieved, allowing it to recover.</p>
<p>After a certain period of time, the circuit breaker will let a single request pass through to the backend. If that call fails, nothing changes. If the call succeeds, the circuit breaker will close, allowing the requests to pass through to the external system.</p>
<p>The number of use cases for a circuit breaker is most likely limited by our imagination. A nice one I could think of was to limit functionality when load becomes too high. Typically, this would be the functionality that is &#8220;nice to have&#8221;, but not essential to your application. To do this, your code would have to inspect the state of the circuit breaker when deciding which options are made available to your user. Do keep in mind though, that limiting functionality might cause your circuit breaker to sit and wait for requests which don&#8217;t come, never closing it. You&#8217;ll need another mechanism for detecting when it can be closed.</p>
<p><strong>Implementing the circuit breaker</strong></p>
<p>I&#8217;ve been playing around with a small circuit breaker implementation. You can find the code in our <a href="http://gridshore.googlecode.com/svn/trunk/StabilityPatterns/" target="_blank">code repository</a>. It&#8217;s really small, but seemed really powerful.</p>
<p>There are 2 main components in the application.</p>
<ul>
<li>The interceptor is responsible for intercepting calls to the external system and sending the requests and responses to the circuit breaker [<a title="AnnotatedMethodCircuitBreakerInterceptor.java" href="http://gridshore.googlecode.com/svn/trunk/StabilityPatterns/circuitbreaker/src/main/java/nl/gridshore/stability/circuitbreaker/AnnotatedMethodCircuitBreakerInterceptor.java" target="_blank">see code</a>]</li>
<li>The circuit breaker itself decides if requests should be sent and what should happen when responses are received [<a title="SimpleCircuitBreaker.java" href="http://gridshore.googlecode.com/svn/trunk/StabilityPatterns/circuitbreaker/src/main/java/nl/gridshore/stability/circuitbreaker/TimedSpringJmxCircuitBreaker.java" target="_blank">see code</a>]</li>
</ul>
<p>To find out if a circuit breaker is actually useful, I&#8217;ve done a few load tests. I&#8217;ve ran these tests against the same application twice. Once with circuit breaker and once without. The results are promising.</p>
<p>When activated, the circuit breaker will cause failures to append a lot faster than when there is none. This means threads are released much faster, allowing the next unfortunate user to receive the error. Of course, it doesn&#8217;t help your user much, but at least you&#8217;ll be able to tell him something is wrong instead of giving him a timeout after 30 seconds.</p>
<p>Don&#8217;t believe me? Have a look at the screen shots of the meter tests below:</p>
<p align="center"><a href="http://www.gridshore.nl/wp-content/uploads/250threads_target_throughput_50.png" target="_blank"><img src="http://www.gridshore.nl/wp-content/uploads/250threads-target-throughput-50-small.jpg" alt="250threads target throughput 50" hspace="5" vspace="5" width="225" height="137" /></a><br />
250 concurrent threads with a targeted throughput of 50 requests per second. The circuit breaker variant doesn&#8217;t have any failed calls, while the normal implementation has more than 40% failures.</p>
<p align="center"><a href="http://www.gridshore.nl/wp-content/uploads/250threads_target_throughput_100.png" target="_blank"><img src="http://www.gridshore.nl/wp-content/uploads/250threads-target-throughput-100-small.jpg" alt="250threads target throughput 100" hspace="5" vspace="5" width="225" height="137" /></a><br />
250 concurrent threads with a targeted throughput of 100 requests per second. This is where the circuit breaker variant seems to have it&#8217;s first failures.</p>
<p align="center"><a href="http://www.gridshore.nl/wp-content/uploads/1000thread_burst.png" target="_blank"><img src="http://www.gridshore.nl/wp-content/uploads/1000thread-burst-small.png" alt="1000thread burst" hspace="5" vspace="5" width="225" height="61" /></a><br />
And finally, a 1000 thread burst, just to see what happens if you spam tomcat with 1000 concurrent, continuously refreshing users. It&#8217;s 80% failure against 32% for the circuit breaker.</p>
<p><strong>Conclusion</strong></p>
<p>In this post, I&#8217;ve covered two of the stability threats that can be prevented by a correct implementation of the circuit breaker pattern. Our <a title="Gridshore SVN repository - Stability Patterns" href="http://gridshore.googlecode.com/svn/trunk/StabilityPatterns/" target="_blank">svn code repository</a> contains example code of an implementation of a circuit breaker. And finally, I&#8217;ve shown some unit test results to demonstrate the advantage of applying a circuit breaker to your architecture.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2008%2F10%2F30%2Fbring-some-stability-to-your-architecture%2F&amp;title=Bring%20some%20stability%20to%20your%20architecture&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2008/10/30/bring-some-stability-to-your-architecture/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Why are web services so different from an HTML user interface?</title>
		<link>http://www.gridshore.nl/2008/02/13/why-are-web-services-so-different-from-an-html-user-interface/</link>
		<comments>http://www.gridshore.nl/2008/02/13/why-are-web-services-so-different-from-an-html-user-interface/#comments</comments>
		<pubDate>Wed, 13 Feb 2008 18:41:35 +0000</pubDate>
		<dc:creator>Allard</dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[SOA]]></category>
		<category><![CDATA[user interface]]></category>
		<category><![CDATA[web service]]></category>

		<guid isPermaLink="false">http://www.gridshore.nl/2008/02/13/why-are-web-services-so-different-from-an-html-user-interface/</guid>
		<description><![CDATA[<p>We all know how a typical web application is usually built up. The image at the side rougly displays the different layers that are to be found in an application. Typically, the user interface layer receives HTTP requests, calls one or more methods in the Business logic layer, and responds with an HTTP message [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.gridshore.nl/wp-content/gui-application-layout.gif" alt="Typical architecture of a GUI application" align="right" height="155" width="222" />We all know how a typical web application is usually built up. The image at the side rougly displays the different layers that are to be found in an application. Typically, the user interface layer receives HTTP requests, calls one or more methods in the Business logic layer, and responds with an HTTP message containing HTML.</p>
<p>Nowadays, SOA has come along, and suddenly all enterprise architects want XML web services everywhere. For some reason, many think of SOA as a synonym for &#8220;everything must be a web service&#8221;. What SOA really is, is not the topic of this article. I want to discuss the position these web services get in the overall picture.</p>
<p><img src="http://www.gridshore.nl/wp-content/gui-and-ws-separated.gif" alt="Application design when GUI and WS are separated" align="left" height="296" width="220" />The &#8220;Business logic&#8221; layer could contain business services that are useful to other applications too. In that case, it might be an option to provide these business services to the &#8220;outside world&#8221; as XML Web Services. So, the user interface is separated from the rest of the application and replaced with a Web Services interface layer. The business logic is now available to all applications that need it. The user interface that had just been removed is now considered another application that uses the business logic layer through a web services layer.</p>
<p>On paper, it might not even look that ugly. There are, however several major downsides to this approach.</p>
<p>First of all, performance is decreased, as XML Web Service calls cost a lot of processing time. Not only marshalling the request and the response take a lot of time, but HTTP communication takes its toll too.</p>
<p>Something developers will notice, especially after the first release, is that this choice of architecture is difficult to maintain. Most changes that have been requested involve the user interface; a little more information here, something else there, etc. However, to get this information to the front-end, changes have to be made in the business logic, domain model and or the Web Service interface.</p>
<p>The third downside is that the &#8220;Business Logic&#8221; layer and the &#8220;User interface&#8221; layer are (often) functionally coupled. The main functions exposed in the view have almost a one-to-one mapping to business services. Splitting these two layers into different application would then sound inappropriate.</p>
<p>So why is this apparently homogeneous application split up into different components?</p>
<p>One thing I have heard is that this is the way SOA prescribes it should be done. I&#8217;ve read many documents and specifications, but I have never found a single one that says so. It might be obvious that I disagree.</p>
<p>Another excuse is &#8220;versioning&#8221;. For some reason, people think more of versioning as a problem than as an opportunity. When done right, versioning of a web service should be a big problem. But a more important question is: why should you version a service? Probably because the business rules in the business logic layer have changed. If that is the case, why keep the old version alive? It uses a deprecated business logic layer. Another reason to version is because the request/response model of the web service doesn&#8217;t provide all available information. That can be easily solved by adding either a new service, or an optional parameter to the existing request indicating an extended response is wanted. In my article about <a href="http://www.gridshore.nl/blog/index.php?/archives/68-Web-service-versioning-in-the-java-world.html" title="Web Service versioning in the Java world">Web Service versioning in Java</a>, I go more in-depth on ways services can be versioned (limiting to Java).</p>
<p>However, the most common excuse for the separation is reuse. &#8220;Maybe, in the future, more application might want to use this functionality too&#8221; is a sentence I have heard more than once too often. Will the business logic ever be used by another application? If that is the case, will the request/response model chosen sufficient for that application? Big chance that the answers are respectively &#8220;Most probably not&#8221; and &#8220;Very little chance&#8221;.</p>
<p>It is obvious that I am not fond of this solution. Not because I don&#8217;t think it really sounds right, but because I have dealt with this structure in my day to day work. Not somehting I would want to wish you.</p>
<p>I prefer to see the analogy between the User Interface (UI) layer and the Web Services (WS) layer. The UI presents an Business Logic interface to human users. HTML is usually the format of choice. A Web Service layer is exactly that, but then presents the same functionality in another format. For example as SOAP/XML messages. Or as JMS messages on a queue. And let&#8217;s not forget REST.</p>
<p><img src="http://www.gridshore.nl/wp-content/gui-and-ws-combined.gif" alt="GUI-and-WS-combined" align="right" height="148" width="211" />When you see the analogy between the UI and the WS interface, an architectural layout as the image on your right is a good option. In this picture, I have drawn a single &#8220;WS&#8221; box, but there could be more, depending on the types of services you would like to expose. I have, however, never seen more than one WS interface type in an application, and it usually is a SOAP based web service.</p>
<p>The application is still usable by other applications, accessible for other users and a lot easier to develop. There really aren&#8217;t any concessions to be made compared to the completely separated variant. Furthermore, the Web Service only has to be added at the point in time another application actualy needs it. This allows the request/response model to be designed in such a way that external application can take full advantage of the business logic.</p>
<p>I am conviced that the last option provides the most possibilities with the least concessions. And isn&#8217;t that exactly what we want? Or did I really miss something? In that case, please leave a comment and let me know.</p>
<div class='dd_post_share'><div class='dd_buttons'><div class='dd_button'><iframe src='http://widgets.dzone.com/links/widgets/zoneit.html?url=http%3A%2F%2Fwww.gridshore.nl%2F2008%2F02%2F13%2Fwhy-are-web-services-so-different-from-an-html-user-interface%2F&amp;title=Why%20are%20web%20services%20so%20different%20from%20an%20HTML%20user%20interface%3F&amp;t=2' height='25' width='155' frameborder='0' scrolling='no'></iframe></div></div><div style='clear:both'></div></div><!-- Social Buttons Generated by Digg Digg plugin v4.5.3.4, 
    Author : Yong Mook Kim
    Website : http://www.diggdigg2u.com -->]]></content:encoded>
			<wfw:commentRss>http://www.gridshore.nl/2008/02/13/why-are-web-services-so-different-from-an-html-user-interface/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

