<?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>brettdargan.com &#187; Patterns</title>
	<atom:link href="http://brettdargan.com/blog/category/patterns/feed/" rel="self" type="application/rss+xml" />
	<link>http://brettdargan.com/blog</link>
	<description>Thoughts and rants</description>
	<lastBuildDate>Fri, 28 May 2010 01:35:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>RIMVR and HATEOAS: MVC+URITemplateAspects, LinkAwareModels and LinkTemplateProcessors</title>
		<link>http://brettdargan.com/blog/2009/04/29/rimvr/</link>
		<comments>http://brettdargan.com/blog/2009/04/29/rimvr/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 12:24:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://brettdargan.com/blog/?p=337</guid>
		<description><![CDATA[There has been a discussion titled [Jersey] Putting the RESTful "connectedness" around my existing Domain objects on the jersey mailing list that is starting up again.
I don't think I have confused HATEOAS with "connectedness", I have a reasonable understanding of resource state, application state and HATEOAS.
See http://www.stucharlton.com/blog/archives/000141.html and this discussion, http://tech.dir.groups.yahoo.com/group/rest-discuss/message/12497, which I see you [...]]]></description>
			<content:encoded><![CDATA[<p>There has been a discussion titled <a href="https://jersey.dev.java.net/servlets/ReadMsg?list=users&#038;msgNo=5657">[Jersey] Putting the RESTful "connectedness" around my existing Domain objects</a> on the jersey mailing list that is starting up again.</p>
<p>I don't think I have confused HATEOAS with "connectedness", I have a reasonable understanding of resource state, application state and HATEOAS.</p>
<p>See <a href="http://www.stucharlton.com/blog/archives/000141.html">http://www.stucharlton.com/blog/archives/000141.html</a> and this discussion, <a href="http://tech.dir.groups.yahoo.com/group/rest-discuss/message/12497">http://tech.dir.groups.yahoo.com/group/rest-discuss/message/12497</a>, which I see you have contributed to.</p>
<p>I think this final point made by <a href="http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven">Roy</a> is pretty applicable here:</p>
<blockquote><p>
A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience (i.e., expected to be understood by any client that might use the API). From that point on, <b>all application state transitions must be driven by client selection of server-provided choices that are present in the received representations or implied by the user’s manipulation of those representations</b>. The transitions may be determined (or limited by) the client’s knowledge of media types and resource communication mechanisms, both of which may be improved on-the-fly (e.g., code-on-demand). [Failure here implies that out-of-band information is driving interaction instead of hypertext.]
</p></blockquote>
<p><b>My point is you can't adhere to the HATEOAS constraint, without providing links between resources</b> so the server can guide the client to other application states.</p>
<p>I agree that forms are a better example for explaining state transitions, especially since resource state is likely to be changed by providing forms (as will the User Agent, as Roy mentions); or equivalent form templates/prototypes for other media types.<br />
But to me providing forms or equivalents for other media types is a different and easier problem to solve.</p>
<p>I'm very interested in <b>how to evolve existing systems</b>; I want to leverage the <b>vast islands of information</b> that already exist. </p>
<p>I just want to do it in an elegant way from a <b>code</b> and a <b>web perspective</b>, including the fact that uri's shouldn't change.<br />
<div id="attachment_338" class="wp-caption alignleft" style="width: 310px"><a href="http://brettdargan.com/blog/wp-content/uploads/2009/04/hateoas_4_legacy.jpg"><img src="http://brettdargan.com/blog/wp-content/uploads/2009/04/hateoas_4_legacy-300x225.jpg" alt="RIMVR: MVC + URITemplateAspects; LinkAwareModels and LinkTemplateProcessor" title="hateoas_4_legacy" width="300" height="225" class="size-medium wp-image-338" /></a><p class="wp-caption-text">URITemplateAspects; LinkAwareModels and LinkTemplateProcessor</p></div></p>
<p>In a standard, layered design, you would have these components (see <a href="http://brettdargan.com/blog/wp-content/uploads/2009/04/hateoas_4_legacy-300x225.jpg">Image</a>):</p>
<p>1. Code-On-Demand<br />
2. View<br />
3. Controller<br />
4-6. Contains the Proposed Abstractions<br />
7. Model<br />
8. Persistent Store - Db; file; jcr; webdav<br />
9. Proxies</p>
<p>Here are some options I have for adding links around some existing system (there are likely more)</p>
<p>Due to the time constraints, the Pros, will be sparse.</p>
<h3>Option 1: Add Links via Code-On-Demand.</h3>
<p>Add links to my html page via javascript.<br />
I could take my existing html representation and use dhtml to add links.</p>
<p>Cons:<br />
* code-on-demand not available for all user agents or may be disabled<br />
* Proxies can't cache the entire representation<br />
* leak of possible application states to clients that don't need to know<br />
* Detailed knowledge of resource and subresources required to provide "link rich" representations<br />
* Alternative media types may require alternative languages or structure to perform add the links. ie. use of xsl for xml; javascript with svg.</p>
<h3>Option 2: Add Links via Views</h3>
<p>Cons:<br />
* We all know this is bad<br />
* Detailed knowledge of resource and subresources required to provide "link rich" representations<br />
* different views/media types require the same logic and detailed knowledge of the model<br />
* different views/media types may require some application state knowledge. an admin user may have other links than anon.</p>
<h3>Option 3: Add Links via Controllers</h3>
<p>Pros:<br />
* Can handle the inclusion/exclusion of links depending on the current application state, regardless of the media type to respond with </p>
<p>Cons:<br />
* Detailed knowledge of resource and subresources required to provide "link rich" representations</p>
<h3>Option 4: Add Links via Models</h3>
<p>Pros:<br />
* Detailed knowledge of the model and related models belong in the Model</p>
<p>Cons:<br />
* Detailed knowledge of resource links aren't the domain of the models<br />
* Not all possible related models are likely to be represented; to balance performance with types of usage, often some relationships are not modelled, so as to not eager load, very large graphs etc.<br />
* Links are very static, The "next available" application state, still needs to be determined in another layer, like Controller</p>
<h3>Option 5: Add Links via Persistent Store</h3>
<p>Store partial links in the db </p>
<p>Pros:<br />
* Db driven, easy to update<br />
* Tables have relationships<br />
* easy adoption path<br />
* easy to link to external resources, or resources outside your db schema<br />
* easy to share links at db level, if several systems integrate at that level<br />
* Good for sparse relationships. </p>
<p>Cons:<br />
* Update to change a link, will not play nice with intermediaries nor "cool uris, that don't change"<br />
* Not great for <b>consistent dense relationships</b>, you probably want to model that differently. So with a Parent Child relationship, you wouldn't want something in addition to existing foreign key relations, to redundantly specify that to get to the children of a parent you have a list of /child/xyz links. but by having that specified in the URITemplateAspect then you are managing that once, close to the data.<br />
* Relationships are not always defined in Foreign Keys<br />
* Links are very static, The "next available" application state, still needs to be determined in another layer, like Controller<br />
* Only a partial solution for more dynamic aspect of determining what application states make sense, still needs to be done in another layer.<br />
* May be invasive, links stored in columns or other tables, no good if you've got a locked down schema.</p>
<h3>Thoughts</h3>
<p>Models shouldn't have relationships to hardcoded resources, like "/resource/50", but they could have a semantic relationship to "/resource/{id}" or "/resource/{id};role={role}" under certain conditions.</p>
<p>There is a place for such LinkAwareModels (Component no. 5), as long as the links are isolated and only contain semantic relationships, they are not urls.</p>
<p>The Links from Models to Resources are isolated and encapsulated within its own abstraction; which gives us component no. 6 URITemplateAspects (maybe just simplify this to LinkTemplateAspect).</p>
<p>Possible "Application States" are dependent on the request, even though a request must be STATELESS, possible "Application States" may still be determined by the security access; restrictions of media-types or client, which should all be part of the request. If you do stuff with user roles, then make sure you encode within your url.</p>
<p>Component no. 4 is our LinkTemplateProcessor(s) and its responsibility is to evaluate URITemplates within the LinkAwareModels/entities and to determine appropriate state transitions based on the request.</p>
<p>This leads us to the final Option ( well, for this post <img src='http://brettdargan.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  )</p>
<h3>Option 6: Semantic relationships of a "Model to resources" definied via URITemplateAspect and a LinkTemplateProcessor to evaluate the relationships (URITemplates) and sub-entities to determine other "application states"</h3>
<p>Pros:<br />
* Detailed knowledge of the model and related models belong in the Model<br />
* Detailed knowledge of the model to resource of interest is a concern isolated in the URITemplateAspects<br />
* Any possible relationships to other resources can be defined<br />
* Links are very dynamic. The possible state transitions can be determined by the LinkTemplateProcessor, but it can do so decoupled from the detailed relationships of the model to other resources. </p>
<p>The semantic relationships that are defined in the LinkAwareModels, can include uri and other attributes, like rel. The LinkTemplateProcessor can evaluate a lot of the current application state (but not all as the User Agent may have representations from other servers or representations that have been modified by Code-On-Demand) in combination with the semantic relationship to determine the ultimate value of the link to use (relative preferred, of course) and it can determine if that link is a valid state transition. Only if you are an admin do you see this link; or the link retains the current media-type used for this request; so a request for /country/AU.html includes links to cities.html, not just cities. The default negotiation might be something if that is not specified.</p>
<p>* The Processor can operate on objects, prior to rendering to a particular media-type, so if you have a single object model that can render to multiple media-types, you could have less code</p>
<h3>Conclusion</h3>
<p>What do you call, this, maybe Rich Interconnected Model View Resource RIMVR.<br />
Rich in relation to having deep links within a resource representation and from the applicability of those links. That actual uri templates are evaluated late and with some context of the request and application state.</p>
<p>The use of these abstractions, <b>in no way make an application RESTful, that is up to the developers</b>, but hopefully by following some abstractions, like these we will get some clean code and some better understanding of RESTful APIs.</p>
<p><a href="http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/">I have some old code, to show this working.</a><br />
One day I'll get a chance to clarify terms and simplify the code <img src='http://brettdargan.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=RIMVR+and+HATEOAS%3A+MVC%2BURITemplateAspects%2C+LinkAwareModels+and+LinkTemplateProcessors+http://3z75n.th8.us" title="Post to Twitter"><img class="nothumb" src="http://brettdargan.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=RIMVR+and+HATEOAS%3A+MVC%2BURITemplateAspects%2C+LinkAwareModels+and+LinkTemplateProcessors+http://3z75n.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://brettdargan.com/blog/2009/04/29/rimvr/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HATEOAS for legacy object models</title>
		<link>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/</link>
		<comments>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/#comments</comments>
		<pubDate>Tue, 13 Jan 2009 15:44:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[RESTful]]></category>
		<category><![CDATA[Web]]></category>
		<category><![CDATA[aop]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[hateoas]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://brettdargan.com/blog/?p=196</guid>
		<description><![CDATA[




One of the best aspects of RESTful orientated services is getting your resources connected, possibly even achieving HATEOAS. Making that jump with with legacy object models or data can be tricky, depending on how intrusive you want to be.
There is such a large amount of legacy data in various forms, usually with minimal links/relations that [...]]]></description>
			<content:encoded><![CDATA[
<div class="document">


<!-- -*- mode: rst -*- -->
<p>One of the best aspects of RESTful orientated services is getting your resources connected, possibly even achieving HATEOAS. Making that jump with with legacy object models or data can be tricky, depending on how intrusive you want to be.</p>
<p>There is such a large amount of legacy data in various forms, usually with minimal links/relations that could be leveraged.</p>
<p>So it is a worthy challenge to try and do it in the least intrusive manner possible.</p>
<p>This is one approach that is reasonably decoupled from an existing legacy model.</p>
<p>There are three main parts to this technique:</p>
<ol class="arabic simple">
<li>Enhance your model objects so they have a placeholder/collection so you can accumulate links</li>
<li>Annotate your model at interesting points with <strong>link templates</strong>, around attributes or methods or classes</li>
<li>Use a custom <a class="reference external" href="http://jersey.dev.java.net&quot;">ContainerResponseFilter</a> class of jersey to scan for annotations of interest, then evaluate your link templates (at run time), using the data of your models and any request based information you may require.</li>
</ol>
<p>I chose to enhance my model classes using <a class="reference external" href="http://eclipse.org/aspectj">AspectJ</a> at compile time.</p>
<p><a class="reference external" href="http://brettdargan.com/blog/wp-content/uploads/2009/01/hateoas4legacytar.bz2">Download the source</a></p>
<div class="codeblock"><div class="highlight"><pre>mvn glassfish:run
./curl_test #will hit two urls
</pre></div>
</div><p>and you should see some results, with links like this:</p>
<div class="codeblock"><div class="highlight"><pre><span style="color: #BC7A00">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;country</span> <span style="color: #7D9029">xmlns:ns2=</span><span style="color: #BA2121">&quot;http://www.w3.org/1999/xlink&quot;</span><span style="color: #008000; font-weight: bold">&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;links&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span> <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span>
        <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/cities/Brisbane&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/cities/Sydney&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/cities/Melbourne&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/countries/AU&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;/links&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;cities&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;city&gt;</span>
      <span style="color: #008000; font-weight: bold">&lt;links/&gt;</span>
      <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Brisbane<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;/city&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;city&gt;</span>
        <span style="color: #008000; font-weight: bold">&lt;links/&gt;</span>
        <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Sydney<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;/city&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;city&gt;</span>
      <span style="color: #008000; font-weight: bold">&lt;links/&gt;</span>
      <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Melbourne<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;/city&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;/cities&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;isoCode&gt;</span>AU<span style="color: #008000; font-weight: bold">&lt;/isoCode&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Australia<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;/country&gt;</span>
</pre></div>
</div><p>All countries Results</p>
<div class="codeblock"><div class="highlight"><pre><span style="color: #BC7A00">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;countries&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;country</span> <span style="color: #7D9029">xmlns:ns2=</span><span style="color: #BA2121">&quot;http://www.w3.org/1999/xlink&quot;</span><span style="color: #008000; font-weight: bold">&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;links&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/countries/AU&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;/links&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;cities/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;isoCode&gt;</span>AU<span style="color: #008000; font-weight: bold">&lt;/isoCode&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>Australia<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;/country&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;country</span> <span style="color: #7D9029">xmlns:ns2=</span><span style="color: #BA2121">&quot;http://www.w3.org/1999/xlink&quot;</span><span style="color: #008000; font-weight: bold">&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;links&gt;</span>
    <span style="color: #008000; font-weight: bold">&lt;link</span> <span style="color: #7D9029">rel=</span><span style="color: #BA2121">&quot;&quot;</span>
        <span style="color: #7D9029">ns2:type=</span><span style="color: #BA2121">&quot;locator&quot;</span> <span style="color: #7D9029">ns2:href=</span><span style="color: #BA2121">&quot;http://localhost:8080/hateoas4legacy/rs/countries/USA&quot;</span><span style="color: #008000; font-weight: bold">/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;/links&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;cities/&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;isoCode&gt;</span>USA<span style="color: #008000; font-weight: bold">&lt;/isoCode&gt;</span>
  <span style="color: #008000; font-weight: bold">&lt;name&gt;</span>United States of America<span style="color: #008000; font-weight: bold">&lt;/name&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;/country&gt;</span>
<span style="color: #008000; font-weight: bold">&lt;/countries&gt;</span>
</pre></div>
</div><p>It is very crufty, but does work in the simple cases.
I haven't had a chance to demonstrate all of the features yet.</p>
<p>I'm likely to further flesh out this example as it is interesting in other RESTful related ways.</p>
</div>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=HATEOAS+for+legacy+object+models+http://ysfqw.th8.us" title="Post to Twitter"><img class="nothumb" src="http://brettdargan.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=HATEOAS+for+legacy+object+models+http://ysfqw.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://brettdargan.com/blog/2009/01/14/hateoas-for-legacy-object-models/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Experimental Java Circuit Breaker Pattern Implementation</title>
		<link>http://brettdargan.com/blog/2007/12/15/experimental-circuit-breaker-pattern-implementation/</link>
		<comments>http://brettdargan.com/blog/2007/12/15/experimental-circuit-breaker-pattern-implementation/#comments</comments>
		<pubDate>Fri, 14 Dec 2007 15:24:46 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Stability, Performance and Monitoring]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://brettdargan.com/blog/2007/12/15/experimental-circuit-breaker-pattern-implementation/</guid>
		<description><![CDATA[I read "Release It" recently, not a bad book, some good stories, I wish more people would pay attention to things like Stability and Capacity.
Anyway I liked the Circuit Breaker pattern, as I've seen a number of apps with highly coupled systems that barf once latency increases in the back ends then you get "Cascading [...]]]></description>
			<content:encoded><![CDATA[<p>I read <a href="http://www.pragprog.com/titles/mnee" title="Release It">"Release It"</a> recently, not a bad book, some good stories, I wish more people would pay attention to things like Stability and Capacity.</p>
<p>Anyway I liked the Circuit Breaker pattern, as I've seen a number of apps with highly coupled systems that barf once latency increases in the back ends then you get "Cascading Failures" and the webapp's request handler thread pool is exhausted and they all wait their mandatory 30 seconds for a response. Eventually the app either dies, or gets taken out of a load balance farm causing a "Chain Reaction".</p>
<p>Here is an <a href="http://brettdargan.com/blog/wp-content/uploads/2007/12/circuit_breaker.tgz" title="Experimental Circuit Breaker Implementation (circuit_breaker.tgz)">Experimental Circuit Breaker Implementation (circuit_breaker.tgz)</a> , <strong>NOT built or tested FOR PRODUCTION use in anyway</strong>. There is explicity no thread safety no the actual CircuitBreakerSimple class.</p>
<p>download, extract and run ant.</p>
<p>Play around with the parameters to see the affect. Generally it seems to thrash more with increased concurrent threads and interestingly in jdk1.6 sometimes reverts to the default timeout instead of the instance value.</p>
<p>Based roughly on the following logic:<br />
When Circuit is Closed:<br />
on call = pass through<br />
call succeeds = reset count<br />
call fails = count failure<br />
threshold reached = trip breaker. Open State</p>
<p>when Circuit is Half-Open<br />
on call = pass through<br />
call succeeds = reset go. Close State<br />
call fails = trip breaker. Open State</p>
<p>when Circuit is Open<br />
on call = return/fail<br />
on timeout = attempt reset. Half-Open State</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Experimental+Java+Circuit+Breaker+Pattern+Implementation+http://si2ri.th8.us" title="Post to Twitter"><img class="nothumb" src="http://brettdargan.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Experimental+Java+Circuit+Breaker+Pattern+Implementation+http://si2ri.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://brettdargan.com/blog/2007/12/15/experimental-circuit-breaker-pattern-implementation/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>System Management Patterns</title>
		<link>http://brettdargan.com/blog/2005/07/01/system-management-patterns/</link>
		<comments>http://brettdargan.com/blog/2005/07/01/system-management-patterns/#comments</comments>
		<pubDate>Thu, 30 Jun 2005 21:13:44 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Stability, Performance and Monitoring]]></category>
		<category><![CDATA[design]]></category>

		<guid isPermaLink="false">http://brettdargan.com/blog/?p=49</guid>
		<description><![CDATA[Recently the client I've been working towards using webservices with third parties and this has partly prompted me to articulate a couple of potential System Management Patterns. I've asked google and not found any related articles, so here goes.
System Management Patterns Overview

Collect Correlated System Metrics
Gather and store correlated system metrics.
The essence of this pattern is [...]]]></description>
			<content:encoded><![CDATA[<p>Recently the client I've been working towards using webservices with third parties and this has partly prompted me to articulate a couple of potential System Management Patterns. I've asked google and not found any related articles, so here goes.</p>
<p>System Management Patterns Overview<br />
<a href="http://brettdargan.com/blog/wp-content/uploads/2007/08/patterns-overiew.png" title="System Management Patterns Overview"><img src="http://brettdargan.com/blog/wp-content/uploads/2007/08/patterns-overiew.png" alt="System Management Patterns Overview" border="0" height="412" width="686" /></a></p>
<h3><a title="CollectCorrelatedSystemMetrics" name="CollectCorrelatedSystemMetrics"></a>Collect Correlated System Metrics</h3>
<p>Gather and store correlated system metrics.</p>
<p>The essence of this pattern is enable collection of multiple correlated data points over time to provide a picture of the system components that can be analysed at all interesting layers. Enabling better informed business, architectural and design decisions about the system or it's components.</p>
<p>The necessity of this pattern grows as we handle the web's bursty traffic nature and rely on more distributed services. I cannot over state the significant value this provides that will flow through the organisation and it's partners.</p>
<h4>How it Works</h4>
<p>Identify what components make up your system, what dependencies there are and start from the bottom of the pyramid.<br />
<a href="http://brettdargan.com/blog/wp-content/uploads/2007/08/pattern-ccsm.png" title="Correlated System Metrics"><img src="http://brettdargan.com/blog/wp-content/uploads/2007/08/pattern-ccsm.png" alt="Correlated System Metrics" border="0" height="259" width="364" /></a></p>
<p>There are many mature tools and protocols that already provide monitoring at the  Operating System level.</p>
<p>Depending on what container or virtual machine you have they may support the defacto industry standard for monitoring.</p>
<p>Track major data points within your application. For a Web based retailer there are particular areas that would be important, such as Inventory Searches, Purchasing, third party dependencies, like Payment System Providers.</p>
<h4>Using It</h4>
<ul>
<li>Collect correlated system metrics in real-time. Log file analysis has a longer feedback loop, can introduce correlation issues, easily lost or overwritten and doesn't scale well as more system components are added.</li>
<li>Use it often, resolve problems with collection as a high priority, the value it provides decrease as reliability of results or collection.</li>
<li>Prefer the collection of raw data points over aggregated data where possible as you need to make arbitrary choice of aggregation which may prevent the use of the metric with other metrics.  If you were measuring response time for a service serving many concurrent clients, you could track, hitcount and total response time or you may track hitcount and avg. response time over what: period of time, or last x hits?&gt;</li>
<li>Think about coverage, do you have too much? Do you have too little? Don't get too much information, avoid paralysis by analysis.</li>
<li>Think about your system, it is alive, it constantly changes, whether that is code, hardware, os or business usage, everyday is unique!</li>
<li>Don't blindly trust the statistics you have, occasionally, independently verify important statistics, does not have to be exact, could use back of the envelope calculations.</li>
<li>Serious usage may warrant a separate network.</li>
</ul>
<h4>Example</h4>
<p>The technology to support the implementation of this has been around for years<br />
and is mature in the infrastructure layer of a system. There are several network management applications that build upon <a href="http://www.ietf.org/rfc/rfc1157.txt" title="Simple Network Management Protocol">SNMP</a> and <a href="http://people.ee.ethz.ch/~oetiker/webtools/rrdtool/">Round Robin Database Tool</a> to collect real time data and specify a suitable granularity of aggregation to limit archive size, yet still allow queries to be performed.</p>
<p>SNMP monitoring has recently been added to the Java JVM itself. At the application level there are several snmp implementations that could be used to enable a poller, or statistics collector to query your app for certain metrics.</p>
<p>So it is possible to create a system view that spans the Operating System (cpu, disk, network adaptors), Virtual Machine, Container and your application.</p>
<h4>Reap the Benefits</h4>
<p>Knowledge of your approximate workload is the first step.</p>
<p>The benefits flow from the day to day operational aspects to the CIO assuming sufficient coverage has been implemented. Operations/Production Support have an increased ability to diagnose issues, they can identify cause and affect immediately after a change instead of guessing, to the strategic end of town. Better diagnosis of issues, may only be to the extent that significant time is not wasted looking in an area that is not causing the problem. In many cases it will highlight what component is or is not causing a problem and further analysis of the <a href="#CorrelatedComponentSnapshot">Correlated Component Snapshot</a> needs to be investigated.</p>
<p>Developers can use those numbers to <a href="ScalingApproximateWorkload">approximate workload and test large scale changes to the system</a>, like changing operating systems, changing databases, doubling inventory etc.</p>
<ul>
<li>CIO, can get more confident answers to:<br />
What is the <a href="#Fowler" title="see [Fowler] for performance terms">load sensitivity</a> to the system, if we double inventory? What happens if we introduce a promotion that is likely to increase traffic 10 times for the length of the promotion? How much hardware do we need to purchase to support these loads?</li>
<li>Technical Operations Manager, are my servers up? What happened at 13:00, to spike cpu usage by 20%? Is load within reasonable? limits? Are there errors on any devices? We changed disk arrays and performance has decreased?</li>
<li>Production Support, should have a dashboard of important points usually spanning all layers. They can ask questions like: Hey we requested a that package xyz be upgraded and response time of service abc has doubled?</li>
<li>Development Team, the real workload is alot different to what everyone anticipated. Do we need to focus on a different area? Do we need to add or tune caches?</li>
</ul>
<h3><a title="CorrelatedComponentSnapshot" name="CorrelatedComponentSnapshot"></a>Correlated Component Snapshot</h3>
<p>Collect correlated detailed information of a System Component.</p>
<h4>How it Works</h4>
<p>Periodically collect detailed correlated information about your System Component . Let you travel back in time to see what happened to a component, maybe even to see the cause of the resulting affect. It is useful for diagnosing system problems in both production as well as determining and removing bottlenecks when <a href="#ScalingApproximateWorkload">Scaling Approximate Workload</a>.</p>
<h4>Using It</h4>
<ul>
<li>Gather and store detailed correlated information of a System Component.<br />
Collected periodically based on a balance of component usage, gathering cost. 20 minute i is a good rule of thumb</li>
<li>A listing of top running processes at that point in time.</li>
<li>A database server, may have information such as locking transactions, long running transactions, database specific internal statistic reports.</li>
<li>Typically recent data would be stored. Older data to be archived or removed.</li>
</ul>
<h3><a href="ScalingApproximateWorkload">Scaling Approximate Workload</a></h3>
<p>Build tests that can approximate the real workload or your system.</p>
<h4>How it Works</h4>
<p>Having the ability to scale an approximate workload of your system that is monitored via <a href="CollectCorrelatedSystemMetrics">Collect Correlated SystemMetrics</a> provides the ability to really see what is happening to the system when changes occur. It provides the final metrics by which changes to components or workload can analysed and simulated.</p>
<p>This enables developers to simulate and answer "What If?" type of questions.</p>
<h4>Using It</h4>
<ul>
<li>Build read only tests and read-write tests of vital functions. Read-only tests will provide a further level of approximation without the extent of data management imposed by the read-write test.</li>
<li>The tests must be written in a loosely coupled way, to enable simple scaling up of workload. They are intended to be used by a tool that allows simple manipulation of scaling parameters, such as number of clients, number of hits per hour etc.</li>
<li>Approximate data usage as well as functionality usage. While randomness of data is important, significant data distribution should reflected in you most important tests. Don't randomly choose products if a product category represents significant proportions of browsing or searching. If 50% of products browsed are from 1 product category then weight it accordingly.</li>
</ul>
<h3><a title="Ping" name="Ping"></a>Ping</h3>
<p>Is your service platform alive and what is the upper bound performance limit [Bulka] I could potentially achieve from a service on your platform at this time.  This gives meaning to the efficiency of system components under real or approximate workloads when monitored via <a href="#CollectCorrelatedSystemMetrics">Collect Correlated System Metrics</a></p>
<h4>How it Works</h4>
<p>A simple service of your service platform that does nothing, but returns immediately with a suitable response. Requires that a Ping service on the service platform be implemented.</p>
<p>In the case of a Servlet this may be an empty html form with a 200 response code. In the case of a webservice it responds in a similar way, perhaps with application specific response codes as well. In the case of a virtual machine you may be pinging a synchronized resource, to check it's liveness [Lea].</p>
<h4>Using It</h4>
<ul>
<li>This can be used for internal components and more beneficially for external third party components.</li>
<li>Very effective in helping to determine where limiting factors lay; virutal machines, operating systems, design or architecture of a system</li>
<li>Dynamically adjust your system to reduce workload on third parties. As webservices adoption grows businesses will become even more reliant on responsiveness of third party partners. In an ideal world any third party systems will be able to handle any load your system can throw at it. But in site that is growing exponentially, partners may not have the inclination, contractual obligation or capabilities to scale as fast as your organisation. It is most likely the case that some messages are more important than others and that changing the workload you place on their system, or altering practices to accomodate cyclic degradation in their system could be very beneficial.</li>
</ul>
<h4>References</h4>
<p>[Bulka] <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0201704293/qid=1120167799/sr=8-2/ref=sr_8_xs_ap_i2_xgl14/104-7932080-7784733?v=glance&amp;s=books&amp;n=507846">Java Performance and Scalability, Volume 1</a></p>
<p><a title="Fowler" name="Fowler"></a>[Fowler] <a href="http://www.amazon.com/exec/obidos/tg/detail/-/0321127420/104-3299664-3518357?v=glance">Patterns of Enterprise Architecture</a></p>
<p>[Lea]<br />
<a href="http://www.amazon.com/exec/obidos/tg/detail/-/0201310090/qid=1120188315/sr=8-1/ref=pd_bbs_ur_1/104-3299664-3518357?v=glance&amp;s=books&amp;n=507846">Concurrent Programming in Java(TM): Design Principles and Pattern (2nd Edition)</a></p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=System+Management+Patterns+http://h9nnf.th8.us" title="Post to Twitter"><img class="nothumb" src="http://brettdargan.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=System+Management+Patterns+http://h9nnf.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://brettdargan.com/blog/2005/07/01/system-management-patterns/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Antipatterns: Mixing Reporting and Data Entry functions. What the?</title>
		<link>http://brettdargan.com/blog/2004/12/07/antipatterns-mixing-reporting-and-data-entry-functions-what-the/</link>
		<comments>http://brettdargan.com/blog/2004/12/07/antipatterns-mixing-reporting-and-data-entry-functions-what-the/#comments</comments>
		<pubDate>Tue, 07 Dec 2004 12:04:29 +0000</pubDate>
		<dc:creator>bdargan</dc:creator>
				<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Antipatterns]]></category>

		<guid isPermaLink="false">http://brettdargan.com/blog/?p=20</guid>
		<description><![CDATA[Could this smell any worse?
The current project I'm working on is slowly replacing an existing system and one of the worst smells we've come across is the mixing of Reporting and Data Entry functions in an application.
Firstly the Searching/Reporting is time consuming (5-60secs+) full table scans on their order tables including filtering on obscure low [...]]]></description>
			<content:encoded><![CDATA[<p>Could this smell any worse?</p>
<p>The current project I'm working on is slowly replacing an existing system and one of the worst smells we've come across is the mixing of Reporting and Data Entry functions in an application.<br />
Firstly the Searching/Reporting is time consuming (5-60secs+) full table scans on their order tables including filtering on obscure low cardinality columns which were often derived or dependant on child table row existence...</p>
<p>The table in question is the primary order entry table for the business, so it has alot of contention already.</p>
<p>To make matters worse they are currently using SQL Server which has a proven incredibly useless locking mechanism. We have tests that prove that readers block writers when competing for the same resouces.</p>
<p>The old system reduced the affect of some of these limitations by using READ_UNCOMMITTED Isolation Level alot. </p>
<p>It appears as though they tried not to think about any sort of locking, pessimistic or optimistic.</p>
<p>It's been a slog to get business to give up what they already have been given, but <a href="http://www.gregluck.com">Greg</a> is very persuasive. </p>
<p>Some prior work had already come across the Reporting issues so there was already a Reporting Server that has data upto a week out of date.</p>
<p>All reporting aspects of the story could be moved over to the reporting service. We agreed on a date range that our system would search over and for searches prior to that could be performed on the reporting server.</p>
<p>That was most of the problem solved, the other issues are why our project started in the first place.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Antipatterns%3A+Mixing+Reporting+and+Data+Entry+functions.+What+the%3F+http://m5y3p.th8.us" title="Post to Twitter"><img class="nothumb" src="http://brettdargan.com/blog/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://twitter.com/home/?status=Antipatterns%3A+Mixing+Reporting+and+Data+Entry+functions.+What+the%3F+http://m5y3p.th8.us" title="Post to Twitter">Tweet This Post</a></p>]]></content:encoded>
			<wfw:commentRss>http://brettdargan.com/blog/2004/12/07/antipatterns-mixing-reporting-and-data-entry-functions-what-the/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
