<?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>JTeam Blog &#187; Allard Buijze</title>
	<atom:link href="http://blog.jteam.nl/author/allard/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jteam.nl</link>
	<description>Keep updated on what we&#039;re doing!</description>
	<lastBuildDate>Fri, 23 Jul 2010 07:32:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Axon Framework 0.5 released</title>
		<link>http://blog.jteam.nl/2010/04/24/axon-framework-0-5-released/</link>
		<comments>http://blog.jteam.nl/2010/04/24/axon-framework-0-5-released/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 15:30:19 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/2010/04/24/axon-framework-0-5-released/</guid>
		<description><![CDATA[Today, I finalized the 0.5 release of the Axon Framework. There is quite a number of changes since the 0.4 version. The 0.5 version is a major step towards production readiness of the framework. Besides some changes to existing building blocks, such as the event bus, which is now much more powerful, the 0.5 version [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 5px; display: inline;" src="http://www.gridshore.nl/wp-content/uploads/axon_logo.png" alt="" align="left" /> Today, I finalized the 0.5 release of the Axon Framework. There is quite a number of changes since the 0.4 version. The 0.5 version is a major step towards production readiness of the framework.</p>
<p>Besides some changes to existing building blocks, such as the event bus, which is now much more powerful, the 0.5 version also includes some new features.</p>
<p>Read on to find out more.</p>
<p><span id="more-2218"></span></p>
<h2><strong>New features</strong></h2>
<ul>
<li><strong>Code restructuring.</strong> The package structure has been changed to better reflect the different architectural components Axon Framework provides. It should be easier to find the one you&#8217;re looking for.</li>
<li><strong>Command Bus.</strong> The command bus is added to Axon. It provides you the ability to explicitly define commands and dispatch them to your command handlers. Furthermore, the command bus provides you the ability to process commands regardless of their type using interceptors. This is useful for, for example, logging, authorization and correlation of incoming commands.</li>
<li><strong>JPA Event Store. </strong>The easiest CQRS configuration is on using full-consistency. That means everything should run within a single transaction. Since transactions over multiple data sources involve a huge performance penalty, Axon provides a JPA Event Store. Its performance is not as good as the FileSystem version, but is does provide transaction support.</li>
<li><strong>Easy switching between full-consistency and eventual consistency.</strong> You can easily choose to process all commands and related events inside a single transaction, or to handle events asynchronously. Choosing for consistency or high-performance is just a matter of configuration. No coding required.</li>
<li><strong>Per-event listener configuration of asynchronous processing.</strong> It is now possible to decide on synchronous vs asynchronous event processing for each event handler individually, just by adding an annotation. If you configure a transaction manager for your event listeners, Axon will process the events in batches and manage the transactions around them.</li>
<li><strong>Support for rolling snapshots.</strong> All event stores will automatically pick up snapshot events. Snapshot events are an important performance booster when aggregates generate a lot of events. Instead of reading all passed events, the event store just needs to read the last snapshot event and the regular events created since the snapshot.</li>
<li><strong>Transactional Event Processing.</strong> Configuring transactions in asynchronous event processing is now a lot easier. 0.5 includes a <tt>SpringTransactionManager</tt> you can use in combination with Spring&#8217;s <tt>PlatformTransactionManager</tt>.</li>
<li><strong>Major documentation update.</strong> The documentation has been restructured to make it easier to find what you&#8217;re looking for.</li>
</ul>
<h2><strong>Maven Central</strong></h2>
<p>Where the 0.4 version required configuration of a repository in your project’s pom.xml, the 0.5 version doesn’t. All required artifacts are available in the maven central repository.</p>
<h2>Workshop and professional support</h2>
<p>We believe that the 0.5 version of Axon Framework is a major step towards production readiness. Therefore, JTeam has decided to provide professional support for the Axon Framework and organize workshops to get you acquainted with the numerous features and choices involved with CQRS.</p>
<p>The first workshop is planned for Friday May 21st in our office in Amsterdam. For more information, visit <a href="http://www.jteam.nl/training/workshop/cqrs-axon-framework-training-workshop.html">http://www.jteam.nl/training/workshop/cqrs-axon-framework-training-workshop.html</a>.</p>
<h2>Getting started</h2>
<p>Want to get started? Visit <a href="http://www.axonframework.org">www.axonframework.org</a> and download the <a href="http://axonframework.googlecode.com/files/reference-guide-0.5.pdf">reference guide</a>. That should contain enough information to get you started. If you still have questions, drop me a message.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2010/04/24/axon-framework-0-5-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Measuring code quality with Sonar</title>
		<link>http://blog.jteam.nl/2010/02/26/measuring-code-quality-with-sonar/</link>
		<comments>http://blog.jteam.nl/2010/02/26/measuring-code-quality-with-sonar/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 12:13:38 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Quality]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/?p=1856</guid>
		<description><![CDATA[At JTeam, we continuously strive for good quality code. The reason is very simple: bad quality code slows down the development process. The small investment pays out in even the simplest of projects. Measuring code quality is not a matter of a single metric. Instead, software quality has many aspects, some of which can be [...]]]></description>
			<content:encoded><![CDATA[<p><img style="margin: 0px 5px 5px 0px; display: inline; border-width: 0px;" title="sonar-blackonwhite" src="http://blog.jteam.nl/wp-content/uploads/2010/02/sonarblackonwhite.png" border="0" alt="sonar-blackonwhite" width="120" height="74" align="left" /> At JTeam, we continuously strive for good quality code. The reason is very simple: bad quality code slows down the development process. The small investment pays out in even the simplest of projects.</p>
<p>Measuring code quality is not a matter of a single metric. Instead, software quality has many aspects, some of which can be captured in metrics. Those metrics can be nicely assembled within a single application, which gives a nice overview of the state of an application: Sonar.</p>
<p><span id="more-1856"></span><a href="http://sonar.codehaus.org/" target="_blank">Sonar</a> (version 1.12 at the time of writing) is a web application that can be installed standalone or inside an existing Java Web Application Container, such as Tomcat. The standalone version is quite easy to install. Just download, start and a few moments later it’s ready on port 9000.</p>
<p>You can capture metrics using maven by running mvn sonar:sonar on your project. In some cases, your pom.xml file will need an explicit reference to this plugin, since it is not a default apache-maven plugin.</p>
<pre class="brush: xml;">&lt;build&gt;
  &lt;plugins&gt;
    &lt;plugin&gt;
      &lt;groupid&gt;org.codehaus.mojo&lt;/groupid&gt;
      &lt;artifactid&gt;sonar-maven-plugin&lt;/artifactid&gt;
    &lt;/plugin&gt;
  &lt;/plugins&gt;
&lt;/build&gt;</pre>
<p>After running mvn sonar:sonar on your project, Sonar will contain metrics information of your application. Browsing to &#8220;localhost:9000&#8243; will show this.</p>
<p>Sonar has a nice overview screen that shows certain metrics (you can configure which ones you want to see) for all project. In a software development organization, this means that you have a single point where you can measure each project’s “technical health”. You could even add custom metrics, such as budget, number of people on the project, number of story points left in the backlog, etc.</p>
<p><a href="http://blog.jteam.nl/wp-content/uploads/2010/02/overview1.png"><img class="alignnone size-full wp-image-1875" title="overview" src="http://blog.jteam.nl/wp-content/uploads/2010/02/overview1.png" alt="" width="200" height="100" /></a> <a href="http://blog.jteam.nl/wp-content/uploads/2010/02/dashboard1.png"><img class="alignnone size-full wp-image-1873" title="dashboard" src="http://blog.jteam.nl/wp-content/uploads/2010/02/dashboard1.png" alt="" width="200" height="100" /></a> <a href="http://blog.jteam.nl/wp-content/uploads/2010/02/details1.png"><img class="alignnone size-full wp-image-1874" title="details" src="http://blog.jteam.nl/wp-content/uploads/2010/02/details1.png" alt="" width="200" height="100" /></a></p>
<p>Each project has a dashboard. The dashboard is an aggregation of more detailed metrics on a single page. This page gives a pretty good overview of the technical state of a project. When doing project reviews, this page is a good starting point to find items to investigate.</p>
<p>Almost every metric on the dashboard is clickable. When you click on a metric, you get more information about violating classes.</p>
<h2>Configuring Metrics</h2>
<p>Sonar uses <a href="http://findbugs.sourceforge.net/" target="_blank">findbugs</a>, <a href="checkstyle.sourceforge.net/" target="_blank">checkstyle</a> and <a href="pmd.sourceforge.net/" target="_blank">PMD</a> to measure your code for bugs, ugly code and possible violation of code style policies. Sonar comes with a pretty good basic configuration, but the chance is big that you want to fiddle with the settings.</p>
<p>The easiest way is to take a basic configuration and make a copy of it. You can then change the configuration as you like. Note that you have to tell Sonar which projects should use this configuration.</p>
<p><a href="http://blog.jteam.nl/wp-content/uploads/2010/02/configuration1.png"><img class="alignnone size-full wp-image-1872" title="configuration" src="http://blog.jteam.nl/wp-content/uploads/2010/02/configuration1.png" alt="" width="200" height="100" /></a> <a href="http://blog.jteam.nl/wp-content/uploads/2010/02/project_profiles1.png"><img class="alignnone size-full wp-image-1871" title="project_profiles" src="http://blog.jteam.nl/wp-content/uploads/2010/02/project_profiles1.png" alt="" width="200" height="100" /></a></p>
<p>Note that you must be logged in to be able to change the configuration. By default, there is one user, with username and password “admin”.</p>
<p>Another way to create a configuration is by specifically creating a new one. This is useful if you already have checkstyle, PMD and findbug configurations in your organization. You can then upload these files when creating your new configuration.</p>
<h2>Sonar Database Configuration</h2>
<p>The default configuration works nicely if you have Sonar installed locally and don&#8217;t mind to use the default Derby Database. For larger development environments, however, this default configuration is not enough.</p>
<p>You can configure Sonar to use a database quite easily. The “sonar.properties” file contains the basic Sonar configuration. Configuration examples are available for most databases. All you need to do is uncomment a block of configuration and make sure the URL, username and password are correct.</p>
<p>In maven, you have to configure the same URL’s. Personally, I find that a little awkward, since you need to share database details over multiple applications.</p>
<p>You can configure Sonar in your pom.xml file, which makes the configuration accessible to the projects using that pom. The following example configures a MySQL database.</p>
<pre class="brush: xml;">&lt;project&gt;
  &lt;properties&gt;
    &lt;sonar.jdbc.url&gt;jdbc:mysql://my_sonar_db:3306/sonar?useUnicode=true&amp;amp;characterEncoding=utf8&lt;/sonar.jdbc.url&gt;
    &lt;sonar.jdbc.driver&gt;com.mysql.jdbc.Driver&lt;/sonar.jdbc.driver&gt;
    &lt;sonar.jdbc.username&gt;sonar_user&lt;/sonar.jdbc.username&gt;
    &lt;sonar.jdbc.password&gt;sonar_pass&lt;/sonar.jdbc.password&gt;
    &lt;sonar.host.url&gt;http://my_sonar_url:9000&lt;/sonar.host.url&gt;
  &lt;/properties&gt;
&lt;/project&gt;</pre>
<p>Alternatively, you can pass all these parameters in the maven command line, or configure your maven settings.xml (on your build server, for example) to set these parameters.</p>
<h2>Metrics don’t say it all</h2>
<p>Although I believe that Sonar is a very nice tool to create code quality awareness, metrics don’t say it all. Some quality aspects simply cannot be caught in a metric. Just solving the issues that Sonar arises is not a good way to improve quality. Sonar can show problem area’s. It is up to the development team to find out where these problems come from, and solve them.</p>
<p>No matter how good the metrics are, each and every software project still needs a <a href="http://www.jteam.nl" target="_blank">good process</a>, a <a href="http://www.jteam.nl" target="_blank">good project management</a>, a <a href="http://www.jteam.nl" target="_blank">hands-on architect</a> and a <a href="http://www.jteam.nl" target="_blank">smart development team</a> to become a success.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2010/02/26/measuring-code-quality-with-sonar/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Greg Young to attend on DDDnl meetup about CQRS on March 1st.</title>
		<link>http://blog.jteam.nl/2010/02/24/greg-young-to-attend-on-dddnl-meetup-about-cqrs-on-march-1st/</link>
		<comments>http://blog.jteam.nl/2010/02/24/greg-young-to-attend-on-dddnl-meetup-about-cqrs-on-march-1st/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 16:21:43 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[User Group]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/2010/02/24/greg-young-to-attend-on-dddnl-meetup-about-cqrs-on-march-1st/</guid>
		<description><![CDATA[On March 1st, Erik Rozendaal will give a presentation about Command Query Responsibility Seggregation (CQRS). Greg Young, one of the masterminds behind CQRS, has confirmed that he will be present during this meetup too. Seems like a good recipe for an interesting evening. Attendance is free, but registration is required. Read on for details. About [...]]]></description>
			<content:encoded><![CDATA[<p>On March 1st, Erik Rozendaal will give a presentation about Command Query Responsibility Seggregation (CQRS). Greg Young, one of the masterminds behind CQRS, has confirmed that he will be present during this meetup too. Seems like a good recipe for an interesting evening.</p>
<p>Attendance is free, but registration is required. Read on for details.</p>
<p> <span id="more-1840"></span><br />
<h2>About the meetup</h2>
<p>The Domain Driven Design Netherlands User Group (DDDnl) organizes bi-monthly meetups where software developers, architects, product owners and managers join to discuss DDD related issues. During each meetup, one of our members gives a presentation. The upcoming meetup will cover the concept of CQRS.</p>
<p>Command-Query Responsibility Segregation (CQRS) is a technique developed by Greg Young that combines the Event Sourcing pattern with Domain-Driven Design. This provides various benefits, amongst others: a fully encapsulated domain model without the need for any ORM tools, separate query and reporting database, 100% correct historical information, and easy integration with other systems.</p>
<p>In this presentation we&#8217;ll cover the core concepts of Command-Query Responsibility Segregation, its impact on the application&#8217;s architecture, and the various advantages and disadvantages. Some (Java) code will be shown to highlight how such a system can be implemented.</p>
<h2>Time and location</h2>
<p>The meetup will be held at the JTeam Head Office at Frederiksplein 1, Amsterdam. Check <a href="http://www.jteam.nl/contact">http://www.jteam.nl/contact</a> for directions.</p>
<p>You are welcome from 17:30. We will start with some food, which is expected at 18:00. The presentation starts after dinner.</p>
<h2>Registration</h2>
<p>You can confirm your presence by sending an email to <a href="mailto:info@dddnl.org">info@dddnl.org</a>. Please include your name and a phone number where we can reach you, just in case.</p>
<p>If you want to keep updated about other DDDnl meetings, make sure you register on our website: <a href="http://www.dddnl.org">www.dddnl.org</a> as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2010/02/24/greg-young-to-attend-on-dddnl-meetup-about-cqrs-on-march-1st/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Axon Framework &#8211; the CQRS framework for Java &#8211; version 0.4 released</title>
		<link>http://blog.jteam.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/</link>
		<comments>http://blog.jteam.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/#comments</comments>
		<pubDate>Sun, 21 Feb 2010 16:04:09 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/</guid>
		<description><![CDATA[Last week, I published the 0.4 release of the Axon Framework. Axon helps developers build high performance, scalable and extensible applications using the CQRS pattern. The 0.4 release is a major step towards 1.0, and includes transactional event handling, high-performance caching repositories and easy configuration of event sourcing support. Furthermore, we have also built a [...]]]></description>
			<content:encoded><![CDATA[<p><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="logo" border="0" alt="logo" align="left" src="http://blog.jteam.nl/wp-content/uploads/2010/02/logo.png" width="100" height="100" />Last week, I published the 0.4 release of the Axon Framework. Axon helps developers build high performance, scalable and extensible applications using the CQRS pattern. The 0.4 release is a major step towards 1.0, and includes transactional event handling, high-performance caching repositories and easy configuration of event sourcing support. Furthermore, we have also built a demo application that uses Flex to get real-time updates pushed from the server.</p>
<p>Read on to find out more.</p>
<p> <span id="more-1799"></span><br />
<h2>About the Axon Framework</h2>
<p><a name="Axon_Framework"></a></p>
<p>Axon Framework helps build scalable, extensible and maintainable applications by supporting developers apply the Command Query Responsibility Segregation (CQRS) architectural pattern. It does so by providing implementations, sometimes complete, sometimes abstract, of the most important building blocks, such as aggregates, repositories and event the bus – the dispatching mechanism for events. Furthermore, Axon provides annotation support, which allows you to build aggregates and event listeners without tying your code to Axon specific logic. This allows you to focus on your business logic, instead of the plumbing, and helps you makes your code easier to test in isolation.</p>
<h2>Features available in 0.4</h2>
<p>We have made quite a few additions and changes since the 0.3 release. Unfortunately, this also means I had to make some minor API changes. There is now a bigger choice of abstract classes for most of the building blocks. This allows you to choose whether you want to use the logic provided by Axon, or prefer to develop more of your own. Whatever your wish is, there should be a class to help you on your way.</p>
<p>The biggest change since 0.3 is the addition of an Asynchronous Event Bus that supports transactional processing of events. Since it is asynchronous, it means that your command processing doesn’t have to wait for events to be processed. However, this Event Buss can also guarantee the order in which events are delivered to the event handlers. You can choose full concurrent processing (without any guarantees about ordering), full sequential processing (FiFo guarantee) or anything in between. You could, for example, guarantee the sequential processing of Events that come from the same aggregate.</p>
<p>The Event Bus also provides transaction support. That means you can tell the event bus to retry an event after a certain amount of time when processing fails, for example due to an error in the underlying mechanism, such as a database. For performance reasons, you can configure the event handler to process multiple events within a single transaction. Database updates are a lot faster if you process several events within a single transaction before committing it. Within your event handler, you can configure transactions. </p>
<p>Besides Domain Events, Axon now also allows you to explicitly define two other types of events: Application Events and System Events. Application Event can notify your event listeners that something interesting happened in your application. System Events are a special type of application events and can be used to indicate that a part of your application has changed state, for example when the database is no longer available. These System Events could provide interesting operational information about your application.</p>
<p>Another major change since 0.3 is the documentation. We have brought the documentation up to par with the code-base. All features are now extensively described in the reference guide. You can download the manual from the Axon Framework website: <a href="http://www.axonframework.org" target="_blank">www.axonframework.org</a>.</p>
<p>Last, but definitely not least, we have created a demo application that you can easily download and deploy to have a look at how you can use events to your advantage. This demo application is built using a Flex Client and an Axon-based server side component. The Flex Client registers itself as an event listener and will automatically process incoming events, at real time! That means that you can have 2 windows open, change something in one window, and see the change come in immediately on the other window, too. Check our <a href="http://code.google.com/p/axonframework/wiki/SampleInstallation" target="_blank">Sample Installation</a> page for more information.</p>
<h2>What to expect in upcoming releases</h2>
<p>The major components of the CQRS pattern are already available in the 0.4 release of Axon Framework. However, there is still a number of features we want to include in the 1.0 release. Although one of the advantages of CQRS is that it makes an application scalable and extensible, the 1.0 release of Axon Framework focuses on what happens inside a single JVM. Streaming events between JVM’s is not made impossible though, the Spring Integration connectors can be used to publish events to JMS, MQ, mail, HTTP and any other protocol supported by Spring Integration.</p>
<p>Some features to expect before the 1.0 release are rolling snapshots. When aggregates live for a long time, the number of events to read in each time the aggregate is loaded could easily run in the thousands. Reading in a thousand events takes a long time. Instead of reading in a thousand events, you can summarize all these events into a single snapshot event. Axon Framework will provide the plumbing necessary for you to build snapshot events.</p>
<p>Another feature that we’ll be spending some attention on is failure recovery. Unfortunately, applications sometimes behave unexpectedly and sometimes stop entirely. The reason of a crash won’t be the Axon Framework itself, of course. But since we have a reliable source of events in the events store, we can use this to recover from failure. Axon Framework will provide some building blocks that allow you to republish events to event handlers that did not get the chance to process them. This same mechanism will allow you to restore your application state from backups.</p>
<p>The last feature currently on the roadmap is JMX support. Since Axon Framework deals with the dispatching and invocation of event handlers, it has interesting information about an application’s performance and technical state. We are planning to expose this information using JMX MBeans.</p>
<p>If you have any other ideas, you can submit a feature request on <a href="http://www.axonframework.org/issues" target="_blank">www.axonframework.org/issues</a>. </p>
<h2>Getting started with Axon</h2>
<p>If you&#8217;re eager to get started using Axon Framework for your own application, check out the <a href="http://www.axonframework.org" target="_blank">Axon Framework website</a>. There, you can download the binaries, sources documentation and a sample application. If you use Maven, the reference manual will explain how you can configure the dependencies on the Axon binaries.</p>
<p>If the information on the website is not enough to get you started, don’t hesitate to send me a message or post a comment at the bottom of this blog entry.</p>
<h2>A special thanks to…</h2>
<p>Before I wrap up, I would like to thank Jettro Coenradie for his help on the sample project and the reference documentation. I think the sample turned out into a pretty cool demo environment for some of the advantages that Axon can provide.</p>
<p>Also many thanks to <a href="http://www.jteam.nl" target="_blank">JTeam</a> for the time they allowed me to spend on the project. Without it, I am sure I couldn’t have delivered this release. Thanks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2010/02/21/axon-framework-the-cqrs-framework-for-java-version-0-4-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CQRS &#8211; Designing domain events</title>
		<link>http://blog.jteam.nl/2010/01/27/cqrs-designing-domain-events/</link>
		<comments>http://blog.jteam.nl/2010/01/27/cqrs-designing-domain-events/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 11:27:50 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Axon Framework]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[DDD]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/2010/01/27/cqrs-designing-domain-events/</guid>
		<description><![CDATA[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. In this post, I describe some CQRS event basics and [...]]]></description>
			<content:encoded><![CDATA[<p><a title="AxonFramework logo" href="http://www.axonframework.org" target="_blank"><img style="border-bottom: 0px; border-left: 0px; margin: 5px 10px 10px 0px; display: inline; border-top: 0px; border-right: 0px" title="logo" border="0" alt="logo" align="left" src="http://blog.jteam.nl/wp-content/uploads/2010/01/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> <span id="more-1724"></span><br />
<h2>The role of the domain event</h2>
<p>In CQRS, domain events are the source of all application state changes. The diagram below shows a high-level overview of a CQRS architecture. The separation of the components that deal with commands and those that deal with queries is clearly visible.</p>
<p><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-highlevel" border="0" alt="cqrs_architecture-highlevel" src="http://blog.jteam.nl/wp-content/uploads/2010/01/cqrs_architecturehighlevel.png" width="420" height="327" /></p>
<p>When a command is executed, it will (most likely) change state of one or more aggregates (see DDD definition of aggregate <a href="http://domaindrivendesign.org/node/88" target="_blank">here</a>). As a result of these state changes, one or more events are dispatched.</p>
<p>These events are picked up by Event Handling Components that do whatever they were built to do. Common Event Handling components are those that update database tables in the query database, or those that send an email notification to a user. You can also use Event Handlers to execute commands on related aggregates.</p>
<p>The command handling component is not aware of the listeners that will act on the generated events. This is an important feature to make an application extensible. The downside is that you cannot foresee how events will be used and what information these event handlers will need.</p>
<h2>Information contained in an event</h2>
<p>Since events are broadcasted throughout the entire application, events should contain the information needed by the variety of possible event listeners that exist or might exist in the future. It is impossible to exactly predict what information is needed by event handling components. However, there are a few guidelines that will cover most of the cases.</p>
<p>Recently, someone asked me for advice on event design. He asked me if it was a good idea to use an “CustomerDetailsModifiedEvent”, which would contain the full customer details of the customer, after the change was applied. Although this sounds safe to do, it will get you in serious trouble at a later stage. I’ll go into that a little later.</p>
<p>Domain events should be as specific as possible. If only the address changed on a Customer, consider using an AddressChangedEvent. That event would then contain the new address. This allows components acting on these events to listen to more specific types of events. If you want to send a (paper) letter to someone if his address changed, the “CustomerDetailsModifiedEvent” won’t get you very far, as you don’t have a way to find out what exactly changed.</p>
<p>In some cases, it might be important to know the state as it was before the command was executed. For example, if it is vital for your application to know whether the person moved to another country (because the letter template is different in these cases, for example), then you should also provide the old address in the event. Since the event is generated by the component that also makes the actual change, this shouldn’t be too hard to implement.</p>
<pre>
<pre class="brush: java;">
public class AddressChangedEvent extends DomainEvent {

    private final Address newAddress;
    private final Address oldAddress;

    public AddressChangedEvent(Address oldAddress, Address newAddress) {
        this.oldAddress = oldAddress;
        this.newAddress = newAddress;
    }

    public Address getNewAddress() {
        return newAddress;
    }

    public Address getOldAddress() {
        return oldAddress;
    }
}
</pre>
</pre>
<p>The code sample above shows the basic information contained in an AddressChangedEvent in case it is important to know the address of a customer before and after the modification. In this sample, the DomainEvent will contain information about the customer on which the address change was applied. Typically, this information is limited to the unique identifier of the aggregate.</p>
<h2>Include the intent of the change</h2>
<p>Let’s assume that our business case requires us to send a letter to each customer that changes address. This letter serves as some sort of validation that the address exists and gives the customer feedback that the address change was successfully handled.</p>
<p>In CQRS, we would just create a Event Handling Component that listens to events of type AddressChangedEvent and automatically send a letter to this customer. The information needed for the letter, such as customer name and gender are queried in the query database, since they are not contained in the event itself.</p>
<p>Consider an event with the following information:<br />
  <br />AddressChangedEvent {</p>
<p>- aggregateId 123</p>
<p>- newAddress (“someStreat 2”, &quot;13432”, “SomeCIty”) &lt;- notice the typo in the street name</p>
<p>- oldAdress (…)</p>
<p>As a result of this event, a letter is sent. It is very unlikely that the typo in the street name will cause the letter not to arrive at the destination.</p>
<p>A little later, a sales representative notices the typo in the street name and want to change the address. This change will cause another letter to be sent, most likely to the same address. That’s not really the signal the business likes to send out.</p>
<p>In this scenario, we have captured two different intents of address changes: one is to report that a customer moved to another address, the other is to make a correction in an existing address. The way we deal with these different scenario’s is different.</p>
<p>Some components, like a database updaters, typically don’t care about intent. They will change the address to the new one, regardless of the reason. Furthermore, the information needed by listeners in both scenario’s is identical.</p>
<p>When designing events, consider making an abstract event type that defines “what” has changed. For example, an abstract AddressChangedEvent. We make it abstract, because we never want an instance of this type. This abstract then has a subclass for each intent of the change, representing the “why” of the state change. For example, AddressCorrectionEvent and CustomerMovedEvent. Since they both extend the abstract AddressChangedEvent, the both contain information about the old and new address.</p>
<p>Our event handling components now have a choice. If they don’t care about intent, such as the database updater, they will handle the abstract AddressChangedEvent. If they do, like our letter sender, they can listen to intent specific subclasses. In this case, the letter sender would only act on events of type CustomerMovedEvent.</p>
<h2>Event immutability</h2>
<p>Domain events represent a notification of a state change of an aggregate. It is a representation of something that happened. Whatever you do, what happened has happened. That said, it doesn’t make much sense to change any information in the event while it is being processed.</p>
<p>In CQRS, events are ubiquitous. This means that any component anywhere in the application could listen to any event. Once properties on these events start to change, it is very hard (if not impossible) to predict which component saw which information on the event.</p>
<p>Therefore, make sure all information contained in the event is immutable. At least from the time the event is dispatched. In java, and likely also in other programming languages, making fields immutable provide valuable multi-threading guarantees.</p>
<h2>Event design in the Axon Framework</h2>
<p>Recently, we released version 0.3 of the Axon Framework, an open source framework that helps you with the implementation of applications with a CQRS architecture. Axon Framework provides base implementations for most of the components that make up a CQRS architecture, such as some base classes for events.</p>
<p>All domain events should extend the abstract DomainEvent class. Axon will then ensure that the correct aggregate identifier is registered on the event and will also set a sequence number on the event that allows you to see in which order events were generated for an aggregate. However, the rules and guidelines mentioned above still apply to all domain events.</p>
<p>Starting at version 0.4 (planned for release mid February 2010), Axon Framework also provides support for Application Events and System Events. The former are events that do not represent a state change in an aggregate, but might be of importance to event handling components. The latter provide information about state changes of application components. They could, for example, report that a database is down or a mail server cannot be reached.</p>
<p>For more information about the Axon Framework, visit the project website: <a href="http://www.axonframework.org" target="_blank">www.axonframework.org</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2010/01/27/cqrs-designing-domain-events/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rethinking architecture with CQRS</title>
		<link>http://blog.jteam.nl/2009/12/21/rethinking-architecture-with-cqrs/</link>
		<comments>http://blog.jteam.nl/2009/12/21/rethinking-architecture-with-cqrs/#comments</comments>
		<pubDate>Mon, 21 Dec 2009 11:07:13 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Application Design]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[CQRS]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/?p=1580</guid>
		<description><![CDATA[Many applications use some form of persistent storage to store its state. However, important information about this state is lost: why is the state as it currently is. Furthermore, a single model is used to store information that is retrieved for many different purposes, often resulting in extremely complex and bog-slow SQL queries. Command Query [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jteam.nl/wp-content/uploads/2009/12/question_and_answer.png"><img style="margin: 5px 10px 0px 0px; display: inline; border-width: 0px;" title="question_and_answer" src="http://blog.jteam.nl/wp-content/uploads/2009/12/question_and_answer_thumb.png" border="0" alt="question_and_answer" width="64" height="64" align="left" /></a> Many applications use some form of persistent storage to store its state. However, important information about this state is lost: why is the state as it currently is. Furthermore, a single model is used to store information that is retrieved for many different purposes, often resulting in extremely complex and bog-slow SQL queries.</p>
<p>Command Query Responsibility Segregation (CQRS) is an architectural style that makes a clear distinction between commands that change the application state and queries that expose the application state.</p>
<p><span id="more-1580"></span></p>
<h2>Background</h2>
<p>My interest in CQRS was triggered when I saw Greg Young explain “<a href="http://www.infoq.com/interviews/greg-young-ddd" target="_blank">State Transitions in Domain-Driven Design</a>” on InfoQ. In this interview, Greg explains how he sees that application would benefit from using separate models for state validation and transition on one side and maintaining a view on the current state on the other.</p>
<p>One of the problems that Greg describes is the fact that a single model is often used for different purposes. It is nicely illustrated by the SQL query below. It shows how the model chosen in the application is not suited for the purpose of providing certain information (messages between users, in this case).</p>
<pre class="brush: java;">queryBuilder.append(
  &quot;m.*, &quot; +
  &quot;m.origin_participant_id as message_origin_participant_id, &quot; +
  &quot;po.first_name as message_origin_participant_first_name, &quot; +
  &quot;po.avatar as message_origin_participant_avatar, &quot; +
  &quot;po_ua.username as message_origin_participant_username, &quot; +
  &quot;CASE WHEN !isnull(po.fieldworker_project_id) THEN 'fieldworker' WHEN !isnull(po_ap.project_id) THEN 'fundraiser' ELSE 'player' END AS message_origin_participant_type, &quot; +
  &quot;po.city as message_origin_participant_city, &quot; +
  &quot;c.name as message_origin_participant_country, &quot; +
  &quot;pd.first_name as message_destination_participant_first_name, &quot; +
  &quot;pd.avatar as message_destination_participant_avatar, &quot; +
  &quot;pd_ua.username as message_destination_participant_username, &quot; +
  &quot;CASE WHEN !isnull(pd.fieldworker_project_id) THEN 'fieldworker' WHEN !isnull(pd_ap.project_id) THEN 'fundraiser' ELSE 'player' END AS message_destination_participant_type, &quot; +
  &quot;m.destination_participant_id as message_destination_participant_id &quot; +
  &quot;from internal_message m  &quot; +
  &quot;left join player po on m.origin_participant_id = po.id &quot; +
  &quot;left join (select player_id, project_id from ambassador_project where enabled = true group by player_id) po_ap on po_ap.player_id =  po.id &quot; +
  &quot;left join user_account po_ua on po.user_account_id = po_ua.id &quot; +
  &quot;left join country c on po.country_id = c.id &quot; +
  &quot;left join player pd on m.destination_participant_id = pd.id &quot; +
  &quot;left join (select player_id, project_id from ambassador_project where enabled = true group by player_id) pd_ap on pd_ap.player_id =  pd.id &quot; +
  &quot;inner join user_account pd_ua on pd.user_account_id = pd_ua.id &quot; +
  &quot;where m.destination_participant_id = ? &quot;
);
</pre>
<p>Wouldn’t it be a lot nice to have a query such as the one below instead?</p>
<pre class="brush: sql;">&lt;/pre&gt;
SELECT * FROM messages WHERE receiving_participant = ?
&lt;pre&gt;</pre>
<p>Achieving such queries is very easy, but doing so without making your model impossible to use for maintaining state integrity and guarding invariants is a lot harder. Well, unless you apply CQRS.</p>
<h2>Architecture</h2>
<p>The diagram below shows an overview of a typical CQRS architecture.</p>
<p><a href="http://blog.jteam.nl/wp-content/uploads/2009/12/cqrs_architecture.jpg"><img style="border-width: 0px; display: block; margin-left: auto; margin-right: auto;" title="cqrs_architecture" src="http://blog.jteam.nl/wp-content/uploads/2009/12/cqrs_architecture_thumb.jpg" border="0" alt="cqrs_architecture" 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>
<h2>Benefits</h2>
<p><strong>Matches the natural language used</strong></p>
<p>At first glance, such an architecture might look very complex and over-engineered. However, after taking the first implementation steps, it felt pretty natural. In fact, when you explain the behavior of an application, you use a style that fits CQRS quite nicely: “when an order is approved, we send a confirmation email to the customer”.</p>
<p><strong>Extensibility</strong></p>
<p>Imagine an order management application. With CQRS, you could have an “OrderApproved” event, which is caught by a database updating event handler as well as one that sends an email to the customer with order information. If you later on decide to store the order information in an accounting tool as well, all it takes is adding an event handler that does the accounting integration. And since you can reload historic events as well, you can even reconstruct historic information to put in the accounting table.</p>
<p><strong>Reliable audit trail</strong></p>
<p>As I said above [see section Architecture], the model that is used to process command will generate events. These events are the sole source of state changes for the domain classes. If you want to load an aggregate from persistent storage, it will actually load all the past events of that aggregate. This process is called Event Sourcing. When events become too numerous, you can combine a number of historic events into a single snapshot event. The events that have been combined can then be archived for auditing purposes.</p>
<p>Event Sourcing turns your event storage into an extremely reliable audit trail. The events do no only show what happened and when, but they will also reveal the intention a user had. Not only is it an audit trail that will never move out-of-sync with your application, you can use the audit trail to actually replay all actions in the application. Events are not just a notification of state change, they are also the source of state change.</p>
<p><strong>Transparent distributed processing</strong></p>
<p>When using events as the trigger for state changes, you can easily distribute your application over multiple processing units (servers, JVM’s, whatever). Events can easily be serialized and sent from one server to another over JMS, via the file system or even email. The Spring Integration framework –a messaging framework – fits nicely with the event processing concept.</p>
<p>You could even let certain types of aggregates live on dedicated machines. This allows you to choose different SLA’s for different parts of you application, such as giving order creation a higher priority than sales reporting.</p>
<p><strong>Performance and Scalability</strong></p>
<p>Since event handling is done asynchronously, a user does not have to wait for all changes to be applied. Especially when integrating with external systems, this can improve liveness of an application significantly.</p>
<p>Another aspect of CQRS is that it heavily builds upon BASE (<strong>B</strong>asic <strong>A</strong>vailability, <strong>S</strong>oft-state, <strong>E</strong>ventual consistency) transactions. Although the “eventual” part scares a lot of customers and developers, the price of distributed ACID transactions is one that customer typically resent. In most cases “eventual” is just a matter of several milliseconds. But you’re free to make that seconds, minutes or even hours if your SLA permits it (think of management reports that are only read once a week or month).</p>
<p><strong>Asynchronous analysis</strong></p>
<p>When you build a CQRS style application, all activity in your application is processed using events. This makes it easy to catch these events and monitor them for inconsistent behavior. Event analysis tools like <a href="http://esper.codehaus.org/" target="_blank">Esper</a> allow you to monitor event streams for patterns that indicate possible fraud.</p>
<p>For example, when you detect that a sudden large number of users has an increased amount of failed login attempts, you could decide to block these accounts for a small period of time. In one of our projects, we use <a href="http://www.rsa.com/node.aspx?id=3018" target="_blank">RSA Adaptive Authentication</a> to increase the level of authentication required when someone tries to login on an account that might be the subject of dictionary attacks.</p>
<h2>cqrs4j – an open source CQRS Framework</h2>
<p><a href="http://code.google.com/p/cqrs4j" target="_blank"><img style="display: inline; margin-left: 0px; margin-right: 0px; border-width: 0px;" title="cqrs4j logo" src="http://blog.jteam.nl/wp-content/uploads/2009/12/logo_large.png" border="0" alt="cqrs4j logo" width="100" height="100" align="left" /></a> A few days ago, I published the source code of a CQRS framework – <a href="http://code.google.com/p/cqrs4j" target="_blank">cqrs4j</a> – on Google code. This framework aims at reducing the amount of “plumbing” and boilerplate code to a minimum. It also provides integration support for Spring Integration and transactional event processing.</p>
<p>You can find project information, source code and documentation at <a href="http://code.google.com/p/cqrs4j/">http://code.google.com/p/cqrs4j/</a>.</p>
<p>[Update: cqrs4j has been renamed to Axon Framework. You can find more information on www.axonframework.org].</p>
<h2>Upcoming presentations and events</h2>
<p>JTeam organizes monthly Tech Meetings, where interesting technologies are discussed. The January 2010 edition will contain a presentation about CQRS. Registration is required, but free of charge. The tech meeting is held on January 7th in our office in Amsterdam [<a href="http://www.jteam.nl/contact.html" target="_blank">directions</a>] and starts at 16:00. It includes dinner.  Send us an <a href="mailto:techmeeting@jteam.nl?subject=I%20want%20to%20join%20the%203rd%20Dec%20Tech%20meet%20%40%20JTeam&amp;body=Name%3A%0AOrganization%3A%0Aemail%3A%0ATel.%23%0A" target="_blank">email</a> if you like to attend.</p>
<p>The DDDnl user group organizes a presentation and discussion session on March 9th, starting at 18:00. It is also held at the JTeam office in Amsterdam [<a href="http://www.jteam.nl/contact.html" target="_blank">directions</a>]. Attendance requires <a href="http://www.dddnl.org/user/register" target="_blank">registration</a> with the DDDnl user group, which is completely free of charge. Visit <a href="http://www.dddnl.org" target="_blank">dddnl.org</a> for more information.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/12/21/rethinking-architecture-with-cqrs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Battling complexity in large web applications</title>
		<link>http://blog.jteam.nl/2009/10/20/battling-complexity-in-large-web-applications/</link>
		<comments>http://blog.jteam.nl/2009/10/20/battling-complexity-in-large-web-applications/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 10:15:48 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Application Design]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Productivity]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/2009/10/20/battling-complexity-in-large-web-applications/</guid>
		<description><![CDATA[Nowadays, companies are hardly ever satisfied with a mere web-presence. No, websites have become true applications in their own right. Instead of being a by-product, most businesses acknowledge that the web offers them a nice channel to do business. However, the demands from the business keeps growing as each company want to be better than [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.jteam.nl/wp-content/uploads/2009/10/spaceshuttleendeavourlaunch2.jpg"><img style="border-right-width: 0px; margin: 0px 5px 5px 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="space-shuttle-endeavour-launch-2" border="0" alt="space-shuttle-endeavour-launch-2" align="left" src="http://blog.jteam.nl/wp-content/uploads/2009/10/spaceshuttleendeavourlaunch2_thumb.jpg" width="71" height="104" /></a> Nowadays, companies are hardly ever satisfied with a mere web-presence. No, websites have become true applications in their own right. Instead of being a by-product, most businesses acknowledge that the web offers them a nice channel to do business. However, the demands from the business keeps growing as each company want to be better than its competitors. </p>
<p>The increasing demands from the business have a direct influence on the applications complexity. Each time, especially when joining external projects, I am amazed by the way complexity is dealt with in most applications. “Building software isn’t rocket science”, but sometimes we do seem to make it just as complex.</p>
<p>In this article, I provide some insight in different forms of complexity, and how software development teams can design their application in order to deal with the ever growing demands from the business.</p>
<p> <span id="more-1245"></span>
<p>At the dawn of each software development project, the sky is blue and the grass is green. That’s the type of project most developers like to do. However, as time progresses and features are added and changed (they are hardly ever removed, for some reason), the developers become entangled by their own code. Concepts –in which lots of time was invested to get them defined- become muddled and intentions of methods and services become vague. Eventually, the application will evolve into a <a href="http://en.wikipedia.org/wiki/Big_ball_of_mud" target="_blank">Big Ball of Mud</a>.</p>
<p><strong>Causes of complexity</strong></p>
<p>The degree in which the project team deal with complexity significantly influences the speed at which a codebase evolves into a ball of mud. There are numerous sources for complexity, that can be separated into three categories. </p>
<p align="center"><a href="http://geekandpoke.typepad.com/geekandpoke/2007/10/complexity.html" target="_blank"><img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="complexajax" border="0" alt="complexajax" src="http://blog.jteam.nl/wp-content/uploads/2009/10/complexajax.jpg" width="302" height="420" /></a><em>It is important to distinguish the different causes of complexity</em></p>
<p><u><em>Project Environment</em></u></p>
<p>The first source is the project environment itself. This mainly includes the availability of resources (e.g. people, money, knowledge) and the management style of the project manager and customer. Some project managers truly believe that when a developers estimates a piece of work at 1 week, that the sentence “I’ll give you 3 days” will actually do good to the project on the long term. Although an interesting topic, it is not the type of complexity I want to deal with in this post.</p>
<p><u><em>Technical Complexity</em></u></p>
<p>Another aspect influencing complexity is the technical environment of the project. What are the frameworks and platforms used in the development and deployment of the software. As with any technology, it is important to know the powers and limitations of each framework. If a framework requires expert knowledge to interact with it, then try to abstract that knowledge away into separate modules.</p>
<p>Every development team contains a couple of developers that is very well capable of solving these technical solutions. However, once solved and abstracted away, this technical complexity is mitigated and hardly a risk to the project. Of course there are extremes, where project heavily rely on bleeding edge technology. On those projects, you’re likely to keep a high level of technical complexity in the project. But no matter what, it should be clearly separated from the other type, discussed in the next paragraph.</p>
<p><u><em>Business Complexity</em></u></p>
<p>The third aspect is the one I will be focusing on in this post: the business domain. It is the sum of the knowledge, rules and activities of your customer that makes them survive. Solving the problems in this domain is often highly complex, but not unsolvable.</p>
<p>The majority of the business complexity is composed of the business rules. In contrast to the technological environment, the business environment is continuously in motion. And for some reason, this always means the addition of new rules and the changing of old ones, hardly ever removing them. The result of this process is an ever-growing application with increasing complexity.</p>
<p>The next sections cover a few guidelines that help you manage complexity and maintain it in acceptable ranges. In the end, people have to be able to understand the code.</p>
<p><strong>Application Layering</strong></p>
<p>The use of layers in software engineering is a concept I encounter in almost any project I join. The boundaries and definitions of these layers, though, are often fuzzy or undefined. The result is that, as the project progresses, different types of concerns leak into layers of the application where those concerns do not belong.</p>
<p>When correctly defined, layers can help developers make a clear separation between different types of complexity. Solve technical issues in another layer (e.g. the infrastructure layer) than the business complexity (e.g. application or service layer). Define clear boundaries between these layers and make sure each developer understands and respects them.</p>
<p><strong>Use a model</strong></p>
<p>The real world as a whole is useless when it comes to solving problems in software engineering. If you’re in the theatre ticket selling business, you don’t care that seats come in different styles, different colors and that some types of seats have legs. In other words, you don’t care what a seat is in the real world. I don’t expect to be telling new stuff here, but for some reason, I see it go wrong many times.</p>
<p>A common mistake I encounter in programs is that there is no real model at all. Well, there is a modules in the project called model, and it contains classes with getters and setters. Technically, it is a model, but is has been simplified to the extent that it is pretty much useless in solving the business problems. These problems are then solved in the service layer. But with the additions of new rules, this layer grows out of proportions with in some cases hundreds of methods, some of which are quite-the-same-but-not-really.</p>
<p>Another pitfall is the desire to make their model similar to the real world. The real world is not relevant to the application. An application needs to solve problems. The real world might just not be the ideal place to do that. Instead, the business itself should drive the modeling choices. And if two parts of a business (e.g. divisions) have different views on the same actual thing, consider creating a different model for each one of them.</p>
<p>A third consideration often forgotten in the development process is that not every part of the application should have to use the same model. A model is used to solve (complex) problems. Each part of an application solves different problems in the domain. A logical conclusion is that these parts do not necessarily ask for the same model. A good indicator for the possibility of splitting the model is that a single word is used in different contexts, and has a different meaning in each context. The word “Flight” will mean different things to the ground crew and the cabin crew. They will all have different intents when using the concept of a Flight. Combining all these intents into a single (shared) domain concept will most likely clutter your domain and make it harder to understand.</p>
<p><strong>Watch your language</strong></p>
<p>Ideally, the names of the concepts in the model reflect the actual words used in the business. If a new concept is added to the model, that name should be introduced in the business as well. Eric Evans calls this the “Ubiquitous Language”, the language used by all people and software involved in the domain the software runs in.</p>
<p>Why is this important? It helps new developers on a project. If they are familiar with the terminology, they will most likely understand the application right away. If they don’t, they will pick up the jargon faster and be able to talk to domain experts earlier.</p>
<p>It will also help in finding the locations where changes need to be made. If the model is correct (i.e. fits the business nicely), the language the domain expert uses will pinpoint you to the location where changes need to be made.</p>
<p><strong>Modularity</strong></p>
<p>Where simple applications will contain just a few concepts (where each concept is implemented as one or few classes), large applications may contain literally hundreds or thousands of concepts. A human being is simply not able to maintain a good overview of that amount of concepts.</p>
<p>Therefore, separate related concepts into modules. Within a module, these concepts may have tight relationships. In other words, the classes representing these concepts will have dependencies towards each other. Across modules, dependencies should be minimized. I often encounter dependencies between modules that don’t really need to be there. Removing them decreases application complexity and increases its maintainability. Especially “<a href="http://en.wikipedia.org/wiki/Domain-driven_design" target="_blank">Entity</a>”&#160; to “Entity” relationships should be avoided as much as possible.</p>
<p>For example, let’s say we have an Order that references a Product, both in different modules as different departments manage the lifecycle of these objects. What happens if the Product price changes? All orders containing that product (and most of them have probably been handled already) will change as well. The solutions is simple, add a property to the order that states the price at which the product was sold. What if other characteristics change? The name for example? Remember, we don’t care about the real world , where products don’t just change name, we care about the world the way the business wants it. Instead of referencing the Product entity as a whole, perhaps it is sufficient to copy the relevant data from the Product into the Order at the time the Order is created. Or perhaps the entity reference is only maintained for as long as the Order is being processed. This allows you to delete Product instances without losing data in the Orders module.</p>
<p>The choices you can make in keeping nicely separated modules heavily depend on the way the model has been built. The better the model is, the more flexibility you have in making choices that help your application.</p>
<p><strong>Conclusion</strong></p>
<p>In this post, I have briefly touched a few types of complexity encountered in software projects. Don’t deal with multiple types of complexity in one location (i.e. layer) in your application. Make a clear separation between these to prevent technical choices from interfering with your business logic and vice versa.</p>
<p>When it comes to business logic, try to make a model that fits the way the business likes to work. Don’t try to make it look like the real world. That world has proven to be less than ideal when it comes to solving complex problems.</p>
<p>Use the Ubiquitous Language to define the terms and concepts in your model. This helps new developers to learn the language faster and get a better understanding of the application.</p>
<p>Finally, when the number of concepts expands beyond human capability of maintaining an overview of them, separate concepts into modules. Choose your modularity carefully. Try to keep dependencies tight inside the module, while limiting the dependencies between modules.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/10/20/battling-complexity-in-large-web-applications/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Domain Driven Design applied</title>
		<link>http://blog.jteam.nl/2009/07/28/domain-driven-design-applied/</link>
		<comments>http://blog.jteam.nl/2009/07/28/domain-driven-design-applied/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 14:27:53 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Domain Driven Design]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[Project]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/?p=598</guid>
		<description><![CDATA[In a recent project for Osix, we developed an application allowing visitors of a library to use the wireless Internet connection available there. Visitors can pay for the Internet access in two ways: an online payment, for example using a credit card or by deducting the amount from their library account. All user accounts, as [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent project for <a href="http://www.osix.nl" target="_blank">Osix</a>, we developed an application allowing visitors of a library to use the wireless Internet connection available there. Visitors can pay for the Internet access in two ways: an online payment, for example using a credit card or by deducting the amount from their library account. All user accounts, as well as the available products, library configurations and payments are managed from a single central application, called Digital Services Manager.</p>
<p>In this post, I will elaborate on how <a href="http://domaindrivendesign.org/" target="_blank">Domain Driven Design</a> has helped us build a clean and maintainable application, mainly focusing on some technical and implementation choices that we have made.</p>
<p> <span id="more-598"></span>
</p>
<h3>DDD Background</h3>
<p>Domain Driven Design is really about the way software is developed. Hence, it will say more about the way to get to an implementation than about the actual implementation itself. However, if you do it correctly, you will find some of the DDD principles back in your implementation.</p>
<p>The most important concept in DDD is the “Ubiquitous Language”: the language that is used within the domain by all people involved, such as domain expert (our customer), developers and stakeholders. Since this language is used by everybody, it is best to reflect that language directly –hence without translation– in your code. Since the language will contain both nouns and verbs, this means that you will end up with a <a href="http://martinfowler.com/eaaCatalog/domainModel.html" target="_blank">Rich Domain Model</a>.</p>
<p>Another really important principle of DDD is “make it explicit”. I can’t even recall how many times Eric Evans said that during the four day training he gave two weeks ago. This means that, for example, every time you come across some relationship between two values, you should assemble these two values and name the combination. This way, you make the relationship between these values explicit and named. This name should either come from the Ubiquitous Language or should be introduced as part of it. Yes, that means no single developer can make up a name for something without consulting the domain expert first.</p>
<h3>How this reflects in the implementation</h3>
<p>Most people I talk to are curious about how this reflects in the implementation. Some people even seem to reject DDD because it is not really all that different in the implementation. Of course it isn’t, at least, not on first sight.</p>
<p>In the OSIX domain, people can use wireless access points in Libraries to gain access to the Internet using their laptop. To do this, they need to register themselves in a central application, owned and maintained by OSIX. This application serves as a web shop where users can buy credits, it provides administrators to block or enable users and keeps a log of actual time spent online.</p>
<p>This means our domain model implementation contains classes like Library, User and InternetSession. This last one is DDD-implementation wise quite interesting.</p>
<p>We needed to log the time a user logged on and when he logged off again. Hence, our first name for this class was “LogEntry”. Technically, we are just talking about a giant Log with a lot of entries. However, DDD requires that everything is to be made explicit and named according to the Ubiquitous Language. So, we consulted the domain expert. He said he calls it Internet Sessions. A user starts an internet session, and an internet session is ended when a user logs of.</p>
<p>Does it change the implementation of the class much? Not really, except for some different method names, perhaps, nothing is really different. In the end, we’re still programming Java, and the same things need to be done. And if you’re used to Anemic Domain Models, you’ll probably have to get used to the fact that invariants are guarded inside the domain object itself, instead of a service.</p>
<p>So, why is this naming important? First of all, it allows your developers and domain expert to talk the same language, without the need of continuous translation. Secondly, new developers joining the project will easily pick up the language and recognize the concepts in the code. This really showed when we needed to change some developers. The new developer was quickly able to see which functionality had been implemented and which still needed some work. Finally, our client, who has a fair understanding of the Java language, was able to understand our implementation and give us direct feedback.</p>
<h3>How about persistence?</h3>
<p>Somehow, many people see Domain Driven Design and Rich Domain Model as the same thing. It’s simply not true. A Rich Domain Model is the logical consequence of a DDD project, since everything is made explicit. And making things explicit means providing names, properties and behavior to concepts.</p>
<p>Another assumption often made is that Rich Domain Model means “put all logic in the domain”. Which is also not true. It’s not called a model for nothing. Using a model means you consciously leave things out of your domain, because they are either not relevant or not practical in your implementation.</p>
<p>In the OSIX project, we assigned the responsibility of retrieving and persisting objects to the application layer. This means the application services call on the Repository implementations to retrieve or save objects.</p>
<p>Furthermore, we decided to keep all modifications to the state of Entities inside the scope of the Application Layer. In the implementation, this meant two things. First of all, the Transactional boundary is located on the service layer, meaning that entities leaving the Application Service are detached from the persistence context, meaning that changes will not be seen by the persistence manager and are ignored. Secondly, the service layer will never accept an entity as a parameter. If an entity is needed, the application service will retrieve it based on its identity, which is passed as a parameter instead.</p>
<p>Some of the Application Service interfaces methods look as follows:</p>
<pre>
<pre class="brush: java;">
InternetSession startSession(final LocalDateTime startTime,
                             final UserName userName,
                             final BranchCode branchCode,
                             final IpAddress ipAddress);

void endSession(final long id,
                final LocalDateTime endTime,
                final BranchCode branchCode);
</pre>
</pre>
<p>All method parameters are value objects, and thus immutable, thread safe and the whole shebang. The startSession method returns en entity: InternetSession. If you wish to change the state of that object in a way that is useful to the application, you need to call another method (e.g. endSession) using the identity of the session, a long in this case. (Yes, in the case of “make it explicit”, SessionId would be a better name for it.)</p>
<p>The implementation of this application service is no rocket science either. It contains only little logic, since it delegates most of it to the domain objects themselves.</p>
<pre>
<pre class="brush: java;">
@Transactional
public void endSession(final long id,
                       final LocalDateTime endTime,
                       final BranchCode branchCode)
               throws NoSuchSessionException {

    InternetSession session = internetSessionRepository.loadSession(id);
    if (!session.getBranchCode().equals(branchCode)) {
        throw new NoSuchSessionException(&amp;amp;quot;This session belongs to another Branch&amp;amp;quot;);
    }

    if (session.isOpen()) {
        session.closeSession(endTime);
        internetSessionRepository.saveSession(session);
    }
}
</pre>
</pre>
<p>Line 7 shows the actual InternetSession entity being retrieved from the repository. In Hibernate/JPA terms this means the entity is attached to the PersistenceContext, and all changes are observed by the persistence manager.</p>
<p>Line 8-10 show some very simple validation logic to prevent sessions from another Branch being closed accidentally.</p>
<p>Line 12-14 do the calls to the actual business logic involving the closing of a session.</p>
<p>You could state that the Application Service is responsible of the orchestration of business logic execution. It doesn’t say anything about what the business logic actually means (e.g. what does it it mean that a session is open?).</p>
<h3>Conclusion</h3>
<p>In the end, DDD doesn’t really drastically change the way most applications are built. The most important change is the actual naming of objects and methods and the location of the business logic. However, this seemingly subtle change can have a big effect on the maintainability of your application.</p>
<p>Domain Driven Design is mainly about making things explicit, and doing so in the Ubiquitous Language.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/07/28/domain-driven-design-applied/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Project: welke.nl</title>
		<link>http://blog.jteam.nl/2009/07/23/project-welke-nl/</link>
		<comments>http://blog.jteam.nl/2009/07/23/project-welke-nl/#comments</comments>
		<pubDate>Thu, 23 Jul 2009 11:00:32 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Business]]></category>
		<category><![CDATA[Enterprise Search]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[Customer]]></category>
		<category><![CDATA[Empowerment]]></category>
		<category><![CDATA[Innovation]]></category>
		<category><![CDATA[Search]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/?p=468</guid>
		<description><![CDATA[The Welke Magazine has been around for a while now and is a well-established name in the home decoration area. To follow up on the success of their paper version, MediaMij –the company publishing these magazines– decided to expand their position in the market by launching an electronic version, welke.nl. The goal of this website [...]]]></description>
			<content:encoded><![CDATA[<p>The Welke Magazine has been around for a while now and is a well-established name in the home decoration area. To follow up on the success of their paper version, <a href="http://www.mediamij.nl/" target="_blank">MediaMij</a> –the company publishing these magazines– decided to expand their position in the market by launching an electronic version, <a href="http://www.welke.nl" target="_blank">welke.nl</a>. The goal of this website was to give their readers a more interactive experience and allow them to find more products that could be of interest in an intuitive manner.</p>
<p>In this post, I will focus on some technical and organizational topics that were addressed during the project.<span id="more-468"></span></p>
<h3>Search and data import</h3>
<p>The initial version of welke.nl contained two major parts: the product database and articles. A Content Management System (CMS) has been implemented to help the authors and publishers manage the content on the website.</p>
<p>The product database, however, required more specific features than the CMS could offer out-of-the-box. To enhance the customer experience, welke.nl visitors have to be able to filter through the available products to limit the selection to only those products that are of interest to them. To enable this, we used something called facetted navigation (or attribute-based search). Facetted navigation provides a very intuitive view on the current data set by showing the values of several, well-picked attributes of the search results including the number of products that match for that attribute value. By choosing one of those <em>facets</em>, the search result are then further limited to only results that match that value. This allows users to easily drill down the entire data set and has the added value that users will never get to an empty search results set. Next to normal values (e.g. choosing a specific brand) some facets allow you to choose a range (e.g. price) or multiple selections (e.g. color).  You can see a working example on <a href="http://badkamers.welke.nl/producten/baden.html" target="_blank">the website</a>.</p>
<p>Another major difference between the product database and the articles section is the way data is inserted. MediaMij maintains close contact with their main suppliers in the Netherlands and helps them write interesting articles about new products. The suppliers provide the data to MediaMij in files containing the details of all their products. These files are imported into the CMS using a simple tool and subsequently synchronized with the search engine to allow users to access the information.</p>
<h3>Empowerment</h3>
<p>Welke.nl is divided into several domains, based on the types of products that are offered. The <a href="http://badkamers.welke.nl" target="_blank">bathroom domain</a> was chosen as the first domain to be developed. In addition to the JTeam project staff, two MediaMij developers were included in the development of this first domain. As part of the project, so during the development, we coached them and trained them in the use of the frameworks and technologies that we used on the project. The idea behind this <em>empowerment</em> is that MediaMij could continue development of other domains independent of JTeam.</p>
<p>Only several weeks after the successful launch of the bathroom domain, the <a href="http://keukens.welke.nl/" target="_blank">kitchen domain</a> was developed and launched with only limited support from JTeam. The subsequent development and launch of the <a href="http://haarden.welke.nl" target="_blank">fireplace domain</a> was done by MediaMij without any support from JTeam at all. This proved to the customer that our empowerment approach had indeed worked. In fact, JTeam is not involved at all in the development of the remaining domains, allowing us to focus on more advanced features the client would like to see implemented (for all domains).</p>
<p>The result, a happy customer, who is able to quickly move into new domains, without any dependency on JTeam, so no vendor lock-in. And in turn, JTeam can help the customer on the more technically challenging area’s.</p>
<h3>Going further…</h3>
<p>Development continues on the JTeam side, implementing some additional requirements. Currently, we are in the process of implementing  dealer locator functionality, basically a location-based search. This allows users to search for dealers of products that are nearest to them, based on a location they provide. Luckily, JTeam previously implemented similar functionality for <a href="http://www.ilocal.nl">iLocal</a>. Of course this location-based search functionality will be fully integrated with the existing product database and CMS.</p>
<h3>Conclusion</h3>
<p>We can conclude that the empowerment approach has helped the customer in becoming independent in the maintenance of their new website. They no longer rely on the availability of JTeam personnel to make changes or even expand to new domains. Moreover, it also allowed us to focus on the innovative areas and help improve their customer experience even more.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/07/23/project-welke-nl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The misunderstanding of Domain Driven Design</title>
		<link>http://blog.jteam.nl/2009/05/10/the-misunderstanding-of-domain-driven-design/</link>
		<comments>http://blog.jteam.nl/2009/05/10/the-misunderstanding-of-domain-driven-design/#comments</comments>
		<pubDate>Sun, 10 May 2009 15:11:04 +0000</pubDate>
		<dc:creator>Allard Buijze</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Domain Driven Design]]></category>

		<guid isPermaLink="false">http://blog.jteam.nl/2009/05/10/the-misunderstanding-of-domain-driven-design/</guid>
		<description><![CDATA[There seem to be two mainstream approaches in Java application development: the domain driven approach, and the “fat service layer” or Transaction Script approach. As an architect, I’ve been investigating both methodologies by reading about both of them and applying them in real life enterprise projects. It is at the least amusing to see how [...]]]></description>
			<content:encoded><![CDATA[<p>There seem to be two mainstream approaches in Java application development: the domain driven approach, and the “fat service layer” or <a href="http://martinfowler.com/eaaCatalog/transactionScript.html" target="_blank">Transaction Script</a> approach. As an architect, I’ve been investigating both methodologies by reading about both of them and applying them in real life enterprise projects. It is at the least amusing to see how followers of each approach think of the other. An example of how developers (disappointing to realize that these people are co-developers) react on each other&#8217;s approach can be seen in the <a href="http://www.theserverside.com/news/thread.tss?thread_id=42602" target="_blank">reactions to Arjen Poutsma’s post</a>.</p>
<p><span id="more-115"></span></p>
<p>In some discussions I recently had with developers as well as other architects, I noticed that Domain Driven Design and Rich Domain Model  are interpreted as “put <em>everything</em> in the domain model”. This means (according to some of them) that each object should have a “save” method to persist its state, external systems calls are initiated by the domain objects, and so on and so forth. I have to agree with them that such an approach would not be practical at all. All it would lead to is bloated domain objects of which the real purpose is hidden in hundreds of lines of boilerplate code. However, I don’t believe that Domain Driven Design is about any of this at all. And looking at Eric Evans’ (the writer of the book Domain Driven Design) <a href="http://domaindrivendesign.org/examples#sampleApp" target="_blank">sample application</a>, my thoughts are confirmed.</p>
<p>Domain Driven Design is an approach that describes the approach to designing the business layer. It doesn’t say much about the other layers of an application. The main advice is to base the domain model on the language your customer uses: the ubiquitous language. This means that you should not have a method “setAddress” on a Customer instance if your customer talks about “register a relocation”. In fact, the last application I developed hardly contained any setter on any domain instance at all.</p>
<p>You might wonder what happened to the other layers if DDD is really only about the business layers. Well, the service layer is still what it was, although it tends to contain less code. All that is needed in the service layer is to retrieve the correct domain instance(s) from the repository, call the appropriate methods on them and persist their new state by placing them back in the repository. With this approach, the logic of changing the state is located where the state is kept, in the domain object. The application logic, such as persistence, transactions, calling external application, raising application events, is placed in the service layer.</p>
<p>During one of my discussions, somebody pointed out that according to the Domain Driven Design book one should only create a service if the logic cannot be placed in any of the domain objects. Well, the book does say that, but the service the book talks about is not the type of service that you find in the service layer. The book talks about Domain Services. Whether you decide to use one of these services is completely independent of the use of services in the service layer, which are also referred to as application services.</p>
<p>I can conclude that applications where domain driven design has been applied are not really that different from other applications, with the exception of the domain model itself. However, this richer model tends to make applications more maintainable and easier to understand as the model exposes the language that the customer actually uses. So, in the end, Domain Driven Design does not have to be as scary as many people think. It is just, as one of my colleagues pointed out, a set of best practices for Object Oriented design.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jteam.nl/2009/05/10/the-misunderstanding-of-domain-driven-design/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
