<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Clifton Cunningham on Medium]]></title>
        <description><![CDATA[Stories by Clifton Cunningham on Medium]]></description>
        <link>https://medium.com/@clifcunn?source=rss-c47ca032350b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*x4_2R2fpiPYAEJ0KtG0_Dg.jpeg</url>
            <title>Stories by Clifton Cunningham on Medium</title>
            <link>https://medium.com/@clifcunn?source=rss-c47ca032350b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 19 Jun 2026 14:31:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@clifcunn/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com" rel="hub"/>
        <item>
            <title><![CDATA[Automating the Brink Flair with Node-Red and Home Assistant]]></title>
            <link>https://medium.com/@clifcunn/automating-the-brink-flair-with-node-red-and-home-assistant-8ff6a41d19c?source=rss-c47ca032350b------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ff6a41d19c</guid>
            <category><![CDATA[node-red]]></category>
            <category><![CDATA[modbus]]></category>
            <category><![CDATA[home-assistant]]></category>
            <category><![CDATA[home-automation]]></category>
            <dc:creator><![CDATA[Clifton Cunningham]]></dc:creator>
            <pubDate>Tue, 29 Dec 2020 06:14:07 GMT</pubDate>
            <atom:updated>2020-12-29T06:14:07.842Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automating the Brink Flair</h3><p>Ok, short one, but I spent the last day re-living my electrical engineer days and wanted to share in the hope I help others who were navigating the somewhat hard to find / read docs from Brink. It amazes me that in 2020 a device that costs €2–€3k doesn’t come with a ZigBee or Z-Wave module out of the box.</p><p>My aim was to be able to fully control the HRU (heat recovery unit — for ventilation but in a way that ensures the air coming into the house is warmed by the air leaving, and so saving heating bills) from <a href="https://www.home-assistant.io/">Home Assistant</a>.</p><p>I have published it all on node-red: <a href="https://flows.nodered.org/flow/4e93b2dc8ff6acb5dbbcd48b1df92224">https://flows.nodered.org/flow/4e93b2dc8ff6acb5dbbcd48b1df92224</a></p><p>This is the setup I am using to publish events for my <a href="https://www.brinkclimatesystems.nl/oplossingen/ventilatie/flair-serie">Brink Flair 300</a> heat recovery unit. I have a Raspberry Pi 3, with an RS485&gt;USB, connected to the 2 &amp; 3 pin of the X15 input of the HRU. The flow in Node-Red talks locally to the device via modbus, and then connects to an mqtt server that is used for further connection to Home Assistant, this appears to be the most robust solution.</p><p>I used this USB stick: <a href="https://www.reichelt.nl/nl/nl/raspberry-pi-usb-rs485-interface-rs485-ch340c-rpi-usb-rs485-p242783.html?search=rs485+usb&amp;&amp;r=1">Rpi RS485 USB</a>, but I think any of them will work. You do <em>not</em> need to buy the super expensive ‘digital adapter’ and the app, and with this setup you also do not need the super expensive RF bridge and connectors (though will likely want some physical alternative to this setup to turn it on / off if needed).</p><p>It currently provides temperature, set fan speed, actual fan speed, binary sensors for max, medium, normal (same as the 4-way RF switch) and inputs for speed (50–300, +50, -50). I also have another flow connecting this to the output of my air sensor, so when the air quality drops or it detects us cooking it turns the ventilation on!</p><p>Huge thanks to <a href="https://github.com/sirjackal/brink-modbus">https://github.com/sirjackal/brink-modbus</a> as this was essential in making it all work and getting the steer towards Modbus being the way to connect.</p><p>The gist below has all of the files referred to in this article: <a href="https://gist.github.com/cliftonc/4e93b2dc8ff6acb5dbbcd48b1df92224">https://gist.github.com/cliftonc/4e93b2dc8ff6acb5dbbcd48b1df92224</a></p><h3>Connection to Brink Flair</h3><p>Use the 2 &amp; 3 connections to the red X15 (note that mine came with a removable red plug already in it — so I just needed to connect it).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SThEAA0VsVSo7uRCEVvR4w.png" /><figcaption>Extract from Brink English manual</figcaption></figure><p>To verify it was working, I translated and used the python script from the <a href="https://github.com/sirjackal/brink-modbus">https://github.com/sirjackal/brink-modbus</a> repository, along with <a href="https://github.com/epsilonrt/mbpoll">mbpoll</a>.</p><p>Amazingly (after reversing the wires as I got it wrong first time around!) it actually worked :)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JHABD2Ttm84dxuPUFrw53Q.png" /><figcaption>Output from modbus.py</figcaption></figure><p>Then it was a matter of getting it all in node-red, then wiring up to home assistant via mqtt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lXHZtcdUlN2yHp6YJz_clg.png" /><figcaption>Node-red running on raspberry pi — only talks to modbus + mqtt</figcaption></figure><p>Then finally going into Home Assistant itself and creating the sensors (the actual configuration.yaml is in the gist above):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZhUqKcG9wuT7--OI2B87Qw.png" /></figure><p>And then last of all the dashboards:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*okQnFFph4-J1PTpLnyY2iA.png" /><figcaption>Detailed view</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*8cUxGJ7AS6Hfk-UWR0a6dw.png" /><figcaption>Compact view on my home page</figcaption></figure><p>It lives!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ff6a41d19c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices Day 2017]]></title>
            <link>https://medium.com/@clifcunn/microservices-day-2017-3eca231c35ea?source=rss-c47ca032350b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3eca231c35ea</guid>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[organisational-change]]></category>
            <category><![CDATA[node]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Clifton Cunningham]]></dc:creator>
            <pubDate>Wed, 31 May 2017 10:49:25 GMT</pubDate>
            <atom:updated>2017-05-31T11:01:34.145Z</atom:updated>
            <content:encoded><![CDATA[<p>First up, I gave a short talk about some of the lessons learned and impressions by Engineers about our micro-service architecture:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPL0CdgOSSGlBauWpICW8OFgRsy3tydwOyJ&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dl1GmfbblLcE&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fl1GmfbblLcE%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/04329eb8dc07bfec41cb2fe58da042b6/href">https://medium.com/media/04329eb8dc07bfec41cb2fe58da042b6/href</a></iframe><p>I next joined a panel to talk about scalable systems:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPL0CdgOSSGlBauWpICW8OFgRsy3tydwOyJ&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dw_0z_sKkul0&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fw_0z_sKkul0%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/de1b18b5522da21f154e00063d1d6925/href">https://medium.com/media/de1b18b5522da21f154e00063d1d6925/href</a></iframe><p>And finally was in a second panel talking about organisational change:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPL0CdgOSSGlBauWpICW8OFgRsy3tydwOyJ&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DiNWC8bGgc0s&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FiNWC8bGgc0s%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/91a12572c1476aacf8bb21c68d1588ef/href">https://medium.com/media/91a12572c1476aacf8bb21c68d1588ef/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3eca231c35ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices Day]]></title>
            <link>https://medium.com/@clifcunn/microservices-day-ef7e82c28230?source=rss-c47ca032350b------2</link>
            <guid isPermaLink="false">https://medium.com/p/ef7e82c28230</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Clifton Cunningham]]></dc:creator>
            <pubDate>Wed, 11 May 2016 09:55:03 GMT</pubDate>
            <atom:updated>2016-05-11T09:55:03.278Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FzOrFfeBspls%3Ffeature%3Doembed&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DzOrFfeBspls&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FzOrFfeBspls%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/5f7ea53ed73f35d382ca83d3ced5f005/href">https://medium.com/media/5f7ea53ed73f35d382ca83d3ced5f005/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ef7e82c28230" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An adventure with a memory leak in Node]]></title>
            <link>https://medium.com/@clifcunn/an-adventure-with-a-memory-leak-in-node-3568128a0e83?source=rss-c47ca032350b------2</link>
            <guid isPermaLink="false">https://medium.com/p/3568128a0e83</guid>
            <dc:creator><![CDATA[Clifton Cunningham]]></dc:creator>
            <pubDate>Wed, 04 Mar 2015 20:50:50 GMT</pubDate>
            <atom:updated>2015-03-04T20:50:50.045Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve followed any of my previous posts about what we are building at TES, you will remember that we are using a proxy to perform the composition of fragments of HTML into pages (given 70% of our traffic is from organic SEO) — all via an open source project that I talk about a lot more here:</p><p><a href="https://medium.com/p/29dd3ed500ec"></a></p><p>Well … we’re now completely, 100%, entirely live with the platform built this way, and have been for a few months, and so we have some good news to report.</p><p>The performance and operation of the overall system is great — most individual services are sub 10ms response times, low memory and very reliable (hey — they only do one thing!), the overall pages average 60ms response times even under full load, and all this on significantly less infrastructure then we had previously.</p><p>To top it all off using the fully automated deployment pipeline we have done roughly 60 deployments to live since we went fully live with the eCommerce elements two weeks ago. TES previously didn’t do this many releases in an entire year, let alone two weeks. Some of these small bugs, some fully fledged features — but all just one person picking up a ticket, doing the work, pushing to live.</p><p>Feel free to find yourself something here if you’re wondering what it is:</p><p><a href="https://www.tes.co.uk/teaching-resources/search/">https://www.tes.co.uk/teaching-resources/search/</a></p><p>But, like all stories of going live with a complex, multi-faceted system not everything goes right. One of those is that we observed that the composition layer was exhibiting some strange behaviour regarding memory usage after we went live with all 400k of content pages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QX1A0gxEtHB-MI4mWILKWQ.png" /></figure><p>Not great at all — we had 7 node processes per server (8 cpus), with 16GB memory per server, and what you see above is the node processes killing themselves with OOM. This is after an earlier round where we had the memory limits within Docker set lower than the Node max heap size, and Docker was killing the processes before we got to this point.</p><p>So, we clearly had a memory leak that none of the earlier tests we had been running on any of the individual components (that appeared to not show this behaviour) was highlighting to us.</p><p>I embarked on a rapid process of soak testing each of the pieces that fit into Compoxure — the first candidate was the library that gets and then caches the fragments:</p><p><a href="https://github.com/tes/reliable-get">https://github.com/tes/reliable-get</a></p><p>A series of commits, including some that removed functionality we weren’t currently using, ensued, along with specific soak tests that were (I thought) designed to find out what is going on with memory growth.</p><p><a href="https://github.com/tes/reliable-get/blob/master/benchmark/soak.js">https://github.com/tes/reliable-get/blob/master/benchmark/soak.js</a></p><p>I even used a set of production urls to test against (a lot of them!) to make sure that my test wasn’t too synthetic and so not replicating the live environments. I wrote a little module that dumped memory every second so that I could graph it in Excel …. nada:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EpKJm8cCLHpeOj2tEQlBcQ.png" /></figure><p>So — imagine repeating this process against all the pieces (I won’t bore you but you can see all the commits in Github). Nothing obvious popped out.</p><p>The final approach, which myself and <a href="https://github.com/cressie176">Steve Cresswell</a> from <a href="http://guidesmiths.com/">Guidesmiths</a> agreed never to share publicly, was to go into one of the live containers, manually install <a href="https://github.com/bnoordhuis/node-heapdump">heapdump</a>, restart a worker and then manually trigger heap dumps over the next few hours.</p><p>What this delivered however was very enlightening:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I-BTc0N5NO8j4heEiVxDug.png" /></figure><p>1GB of heap consumed by what appears to be the HTML fragments that are being parsed by the parser, and processed to generate the final output.</p><p>Looking at retainers, the culprit became clear:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*V0_oUnaM3piTKk9RlLzPrg.png" /></figure><p>It was the template engine we were using to parse the declarations, Hogan, holding on to sections of the strings that were being processed by <a href="https://github.com/fb55/htmlparser2/">htmlparser2</a>, and in so doing forcing V8 to hold on to the entire document.</p><p>The specific code that did it is here:</p><p><a href="https://github.com/twitter/hogan.js/blob/master/lib/compiler.js#L404">https://github.com/twitter/hogan.js/blob/master/lib/compiler.js#L404</a></p><p>Which basically just caches the template so that on subsequent use it isn’t re-compiled, a very sensible thing to do for ‘normal’ use, but we weren’t using it normally. Once we went live with all of the documents, we were effectively creating a set of micro cached templates for every single document that parsed through it, and then holding the whole document.</p><p>But — why does V8 hold on to the entire document if you grab just a small chunk of it? Good question:</p><p><a href="https://code.google.com/p/v8/issues/detail?id=2869">Issue 2869 - v8 - Substring of huge string retains huge string in memory - V8 JavaScript Engine - Google Project Hosting</a></p><p>So … our solution was to pull Hogan into the project directly, and remove the caching. It meant nothing was ever holding on to the substr of the document and so V8 could GC it as it should. I’ll package this up into a PR to make it configurable in the next few days.</p><p>The result, note the second deployment when we figured it out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uD3ySoAS4yb6A19GY1O9kg.png" /></figure><p>Everyone happy. Key take aways:</p><ol><li>If you do anything with large documents in node, remember that retaining any substr of it will retain the whole document — be careful.</li><li>We didn’t actually need this feature of caching the compiled template, and in some respects don’t need the full power of a templating engine to parse the declarations — I should probably have looked deeper under the hood when selecting it and may still replace it with a simpler parser.</li><li>Load testing to look for memory leaks must be able to replicate real production traffic — not always easy to do.</li><li>Being able to perform heapdumps in live is invaluable — we’re going to automate it in future.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3568128a0e83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When things don’t go to plan …]]></title>
            <link>https://medium.com/@clifcunn/when-things-dont-go-to-plan-fb3c852a9ce7?source=rss-c47ca032350b------2</link>
            <guid isPermaLink="false">https://medium.com/p/fb3c852a9ce7</guid>
            <dc:creator><![CDATA[Clifton Cunningham]]></dc:creator>
            <pubDate>Sun, 23 Nov 2014 12:16:38 GMT</pubDate>
            <atom:updated>2014-11-23T12:40:14.939Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ee3B_QATgJlvxNq3Ytcq7Q.jpeg" /><figcaption>Copyright: <a href="https://www.flickr.com/photos/clintjcl/7583651542/">https://www.flickr.com/photos/clintjcl/7583651542/</a></figcaption></figure><p>I’ve been talking at a couple of conferences lately about the approach we are taking at TES Global around declarative service composition (<a href="https://medium.com/@clifcunn/nodeconf-eu-29dd3ed500ec">this will explain it</a>).</p><p>What I’ve noticed is that people tend to feel a little uncomfortable about putting a proxy like this in front of their application, and lets be honest — I completely understand that fear — this isn’t just a library, this will be between you and your customer and interacting with every piece of HTML your application produces! Dejan outlined some ideas and concerns in a post <a href="http://dejanglozic.com/2014/10/20/micro-services-and-page-composition-problem/">here</a>.</p><p>I won’t talk about how you can try it in small slices (e.g. maybe on just a small part of your application), but rather some of the work I’ve been doing recently to take some of the ideas and concepts from <a href="https://github.com/tes/compoxure">Compoxure</a> and modularise them so that both we and others can use them without having to buy the whole farm.</p><p>So, the core of <a href="https://github.com/tes/compoxure">Compoxure</a> has been extracted into two new libraries:</p><h4>Parxer: <a href="https://github.com/tes/parxer">https://github.com/tes/parxer</a></h4><p>Parxer extracts the core HTML parsing logic out, think of it like a non-streaming version of <a href="https://www.npmjs.org/package/trumpet">Trumpet</a>.</p><p>Realistically I don’t expect many people find use for this outside of our use case, as there are things with probably ‘better’ APIs out there that if you just want to do HTML transformation, however, if what you want to do is HTML transformation where those transforms involve asynchronous functions (e.g. calls to other services) and you want those to all run in parallel, then this might just be useful for you.</p><p>It’s non-streaming for a number of reasons, not the least that I can’t yet get my head around how to do the parsing and interleaving of parallel requests in a streams mindset, so this model is less complex for me to reason about and hence get working. I also find it very fast, despite the fact that it is technically buffering everything vs just sending it as soon as it gets it.</p><p>It’s been refactored with a simple plugin architecture, so you can easily add your own handlers, with the defaults that <a href="https://github.com/tes/compoxure">Compoxure</a> uses (url, bundles and test) all built in as core.</p><pre>var input = “&lt;html&gt;&lt;div id=’test’ cx-test=’{{environment:name}}’&gt;&lt;/div&gt;&lt;/html&gt;”; <br>parxer({ <br>  plugins: [ require(‘../Plugins’).Test ], <br>  variables: { ‘environment:name’:’test’ }},   <br>  input, <br>  function(err, data) { <br>    var $ = cheerio.load(data); <br>    $(‘#test’).text() == ‘test’; // true<br>});</pre><p>There are a lot more examples in the tests, and of course it is used within <a href="https://github.com/tes/compoxure">Compoxure</a> so you can also look at that source code.</p><h4><strong>Reliable Get</strong>: <a href="https://github.com/tes/reliable-get">https://github.com/tes/reliable-get</a></h4><p>The second part is the code that interacts with the micro-services themselves, ‘reliable-get’.</p><p>Think of this as a wrapper around <a href="https://github.com/mikeal/request">request</a> that ensures that if the service at the other end isn’t reliable that your application won’t die as well.</p><pre>var ReliableGet = require(&#39;reliable-get&#39;);<br>var config = {<br> cache:{<br>   engine:&#39;redis&#39;<br> },<br> circuitbreaker:{<br>   includePath: true<br> }<br>};<br>var rg = new ReliableGet(config);<br>rg.get({url:&#39;http://www.google.com&#39;, cacheKey:&#39;google&#39;, cacheTTL:60000, timeout: 500}, function(err, response) {<br> console.log(response.content);<br>});</pre><p>So once you have created an instance of reliable get, you can fire off GET requests to as many dodgy services as you like, and this will give you a reasonable amount of protection:</p><ul><li>If your service is higher load than the 3rd party you deal with, this will cache responses from it (completely configurable, plus it will honour cache response headers from the service as well).</li><li>If the service has ever responded with a successful response, and then later dies, reliable-get will serve the last successful (‘stale’) response to ensure your app continues to appear like it is functioning as normal.</li><li>There is a circuit breaker that ensures that if the 3rd party service dies or starts having trouble, a circuit breaker can open that can reduce load. In this model it will continue to serve the ‘stale’ content if it has it. This avoids you hammering a service that might be struggling into the ground while you try to fix it.</li></ul><h4>Modularity</h4><p>The other thing that is useful about this process is that it has made the Compoxure code base much smaller and simpler to understand, I’ve found a few bugs in all three projects that are now fixed, overall test coverage is much higher and I think that actually getting others to add features to any one of the three will likely be easier (lets see!).</p><p>I think this method actually worked really well in this instance:</p><ol><li>Write code to get it working.</li><li>Refactor that code to make it easier to work with, increasing test coverage as you go.</li><li>Once refactored, extract out modular code into separate libraries. Increase coverage on those libraries.</li></ol><p>The danger of starting with lots of modules is that you don’t really understand the requirements for those smaller modules until you compose them together into something more complex.</p><p>This way of thinking also has a lot of similarities to the Micro Services — How to Start? — question, e.g. can you only properly identify the right granularity of services if you have previously built something larger that you are now teasing apart?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fb3c852a9ce7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[NodeConf EU — Microservice Composition & Bosco]]></title>
            <link>https://medium.com/@clifcunn/nodeconf-eu-microservice-composition-bosco-e988a638cecb?source=rss-c47ca032350b------2</link>
            <guid isPermaLink="false">https://medium.com/p/e988a638cecb</guid>
            <dc:creator><![CDATA[Clifton Cunningham]]></dc:creator>
            <pubDate>Tue, 04 Nov 2014 09:45:11 GMT</pubDate>
            <atom:updated>2014-11-23T12:22:35.675Z</atom:updated>
            <content:encoded><![CDATA[<h3>NodeConf EU — Microservice Composition &amp; Bosco</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8J-9-_jNB3KGI6jIGiCWYQ.png" /></figure><p>Cian from NearForm has just put the video from NodeConf EU online:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F_SoPZS7Wqiw%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D_SoPZS7Wqiw&amp;image=http%3A%2F%2Fi.ytimg.com%2Fvi%2F_SoPZS7Wqiw%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b76f71ee4b1e2df691aca2cff88992a/href">https://medium.com/media/6b76f71ee4b1e2df691aca2cff88992a/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e988a638cecb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Now you have N problems]]></title>
            <link>https://medium.com/@clifcunn/now-you-have-two-problems-166dd9ca997e?source=rss-c47ca032350b------2</link>
            <guid isPermaLink="false">https://medium.com/p/166dd9ca997e</guid>
            <dc:creator><![CDATA[Clifton Cunningham]]></dc:creator>
            <pubDate>Tue, 21 Oct 2014 05:04:00 GMT</pubDate>
            <atom:updated>2014-11-23T12:21:23.231Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lqatageDM0QPVPskCMrolg.png" /></figure><p>Micro services are definitely a hot topic at the moment, and many organisations large and small are breaking up their monolithic apps into smaller and smaller components.</p><p>Many start out on that journey by breaking out obviously asynchronous tasks — e.g. sending an email — into a separate service that receives messages from other parts of the application via a message bus of some sort.</p><p>The instant you do this though, you have just required your developers to now check out two repositories instead of one. Then you break out another service. Three. Then another. Four. Then you get a taste for it. Five. Six. Seven. Fifty. One hundred.</p><p>This may sound insane, one hundred repositories? But it’s definitely true — once you get the basics in place that allow you to automatically deploy more than one service it then becomes the default to break out new functionality into new services and on it rolls.</p><p>This then creates a challenge though for your development teams. How do they manage to get up and running from a blank start, on their first day, when they have to get hold of over 100 repositories, plus all of the local infrastructure dependencies (MQ, DB, Cache).</p><p>There are some fantastic projects that I would highly recommend that can deal with the base level of this — like <a href="https://boxen.github.com/">https://boxen.github.com/</a> and <a href="https://www.vagrantup.com/">https://www.vagrantup.com/</a> — but they tend to focus on everything but the project your working on, e.g. just getting all of the dependencies up and running repeatably and reliably across a number of developer machines.</p><p>There are also some great build tools like <a href="http://gruntjs.com/">http://gruntjs.com/</a> and <a href="http://gulpjs.com/">http://gulpjs.com/</a> that allow your projects to be built in a common and repeatable way. But by design these tools and their plugin eco-system are very focused on building and managing a single project, not many.</p><p>So what is a CTO to do? Well, by very definition an engineer should build be comfortable building their own tools, so that’s what we did.</p><h2>Bosco</h2><p>Bosco is a tool to help a team manage all of the projects that get created as a byproduct of a micro service architecture. It doesn’t replace Boxen or Vagrant, it isn’t a build tool that is attempting to replace Grunt or Gulp, but works around them.</p><p>Think of the following scenario:</p><p>A new developer joins your team. They get a shiny new laptop, maybe you already have boxen on it so all the standard tools are on board.</p><p>Their buddy directs them to the team repository on github, which they check out.</p><p>They install and run bosco for the first time, prompted to put in the organization’s github name, and an auth key from their account that allows read access to their repositories.</p><p>Now, they are ready to go — what can they do with bosco?</p><p>Well, broadly, the functionality is split across three main areas:</p><h4>1. Managing Multiple Projects</h4><p>These commands are all about making your life a little easier. The ones you use the most:</p><blockquote>bosco morning</blockquote><p>This is a wrapper for a number of commands (which you can run individually), but is basically the command you run each morning (or across the day), to be caught up on the changes that your team has made across all projects.</p><p>It does the following across all repositories: clone, pull, npm install, show activity log.</p><blockquote>bosco grep</blockquote><p>Allows you to quickly git grep across all the projects.</p><blockquote>bosco stash</blockquote><p>Stashes any uncommitted changes across all the projects.</p><p>I suspect you’re starting to get the drift — there are a set of commands that basically allow you to run the ‘standard’ set of commands you would use within a single project across many projects.</p><p>If you don’t want to run the command across all projects, you can filter down by passing an extra parameter:</p><blockquote>bosco stash -r name</blockquote><p>Where you can specify part of the project name (this is expanded as a regex) and the command will only run against projects that match — this is used in all commands that work across projects.</p><p>There are a lot more commands, and you can add your own into your bosco project folder (under /commands).</p><p><a href="https://github.com/tes/bosco/tree/master/commands">https://github.com/tes/bosco/tree/master/commands</a></p><h4>2. Running and Stopping Multiple Projects</h4><p>Ok, so you’re a master at using Bosco to make some operations against many projects a little simpler. Now how do you get the project up and running?</p><p>First, a small diversion into what you need to do with your services to make Bosco aware of how they start and stop.</p><p><strong>package.json and bosco-service.json</strong></p><p>If your project is a Node project, then all you need to do is specify a start script in the package.json. Bosco will find this, and when you tell it to run your projects it will use PM2 to start the project via that command.</p><p>If you’re project isn’t a Node project (e.g. it may actually just be a Docker container definition for Redis). Then you can specifiy more detailed configuration by placing a <strong>bosco-service.json</strong> in the root of the project.</p><p>Two examples are below:</p><p><strong>A Node Project</strong></p><pre>{<br> “tags”:[“review”],<br> “service”:{<br>    “dependsOn”:[“infra-rabbitmq”,”infra-mongodb”,”infra-redis”]<br>}</pre><p>This simply adds a tag to the project (this allows you to start a subset based on the tag — e.g. bosco run -t review), as well as define some dependent services that should be started if this one is started.</p><p>The start command is in Package.json.</p><p><strong>A Docker Service</strong></p><pre>{<br>   “service”: {<br>     “type”:”docker”,<br>     “name”:”infra-redis”,<br>     “registry”:”docker-registry.tescloud.com”,<br>     “username”: “tescloud”,<br>     “version”: “latest”,<br>     “alwaysPull”: true,<br>     “docker”:{<br>       “HostConfig”: {<br>       “PortBindings”: {<br>         “6379/tcp”: [{<br>          “HostIp”: “0.0.0.0&quot;,<br>          “HostPort”: “6379&quot;<br>          }]<br>        }<br>      }<br>    }<br>  }<br>}</pre><p>This configuration tells Bosco that this project contains the definition for a Docker container, that when built is published to the registry shown. Bosco will run it after pulling it from the registry (it doesn’t build and run the container from the folder). This is a very light wrapper around the Docker remote API.</p><p><strong>Running Projects</strong></p><p>Ok, so you’re services are configured — you can now get running.</p><blockquote>bosco run</blockquote><p>This will run everything.</p><blockquote>bosco run -r project</blockquote><p>This will run based on a regex match against the project name.</p><blockquote>bosco run -t review</blockquote><p>This will run based on tags defined in the bosco-service.json files.</p><blockquote>bosco run —watch</blockquote><p>This will run the project, but in watch mode (using PM2).</p><p><strong>Seeing what is running</strong></p><blockquote>bosco ps</blockquote><p>This will show everything that is running.</p><p><strong>Stopping</strong></p><blockquote>bosco stop</blockquote><p>This will stop everything (the -r and -t tags still work for stop).</p><h4>3. Managing Static Assets across Multiple Projects</h4><p>The final piece of the puzzle when dealing with micro-services, especially micro services that render HTML (huh? see this post: <a href="https://medium.com/@clifcunn/nodeconf-eu-29dd3ed500ec">compoxure</a>) is that you need a way of managing static assets across projects — css, javascript and images.</p><p>Bosco is the natural place to do this, as it already knows all of our projects, and having it take on this extra responsibility wasn’t a big stretch.</p><p><strong>bosco-service.json</strong></p><p>If your project has static assets, you need to tell Bosco about them.</p><pre>{<br> “build”: {<br>   “command”: “node_modules/.bin/gulp build”,<br>   “watch”: {<br>     “command”: “node_modules/.bin/gulp build —watch”,<br>     “ready”: “Finished ‘build’”<br>   }<br> },<br>   “files”: {<br>     “upload”: {<br>       “basePath”: “dist/”,<br>       “js”: [<br>         “js/moxie.js”,<br>         “js/plupload.dev.js”,<br>         “js/tsl-uploader.js”<br>       ],<br>       “css”: [<br>         “css/tsl-uploader.css”<br>       ],<br>       “img”: [<br>         “img/header-bg.png”<br>       ],<br>       “swf”: [<br>         “js/Moxie.swf”<br>       ]<br>     },<br>     “cx”: {<br>       “html”: [<br>         “ui/cx-templates/backend.html”<br>       ]<br>     }<br>   }<br>}</pre><p>This configuration tells Bosco that the project is built using Gulp (this is optional — if there is no build step you can just point Bosco straight at the files in the project), and that the output of Gulp is a set of files that are defined in the ‘upload’ file group.</p><p>You can have as many file group’s as you like, as these are simply collections of assets that are grouped together in the final output (e.g. the JS is concatenated and minified, the CSS is concatenated) into a single file and then deployed together to a CDN.</p><p>To make this magic work, there are two key commands.</p><blockquote>bosco cdn</blockquote><p>This command runs across all of your projects, grabs all of the assets, and starts a server locally on port 7334 (<a href="http://localhost:7334/">http://localhost:7334</a>) that serves them up. In addition to serving them up, it serves <a href="https://github.com/tes/compoxure">Compoxure</a> fragments that reference the static assets.</p><p>This allows you to include the assets from a file group into a given page. Note that you don’t have to use Compoxure, you could do this via another mechanism like ESI, SSI or even Ajax depending on how your app works.</p><p>You can also run:</p><blockquote>bosco cdn minify</blockquote><p>If you want Bosco to minify the assets, exactly as it would if you ran the command to push to a CDN, but locally. This can be useful if you have any issues caused by the minification process.</p><p>Finally, once you’re changes are ready you can push the static assets up to a CDN for use in non-local environments.</p><blockquote>bosco -e development -b 76 s3push</blockquote><p>This will push all of the fragments and assets up to S3, into a path prefixed with ‘development/76&#39;.</p><p>You can see a real one here:</p><p><a href="https://duqxiy1o2cbw6.cloudfront.net/development/default/index.html">https://duqxiy1o2cbw6.cloudfront.net/development/default/index.html</a></p><p>See some of this in action:</p><p><a href="https://asciinema.org/a/13142">https://asciinema.org/a/13142</a></p><h3>Summary</h3><p>Bosco does a lot to help your development flow with Microservices. It isn’t a build or deployment tool — you should use other things for that — but it does aim to make the life of a developer on a day to day basis less complex when dealing with a lot of services.</p><p>I’ll be talking more about this at Fullstack in London this week, so do ask questions or let me know of any areas I should flesh out in more detail in future posts.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=166dd9ca997e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Micro Service Composition]]></title>
            <link>https://medium.com/@clifcunn/nodeconf-eu-29dd3ed500ec?source=rss-c47ca032350b------2</link>
            <guid isPermaLink="false">https://medium.com/p/29dd3ed500ec</guid>
            <dc:creator><![CDATA[Clifton Cunningham]]></dc:creator>
            <pubDate>Sat, 06 Sep 2014 08:12:32 GMT</pubDate>
            <atom:updated>2014-09-06T08:13:25.092Z</atom:updated>
            <content:encoded><![CDATA[<p>This weekend sees me travelling off to Waterford for a second year, with <a href="https://twitter.com/gabceb">Gabriel Cebrian</a>, a recent joiner to TES who came on board as part of the <a href="https://www.edsurge.com/n/2014-07-30-tes-global-acquires-blendspace">Blendspace</a> acquisition.</p><p>This year I’m talking about some of our recent work at TES, rebuilding a core part of our technology platform using a micro service architecture.</p><p>Why micro services? Well, its an evolution of all the thinking and work I’ve done since I was at ITV 7 or 8 years ago working around trying to bring their disparate IT systems together via the enterprise equivalent of ‘Service Oriented Architecture’. The differences between the two (which is largely semantic, the absence of software companies and management consultants driving a marketing message over substance and {} instead of &lt;&gt;) I can talk about in another post.</p><p>A lot of what I did when at MailOnline pushed this even further, but we didn’t really get it right. What I’m talking about in this post is the 3rd generation attempt.</p><p>To get a good feel for what a micro service is, and isn’t, I’d suggest you read some of these:</p><ul><li>Martin Fowler —<a href="http://martinfowler.com/articles/microservices.html"> Micro services</a></li><li>Fred George — <a href="http://www.slideshare.net/fredgeorge/micro-service-architecure">Micro services</a></li><li>Dejan Glozic — <a href="http://dejanglozic.com/tag/micro-services/">Micro services</a></li></ul><h3>Compoxure</h3><p>Compoxure tries to solve the deceptively simple problem: if you break a page up into a more distributed set of underlying services, how do you bring them back together to create a single page.</p><p>Break a page a part? What are you talking about? Well, consider this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*YgK35pB22bXJm0LwqMz0Hw.jpeg" /><figcaption>A simple resource page on TES.</figcaption></figure><p>This somewhat simple page (which is very important from an SEO perspective), is clearly made up of a number of disparate parts.</p><ol><li>Site masthead and navigation</li><li>Resource summary and download</li><li>Reviews</li><li>Author panel</li><li>Recommended / Related resources</li></ol><p>Now, the interesting thing about each of these sections is that they each have different data behind them, and they each change at very different rates.</p><p>The site masthead needs to be re-used across the site, so it really shouldn’t be stored or managed by the application that renders this page.</p><p>The reviews panel is also generic, and can be used across the site — not just on resources. It also changes (from a data and caching perspective) whenever user leaves a review — this is at a different rate to the summary above it.</p><p>So, imagine a world where we’ve drunk the micro service kool aid, and so create a set of distinct services — all micro ;) — that do one thing.</p><ol><li>Masthead service — for a given input URL it will provide you with the masthead and navigation.</li><li>Resource Summary — for a given resource ID it will give you back the JSON data that represents a resource, or an HTML fragment that represents that data rendered on the page.</li><li>Resource Reviews — for a given resource ID it will give you back the JSON data that is the reviews, or an HTML fragment that represents the reviews rendered. It also exposes an endpoint for creation of a new review, as well as reporting abuse (e.g. a review that is inappropriate).</li><li>Author Service — as above but for authors.</li><li>Recommended Resource Service — for a given resource and user combination, send back a list of resources you think the user would also be interested in.</li></ol><p>Great — these can all be built, have their own data sources (kept in sync where necessary by asynchronous messaging in the background — e.g. as a resource is created or changed it drops a message onto an MQ) and be deployed independently — even by different teams.</p><p>Now — imagine your the team that has the actual responsibility to build this page. How do you put it together?</p><p>The typical option list is as follows:</p><ol><li><strong>Build a ‘Resource Front End’ application</strong>. Have it respond to the original request, and then make a number of service calls for JSON data from each of the services, and then render the entire page.</li><li><strong>Use Ajax.</strong> Build a single page app that calls back to the various services for JSON and renders client side.</li><li><strong>Use ESI.</strong> Use <a href="http://en.wikipedia.org/wiki/Edge_Side_Includes">Edge Side Includes</a> — serving a fairly flat response and letting the edge server compose HTML together.</li><li><strong>Use SSI. </strong>Same as above, but closer to home with <a href="http://en.wikipedia.org/wiki/Server_Side_Includes">Server Side Includes</a>.</li></ol><p>Now, most organisations go for one of the first two. But both have problems.</p><p>If you go with the ‘Front End’ application, you’ve just recreated an application that is in it’s first stages of becoming a monolith, or in the least a single choke point for change.</p><p>To make a meaningful change to any part of the page, you’ll need to modify and test not just the service but also the app that brings it together. For any meaningful change to any of the disparate services (e.g. the masthead), you’ll likely want to test it as given you’re rendering the whole page in one go an error in the masthead service will actually cause the entire page not to render. You then move and start implementing code to call the services in parallel, implement circuit breaker patterns, etc. etc.</p><p>The second, the Single Page Application approach, is fantastic if you’re behind the firewall or delivering an application vs a content heavy site that depends on SEO. You could go down the render HTML on both client and server <a href="http://facebook.github.io/react/">React</a> or Airbnb <a href="https://github.com/rendrjs/rendr">rendr</a> style but this means you have to ‘buy the farm’ and are forever stuck using one of these approaches across your entire estate — as well as NodeJS.</p><p>This is not very micro service-ey. Note that if you are behind the firewall, I’d strongly recommend using this approach above all others — its by far the simplest for developers to reason about and understand.</p><p>ESI and SSI are interesting — as they point us towards a possible solution, but both have their own challenges when used at scale. What if we could just put something in our HTML markup (e.g. from a CMS) that instructs a layer in our architecture to do the composition for us? But in a way that is simple to understand, decoupled and reliable? It could be its own micro service.</p><p><a href="https://github.com/TSLEducation/compoxure">Compoxure</a> is a composition proxy. It’s built as express middleware, so you can build your own application (there is an example in the source) that has all of your configuration, logging etc. vs having to use ours.</p><p>It’s deceptively simple:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wpf-gfoQ7qVsRczi0NrIHg.png" /><figcaption>Compoxure deployment architecture</figcaption></figure><p>You put Compoxure in front of a backend that serves HTML that presents the bare bones of the page (as much or as little as makes sense). If you put it in front of your CMS it could actually serve quite a lot of the page.</p><p>The HTML contains simple markup that instructs Compoxure to go and get some additional content on the way through (formatted to make it easier to read):</p><pre>&lt;div <br>cx-url=&quot;{{server:resource}}/resource-summary/{{param:resourceId}}&quot; cx-statsd-key=&quot;resource_summary&quot; <br>cx-cache-key=&quot;resource:{{param:resourceId}}&quot; <br>cx-cache-ttl=&quot;5m&quot; <br>cx-timeout=&quot;2s&quot;&gt;&lt;/div&gt;</pre><p>This declaration will get parsed by Compoxure, and do the following if you request /teaching-resources/resource-12345/</p><ul><li>Check the cache at <strong>resource:12345</strong> for content. This is currently Redis only, but you could build an adaptor for something else.</li><li>If miss or stale:</li><li>Make a call out to the resource server (defined in config so it can be changed centrally), at <strong>/resource-summary/12345</strong>.</li><li>It will wrap this call in a circuit breaker, so if it starts to struggle it won’t hammer it into the ground, along with a short timeout.</li><li>If there is any issue, it will simply close up the space (unless configured to display the error — e.g. in development).</li><li>If it is a good response, it will then add it to the cache, and render the response inside the div (or replacing it if you tell it to).</li><li>It will call the logger and statsd functions (which you wire up to your own handlers), so you can keep a very close eye on what it is doing and how it is performing.</li></ul><p>What this means is that you can now safely make as many changes as you like to the resource summary service, and provided it continues to render HTML when asked, the risk of any one change breaking the entire page is drastically reduced.</p><p>To learn more, check out the github repo — it’s public — and any ideas or contributions are of course very welcome.</p><p><a href="https://github.com/TSLEducation/compoxure">https://github.com/TSLEducation/compoxure</a></p><p>If you’re coming to Waterford for Nodeconf I’ll be talking about this and another tool called <a href="https://github.com/TSLEducation/bosco">Bosco</a> — which solves the parallel question — if you have a set of distributed services, how do you manage the static assets like JS and CSS?</p><p>See you in Waterford!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29dd3ed500ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>