<?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>Open Sourcery &#187; Messaging and Ruby</title>
	<atom:link href="http://www.opensourcery.co.za/category/messaging-and-ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.opensourcery.co.za</link>
	<description>Wizardry through open source</description>
	<lastBuildDate>Wed, 04 Aug 2010 13:04: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>To AMQP or to XMPP, that is the question</title>
		<link>http://www.opensourcery.co.za/2009/04/19/to-amqp-or-to-xmpp-that-is-the-question/</link>
		<comments>http://www.opensourcery.co.za/2009/04/19/to-amqp-or-to-xmpp-that-is-the-question/#comments</comments>
		<pubDate>Sun, 19 Apr 2009 18:22:44 +0000</pubDate>
		<dc:creator>Kenneth Kalmer</dc:creator>
				<category><![CDATA[Messaging and Ruby]]></category>
		<category><![CDATA[amqp]]></category>
		<category><![CDATA[jabber]]></category>
		<category><![CDATA[messaging]]></category>
		<category><![CDATA[xmpp]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.za/?p=173</guid>
		<description><![CDATA[Some time ago I started a series of blog posts [1,2] on Ruby and messaging. Most of the series is still in draft format and has to be completed. It&#8217;s a topic I&#8217;ve been very interested for some time, and have monitored the space quite closely looking for new implementations and collecting presentations and links [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I started a series of blog posts [<a title="Ruby and Messaging Part 1 - The Big Picture" href="/2008/07/07/messaging-and-ruby-part-1-the-big-picture/">1</a>,<a title="Ruby and Messaging Part 2 - Giving Rails a Break" href="/2008/11/07/ruby-and-messaging-part-2-giving-rails-a-break/">2</a>] on Ruby and messaging. Most of the series is still in draft format and has to be completed. It&#8217;s a topic I&#8217;ve been very interested for some time, and have monitored the space quite closely looking for new implementations and collecting presentations and links as I go along. I&#8217;ve been a fan of Jabber (XMPP) for some time now, but it has some smells, to me at least&#8230;</p>
<p>First, some background. I&#8217;m the chief utopian at a South African ISP, <a title="Internet Exchange" href="http://www.inx.co.za">inX</a>, and most of my current work focusses on finishing off the fourth generation of our flagship project <a href="http://www.ispinabox.co.za/">ISP in a Box</a>. ISP in a Box is essentially a Rails frontend to a variety of services we procure and reprovision to resellers, which in turn sell to their clients. Apart from coping with a lot of models and extremely complex business processes, we also have to cope with procuring and provisioning services.</p>
<p>In this post I&#8217;ll aim to give some insight into our provisioning processes, and more specifically how I plan to implement our hosting provisioning over the coming days.</p>
<p>We exclusively use the excellent <a href="http://ruote.rubyforge.org">ruote Worflow Engine</a> by <a href="http://jmettraux.wordpress.com/">John Mettraux</a> to drive our procurement/provisioning processes, instead of overly complex state machines. As part of this I&#8217;ve implemented a Jabber Participant/Listener pair of classes for ruote, allowing any part of the workflow to be shelled out to a Jabber bot for processing, and continuing the workflow when done. This has worked great so far, but the requirements of our hosting services are somewhat more. This made me sit down and think, and <a title="after shopping, a big swot analysis of XMPP, AMQP &amp; REST for our ISP services provisioning platform" href="http://twitter.com/kennethkalmer/status/1557190531">I announced today</a> that I&#8217;ll be doing a &#8220;pen and paper&#8221; SWOT on XMPP, AMQP and REST. What I came up with, is not a textbook SWOT, but at least a look at AMQP from an XMPP point of view. And it was interesting indeed, so much so that I&#8217;ve made up my mind to move to AMQP from XMPP. Here&#8217;s what happened&#8230;</p>
<p><strong>The smells of XMPP</strong></p>
<p>For the record, I really love XMPP as a protocol and the possibilities made possible by it. I&#8217;ve written a good couple of clients, for fun and for serious production use at our company. In my mind, here is a &#8220;SWOT&#8221; on XMPP from someone who works with it frequently.</p>
<table border="0">
<tbody>
<tr>
<th>Strengths</th>
<th>Weaknesses</th>
</tr>
<tr>
<td>
<ul>
<li>Presence &#8211; Know if your bots are running</li>
<li>Quick &#8211; Easy to get going (emerge ejabberd; gem install xmpp4-simple)</li>
<li>Queue like &#8211; ejabberd will store &#8220;offline chats&#8221;</li>
<li>Feedback and control via pidgin</li>
<li>Explicit identities (JID)</li>
</ul>
</td>
<td>
<ul>
<li>Roster &#8211; Managing relationships is a nightmare</li>
<li>Roster &#8211; High number of presence updates can be large overhead</li>
<li>PubSub &#8211; Feels like an afterthought to me</li>
<li>REST bridge (hence <a href="http://github.com/kennethkalmer/ratpack">ratpack</a>)</li>
<li>File transfers are an &#8220;extension&#8221; to protocol and daemons</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p>NOTE: I personally feel that most of the times we implement XMPP where we should be implementing a real queueing protocol. This holds especially true, if you like me, counts on ejabberd&#8217;s persisting of messages while the client is down.</p>
<p>For me personally the <em>biggest smell</em> in XMPP is the roster, at least for automated clients. This shows in other implementations too, <a href="http://github.com/engineyard/vertebra">Vertebra</a> implemented a gatekeeper called Herault. I assume that with Herault in place you don&#8217;t care about roster management, and all bots will freely accept invitations from each other, and ask Herault whether the commands should be accepted or not. This is a perfectly sound plan, permitted your XMPP server is well secured and doesn&#8217;t allow inter-domain communications, ie you&#8217;re running inside a wall of trust.</p>
<p><strong>The promised land of AMQP</strong></p>
<p>I&#8217;m typing this without ever having written a single piece of AMQP code (be it producer or consumer). The &#8220;SWOT&#8221; below is what I&#8217;ve extracted from various online sources over the last couple of weeks, and especially today. I&#8217;ve got a number of requirements that needs to be fulfilled first:</p>
<ul>
<li>Peer to peer implementation of &#8220;bots&#8221; or &#8220;agents&#8221;</li>
<li>Identity driven commands -&gt; &#8220;Server 1: Create new site&#8221;, &#8220;Server 2: Suspend site&#8221;</li>
<li>Unrestricted &#8220;bot&#8221; to &#8220;bot&#8221; communication</li>
<li>File transfers (big files)</li>
<li>No more roster management</li>
</ul>
<p>Now the scary part is that all the above requirements can be fulfilled with XMPP. The implementation would smell however.</p>
<table border="0">
<tbody>
<tr>
<th>Requirement</th>
<th>XMPP</th>
<th>AMQP</th>
</tr>
<tr>
<td>Peer to peer communication</td>
<td>Roster management (-1)</td>
<td>Unique named queues (+1)</td>
</tr>
<tr>
<td>Identity driven commands</td>
<td>Roster management (-1)</td>
<td>Unique named queues (+1)</td>
</tr>
<tr>
<td>File transfers</td>
<td>File transfer proxy configuration (-1)</td>
<td>Supported on the wire (+1)</td>
</tr>
<tr>
<td>No roster management</td>
<td>Implement copy of Vertebra&#8217;s Herault (-1)</td>
<td>Unique named queues (+1)</td>
</tr>
</tbody>
</table>
<p>I hope the table above shows how blurred the lines are, and how difficult it can be to make a decision between the two protocols. Below is my non-textbook &#8220;SWOT&#8221; of AMQP.</p>
<table border="0">
<tbody>
<tr>
<th>Strengths</th>
<th>Weaknesses</th>
</tr>
<tr>
<td>
<ul>
<li>No rosters to manage &#8211; Use queues</li>
<li>Security managed inside the broker (at least with RabbitMQ)</li>
<li>One to one (private) communication</li>
<li>One to many (fan out) communication</li>
<li>File transfer on the wire</li>
<li>REST interfaces in the making (RestMS)</li>
</ul>
</td>
<td>
<ul>
<li>Presence &#8211; Know if your producers/consumers are running</li>
<li>Explicit Identity &#8211; (JID)</li>
<li>Not so quick yet (RabbitMQ ebuild only came into portage <a href="http://twitter.com/asynchronaut/statuses/1558873331">today</a>)</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p><strong>In Summary</strong></p>
<p>Both protocols are great, and the differences are not obvious at first. XMPP is easily mistaken as a message queue, especially because of the &#8220;offline chat&#8221; features in Jabber daemons and the inherently &#8220;targetted messages&#8221;. AMQP supports all of this, and so much more, without the need for roster management or Heraults. The only thing that I&#8217;ll miss from XMPP is the presence features. All my bots currently &#8220;talk to me and members of our support team&#8221;. I&#8217;ll implement this in my AMQP producers/consumers irrespective.</p>
<p>XMPP is built for one-on-one communication, with &#8220;broadcasting&#8221; supported by a protocol extension called PubSub. AMQP inherently supports one-on-one and one-to-many communication through it&#8217;s clever message/exchange system.</p>
<p>Going forward, I&#8217;m starting with the excellent <a href="http://github.com/ezmobius/nanite">nanite</a> project from <a href="http://brainspl.at/">Ezra</a>. I&#8217;ll probably work on bringing AMQP comsumers/producers into ruote this week, as well as implementing a nanite actor/master combo for ruote as well.</p>
<p>A great and timely <a href="http://www.rubyinside.com/rabbitmq-a-fast-reliable-queuing-option-for-rubyists-1681.html">post on RubyInside</a> higlights <a href="http://www.rabbitmq.com/">RabbitMQ</a> and some presentations to watch.</p>
<p>Please chime in on the comments, admittedly I might have buttered up AMQP due to my recent excitement, but I have a &#8220;gut feeling&#8221; it will payoff better in the future than XMPP. XMPP still rocks, I&#8217;ve just been using it as the wrong tool for the job, and I fear others have done the same.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.za/2009/04/19/to-amqp-or-to-xmpp-that-is-the-question/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Ruby and Messaging (Part 2) &#8211; Giving Rails a Break</title>
		<link>http://www.opensourcery.co.za/2008/11/07/ruby-and-messaging-part-2-giving-rails-a-break/</link>
		<comments>http://www.opensourcery.co.za/2008/11/07/ruby-and-messaging-part-2-giving-rails-a-break/#comments</comments>
		<pubDate>Fri, 07 Nov 2008 08:57:31 +0000</pubDate>
		<dc:creator>Kenneth Kalmer</dc:creator>
				<category><![CDATA[Messaging and Ruby]]></category>
		<category><![CDATA[messaging]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.za/?p=38</guid>
		<description><![CDATA[NOTE: This post has been in draft for a couple of months now, and might seem a bit dated because of that. I need to complete the series and have decided to publish it for a sense of completeness.
Like all good bloggers out there, it seems plenty of days between episodes in a series is [...]]]></description>
			<content:encoded><![CDATA[<p class="info"><strong>NOTE:</strong> This post has been in draft for a couple of months now, and might seem a bit dated because of that. I need to complete the series and have decided to publish it for a sense of completeness.</p>
<p>Like all good bloggers out there, it seems plenty of days between episodes in a series is quite reasonable. Nevermind, thats just wrong. Anyone following this blog would have noticed the interesting rise and fall of <a href="/bind-dlz-on-rails/">BIND DLZ on Rails</a>, and its successor <a href="/powerdns-on-rails/">PowerDNS on Rails</a>. This does seem to take a good chunk out of valuable writing time, especially when the likes of<a href="http://jmettraux.wordpress.com/"> John Mettraux</a> are waiting for the next installments&#8230; So without further adue, here is <em>Ruby and Messaging (Part 2) &#8211; Giving Rails a Break</em></p>
<p><strong>Introduction and ramblings</strong></p>
<p>Undoubtedly the topic of messaging in Rails has generated a lot of interest lately, and I&#8217;m sad that I missed my chance to be ahead of the curve in terms of coverage. Why is messaging such a hot topic? Well, Ruby (Rails and other frameworks) allows you to build extremely popular and powerful sites in record time. This does however bring some unforeseen problems, scaling being number one.</p>
<p>Oh no, not another scaling post! On the contrary, I&#8217;d like to highlight how developers hit stardom without ever realizing what it takes. The folks over at Google, Yahoo! and other popular properties had years to figure out how to build reliable, distributed and scalable systems. Amazon is one of the stars of the new Cloud Computing genre, with folks like EngineYard following hot on their tales. These cloud computing providers capitalize on the fact that everyday developers don&#8217;t know a thing about scaling systems. A timely post on the <a href="http://googleblog.blogspot.com/2008/07/we-knew-web-was-big.html">Google Blog</a> proves this quite well:</p>
<blockquote><p>Back then, we did everything in batches: one workstation could compute the PageRank graph on 26 million pages in a couple of hours, and that set of pages would be used as Google&#8217;s index for a fixed period of time.</p></blockquote>
<p>They processed 26 million records in a couple of hours on a <em>workstation</em>. I doubt that <em>workstation</em> compared to even a small AMI. See my point?</p>
<p>Now before we get to batches and distributed systems, lets take a step back and look at the simplest of Ruby messaging systems: the ones that help Rails &#8220;scale&#8221;. I&#8217;ll just be touching on them briefly, you&#8217;ll have to consult Google for more information and real examples.</p>
<p><strong>Giving Rails a break</strong></p>
<p>Now some purists might flame me for this, since it covers messaging at a conceptual level. The real implementations cannot be seen as pure messaging, but I believe in crawling before you walk (it&#8217;s just how nature intended).</p>
<p>So how why does Rails need a break? Some tasks just take too long. Bold, I know. &#8220;Too long&#8221; is extremely relative, considering Flickr keeps there page generation times well below 250 miliseconds. In that case, 300 milliseconds is a 20% increase in processing time! That, my dear reader, is taking &#8220;too long&#8221;.</p>
<p>I&#8217;ll be focusing the remainder of the post on methods that resemble messaging systems, not on ways to make Ruby any faster, or bypass expensive ActiveRecord operations. Other people have covered those topics already, and this is a build up to some more serious articles on messaging, not scaling.</p>
<p><strong>In process messaging</strong></p>
<p>I&#8217;ll be using the classical sending email is slow example, since its relevant to almost every single Rails application in existence.</p>
<p>Let me take a step back and define &#8220;in process messaging&#8221; as I see it. In process messaging is the act of sending an instruction from one part of a running application, to another. This may, or may not, involve the use of threading, but it remains inside a single process. This differs from inter-process (and mostly asynchronous) messaging, which involves message passing between different running systems.</p>
<p>Back to sending email. It&#8217;s slow because a mail server is a different beast all together. It takes more than 250 ms for a mail to get queued in a SMTP server, especially if the mail server is not on the same server as the Rails application. And besides, why can&#8217;t we run that &#8220;in the background&#8221; and tell the user the message has been sent? This means the user gets the confirmation page before Rails is even done with sending the message.</p>
<p>Using something like PHP would make this a snap. You&#8217;ll generate your confirmation message to the user, flush PHP&#8217;s buffers and ask Apache to close off the request. Then you&#8217;ll send the email afterwards, out of sight and out of mind. Rails doesn&#8217;t sport this option, but all is not lost.</p>
<p>Enter two plugins that caught my eye.</p>
<p><em><strong>Spawn</strong></em></p>
<p>Though it can run in fork mode (making it asynchronous), it does support threading mode (making it in process).</p>
<p>A simple code example looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">spawn <span style="color:#9966CC; font-weight:bold;">do</span>
  Mailer.<span style="color:#9900CC;">deliver_registration_confirmation</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0066ff; font-weight:bold;">@subscriber</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>I&#8217;ve had the pleasure to use spawn on a couple of projects and it works very nicely. It&#8217;s especially rewarding to watch your log files and see the spawned process took a couple of seconds and you know that you didn&#8217;t keep the request on hold for that time.</p>
<p>You can also use spawn outside of Rails with minimal effort. Open up spwan.rb and have a look for yourself, it is a beautful little file that is very good at doing one thing.</p>
<p><em><strong>background</strong></em></p>
<p>The aptly named &#8220;<a href="http://devblog.imedo.de/2008/6/18/running-ruby-blocks-in-the-background">background</a>&#8221; plugin also does a great job of handling these long running tasks. I&#8217;ve used this one in an application or two and love it. It also covers various operation modes, but at its simplest it will also run in process.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">background <span style="color:#9966CC; font-weight:bold;">do</span>
  Mailer.<span style="color:#9900CC;">deliver_registration_confirmation</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0066ff; font-weight:bold;">@subscriber</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>It&#8217;s as simple as that. It offers slightly more than spawn, but I&#8217;ll cover more advanced topics later in the series. It also supports out of process messaging, but thats covered next&#8230;</p>
<p><strong>Inter-process messaging</strong></p>
<p>Not to move on too quickly, but inter-process processing follows the same lines as the in-process examples. I&#8217;m using inter-process messaging loosely here to refer to Ruby-to-Ruby communication within the same project, and where you as the developer control both ends of the conversation.The later parts of the series will address different queuing implementations and protocols for performing tasks larger than just sending mail.</p>
<p>A player I really want to mention here is <a href="http://backgroundrb.rubyforge.org/">BackgroundRB</a>. It steps things up a bit by running your workers outside of the Rails process. Jobs are queued &amp; scheduled and handled by worker processes. It seems tightly coupled with Rails, so I don&#8217;t know how easy it would be to use it outside of Rails.</p>
<p>Using Distributed Ruby, or DRb, is another great way to have asynchronous processing. DRb is more of a roll-your-own solution, but really helps if you&#8217;ve planned properly and understand the DRb implementation. DRb uses its own format to pass messages around between servers. Did I just mention servers, and not client-server? <em>Yes</em>. In the DRb world the client is also a server and is asked to do processing the &#8220;server&#8221; can&#8217;t. This has bitten me on the arse before, and thats why I said you need proper planning. If you pass complicated objects over the wire, the processing will be directed back to the client, effectively rendering DRb useless. I&#8217;ll cover this at some other time.</p>
<p>Another approach I&#8217;ve used where the communication needs to be synchronous, but between different processes is to build my own REST services. I&#8217;ve favored <a href="http://halcyon.rubyforge.org/">Halcyon</a> so far, for no other reason than getting familiar with JSON. You can use your imagination when you control both ends of the conversation, but keep your messages in a format thats preferably standard and open, like XML/JSON.</p>
<p><strong>Synchronous and asynchronous processing</strong></p>
<p>Just to avoid confusion I need to make this clear. No matter how your messages travel, be it in-process or inter-process, it doesn&#8217;t make it asynchronous. My examples of using the spawn and background allow for <em>asynchronous processing</em> using variables as in-process messages (or instructions). Furthermore the REST API example does the opposite, it uses inter-process messaging as part of a <em>synchronous process</em>.</p>
<p>Keep the distinction clear in your design. Messaging is a form of communication and not of processing. Various people use the terms almost interchangeably and this makes it seemingly difficult to grasp the concepts correctly.</p>
<p>Using a clear, concise and open messaging implementation will build you applications that can grow almost indefinitely. Look at the web as a prime example of this, with billions simple HTTP messages getting passed around every couple of minutes.</p>
<p><strong>Looking forward</strong></p>
<p>There are definitely better approaches available to us, including message queuing, broadcasting and message federation, to name but a few. The next parts of the series will cover these topics in more details. Looking back at <a href="/2008/07/07/messaging-and-ruby-part-1-the-big-picture/">the first part of the series</a> I made a proposition that we model our systems after existing ecosystems found in nature. In such a ecosystem each component can live on it&#8217;s own, evolve separate and flourish.</p>
<p>The topics discussed in the post doesn&#8217;t really encourage the building of an ecosystem, but rather an abomination if used incorrectly. Its from my own experiences of dealing with these abominations that I&#8217;ve modeled my ecosystems on nature and continue to see them flourish. These approaches are also tied to Rails, with the exception of DRb and REST, and create a lock-in of sorts. Not that I don&#8217;t like Rails, I love having options even more.</p>
<p>The next two articles will focus on using Jabber/XMPP and AMQP, and all their friends. Two very powerful technologies that compete head on for developer mindshare, although I sometimes believe the mindshare should be 50/50. After that I might change the direction to practical uses and implementations of messaging (<a href="http://openwferu.rubyforge.org/">ruote</a> comes to mind).</p>
<p class="info"><strong>NOTE:</strong> This post has been in draft for a couple of months now, and might seem a bit dated because of that. I need to complete the series and have decided to publish it for a sense of completeness.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.za/2008/11/07/ruby-and-messaging-part-2-giving-rails-a-break/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Messaging and Ruby (Part 1) &#8211; The Big Picture</title>
		<link>http://www.opensourcery.co.za/2008/07/07/messaging-and-ruby-part-1-the-big-picture/</link>
		<comments>http://www.opensourcery.co.za/2008/07/07/messaging-and-ruby-part-1-the-big-picture/#comments</comments>
		<pubDate>Mon, 07 Jul 2008 09:00:10 +0000</pubDate>
		<dc:creator>Kenneth Kalmer</dc:creator>
				<category><![CDATA[Messaging and Ruby]]></category>
		<category><![CDATA[messaging]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.opensourcery.co.za/?p=37</guid>
		<description><![CDATA[Rails doesn&#8217;t scale.
Now that I have your attention, lets forget scaling all together and instead start focusing on how you can give Rails a break using messaging or &#8216;backgrounding&#8217;. This is the first in a series of articles where I&#8217;m combining my own research and experience together to a) prevent me from making the same [...]]]></description>
			<content:encoded><![CDATA[<p>Rails doesn&#8217;t scale.</p>
<p>Now that I have your attention, lets forget scaling all together and instead start focusing on how you can give Rails a break using messaging or &#8216;backgrounding&#8217;. This is the first in a series of articles where I&#8217;m combining my own research and experience together to a) prevent me from making the same mistakes in future, and b) hopefully help someone else to not make the same mistakes I did.</p>
<p><strong>Prelude</strong></p>
<p>Ever since I&#8217;ve read <a href="http://nutrun.com/weblog/distributed-programming-with-jabber-and-eventmachine/">Distributed programming with Jabber and EventMachine</a> I&#8217;ve been baffled by the almost endless possibilities this offers. I&#8217;ve shared this knowledge with several people, who got excited too, but not as excited as I did. Then I read about <a href="http://brainspl.at/articles/2008/06/02/introducing-vertebra">Vertebra on Ezra&#8217;s blog</a> and almost lost my mind, shared this knowledge again and got a more enthusiastic response. Since then I&#8217;ve been scouring the net for more information and examples on using Jabber for distributed programming, as well as alternatives, since something was not entirely right in the equation.</p>
<p>Up until now I&#8217;ve used some insane combinations of Distributed Ruby, SQS, &#8220;Roll your own ActiveRecord queue&#8221;, REST and who even knows what else to achieve some levels of &#8217;scalability&#8217; and &#8216;asynchronous processing&#8217;.</p>
<p>Each project I work on have varying demands, from being ready to survive a Slashdotting all the way down to integrating with several desperate systems. Each one has its own expectations in terms of processes, business rules, and reporting on &#8220;background tasks&#8221;. It is quite a colorful affair I assure you. Now on each iteration I try something else, something new, something better. And they do get better, so I&#8217;m proud of the work I&#8217;ve done, and even more proud of my team members keeping up with the frantic evolution of the code everywhere.</p>
<p>However, this roll-your-own messaging systems are not scalable or reliable. You need the wisdom of crowds at your disposal. You need to draw on the knowledge of guys who&#8217;ve built systems for Fortune 500&#8217;s, built systems for telco&#8217;s, built systems for financial markets, built systems for medical care, built systems for aviation, etc.</p>
<p>Why? These guys have faced obstacles we can never imagine ,and they&#8217;ve overcome them. Through the years their knowledge has become available to us, and we must apply it. I&#8217;m sure if Twitter thought like a telco, and built Twitter the way a telco would, it would have never broken a sweat handling all those tweats.  But I&#8217;m not one to criticise, on with the story.</p>
<p><strong>What is messaging, and why is it important?</strong></p>
<p>Good question! <a href="http://en.wikipedia.org/wiki/Message">Wikipedia</a> sums it up like this:</p>
<blockquote><p>There are two main senses of the word &#8220;message&#8221; in computer science: messages passed within software, which may or may not be human-readable, and human-readable messages delivered via computer software for person-to-person communication.</p></blockquote>
<p>We&#8217;ll be focussing on the first sense, &#8220;messages passed within software&#8221;.</p>
<p><strong>Why is messaging important?</strong></p>
<p>It allows us to build systems that have the following characteristics:</p>
<ol>
<li>Snappy websites that don&#8217;t block while performing expensive operations (sending mail, resizing photo&#8217;s, encoding videos, etc).</li>
<li>Horizontal scalability, just throw in more instances of your program to speed up processing</li>
<li>Loosely coupled components that merely &#8216;talk&#8217; to each other</li>
<li>Ability to easily replace Ruby with something else for specific tasks</li>
</ol>
<p>By passing simple messages around between different processes, or systems, we can build an ecosystem from smaller, more specialized components and then allow users to interact with the ecosystem as whole, as opposed to a monolithic compound.</p>
<p>Nature has proven over and over again how effective ecosystems are at surviving by evolving. Having loosely coupled components that exist independently, but talk to each other via messages, allows you to build extremely powerful systems, that would by virtue, scale indefinitely and evolve constantly.</p>
<p><strong>Awesome! How do I do it?</strong></p>
<p><span style="text-decoration: line-through;">It&#8217;s quite simple, you need this gem, that app, several servers, big dollars</span>. You first need to understand a couple of concepts. This is very important, and this was my biggest mistake. There is no shortage of ways to perform distributed programming or to run expensive operations asynchronously, and this list is not even a chip off the iceberg.</p>
<p>In my experience as a Rails and Ruby developer, I&#8217;ve dabbled in a few different ways to solve the asynchronous and distributed programming problems, each with their own merits (and demerits). Each of these problems and proposed solutions are covered this series, so I&#8217;m only gonna touch on them briefly now.</p>
<p><em>Asynchronous processing in Ruby on Rails</em></p>
<p>Here I&#8217;m specifically referring to expensive tasks that &#8216;lock up the browser&#8217; without any real reason at all. I can probably build a list from here to the moon based on the experiences of others and myself, but I won&#8217;t. Simple examples will suffice, and these include sending mails, resizing images, interacting with other services (RSS, REST) and cron-like processing. Just like I said in the opening statements, the expectations on today&#8217;s websites are enormous&#8230;</p>
<p><em>Distributed processing with Ruby</em></p>
<p>Leveraging cloud computing to perform an array of expensive or time consuming tasks. This is a wide open description, but I&#8217;d like to restrict the scope to tasks like video encoding, photo manipulation, sending newsletters to thousands of users, crawler activities, and other general tasks related to servicing millions of users. I&#8217;m not referring to cracking the human genome, or even solving the Rubik&#8217;s cube in the smallest number of steps. Tasks of those caliber require something much bigger than what my mind can conjure up.</p>
<p><em>Cron-like processing of tasks</em></p>
<p>The newsletter example above will fit in here too, since we need to determine at a specific time who will receive which newsletters. The trigger to some crawling activities might also be scheduled. I&#8217;ll make the article is more clear, I&#8217;m a but stumped now&#8230;</p>
<p><em>Workflow-like systems</em></p>
<p>In this artcle I&#8217;ll probably get crucified for not discussing awesome libraries like <a href="http://github.com/jmettraux/ruote">ruote</a> and other BPM engines, but will instead focus on using messaging to drive sequential processes through loosely coupled components, building the ecosystem example used earlier in this article.</p>
<p><strong>For the impatient and the eager</strong></p>
<p>I&#8217;ll be discussing examples built on top of <a href="http://www.ruby-doc.org/stdlib/libdoc/drb/rdoc/index.html">DRb</a>, <a href="http://sqs.amazonaws.com/">SQS</a>, <a href="http://www.xmpp.org/">Jabber (XMPP)</a>, <a href="http://jira.amqp.org/confluence/display/AMQP/About+AMQP">Advanced Messaging and Queueing Protocol (AMQP)</a> and others. I&#8217;ll also be looking at various clients, servers and services that help facilitate message sending, consumption and brokering with Ruby.</p>
<p>Most important of all is not the technology it self, but the lessons learned from using it. These are lessons I learned while getting baptized by fire, or learned from others who show the same scars. I want to help others to not have the same scars, and instead focus on the next generation of problems so I can learn from them again.</p>
<p><strong>Looking forward</strong></p>
<p>At the time of writing I have the other articles in some combination of notes, taboo&#8217;s, del.icio.us-ness and draft posts, and am looking forward to completing them eagerly for publishing, hence this appetizer.</p>
<p>Please add the feed to your reader of choice so you can grab them as they are released. I&#8217;d also appreciate some pre-emptive feedback and pointers from people who&#8217;ve wondered down the same path so I can include more info in the coming articles.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.opensourcery.co.za/2008/07/07/messaging-and-ruby-part-1-the-big-picture/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
