<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

 <title>Luca Grulla</title>
 <link href="http://www.lucagrulla.com/atom.xml" rel="self"/>
 <link href="http://www.lucagrulla.com/"/>
 <updated>2015-10-23T06:11:07+00:00</updated>
 <id>http://www.lucagrulla.com/</id>
 <author>
   <name>Luca Grulla</name>
 </author>

 
 
 <entry>
   <title>Evolutionary Architecture and Microservices: a real world example</title>
   <link href="http://www.lucagrulla.com/posts/evolutionary-architecture-and-microservices"/>
   <updated>2015-07-01T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/evolutionary-architecture-and-microservices</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://martinfowler.com/articles/microservices.html&quot;&gt;Microservices&lt;/a&gt; have received a lot of attention over the last few years. As an architectural style it delivers a lof of benefits compared to a &lt;a href=&quot;http://en.wikipedia.org/wiki/Monolithic_application&quot;&gt;Monolith application&lt;/a&gt;, but there&amp;rsquo;s no doubt that it comes with the cost of a distributed system (such as discoverability, fault tolerance, data consistency just to name a few).&lt;/p&gt;

&lt;p&gt;I believe a Microservice architecture shouldn&amp;rsquo;t be your starting point. Instead, it should  be the result of applying Evolutionary Architecture and &lt;a href=&quot;https://en.wikipedia.org/wiki/Domain-driven_design&quot;&gt;Domain Driven Design&lt;/a&gt; principles to your system, balanced with a analysis of the maturity stage of your product (both from a business and technology perspectives).&lt;/p&gt;

&lt;p&gt;While building &lt;a href=&quot;http://www.uswitch.com/car-insurance&quot;&gt;uSwitch car insurance&lt;/a&gt; we followed exactly these principles; since the beginning of the project until today we refined our architecture based on our increased understanding of the business needs, moving from a monolith by choice system to a well defined microservices architecture that keeps evolving and improving.&lt;/p&gt;

&lt;p&gt;If I look back at these 3 years I can identify five major stages:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;#fast-development-cycle&quot;&gt;Fast development cycle&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#support-business-workflows&quot;&gt;Support business workflows&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#separation-of-concerns&quot;&gt;Separation of concerns&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#decouple-and-scalability&quot;&gt;Decouple and scalability&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;#leverage-ecosystem&quot;&gt;Leveraging uSwitch technology ecosystem&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;&lt;a name=&quot;fast-development-cycle&quot;&gt;&lt;/a&gt;Stage 1: Fast development cycle&lt;/h2&gt;

&lt;p&gt;We wanted to build a new product from scratch and we wanted to go live as soon as possible.
Our first architecture was optimized to enable us to have a fast development cycle and the shortest path to production.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/ArchitectureV1.1.png&quot; style=&quot;border:0&quot; alt=&quot;Architecture for fast development cycle&quot;&gt;&lt;/p&gt;

&lt;!--
&lt;div class=&quot;mxgraph&quot; style=&quot;position:relative;overflow:hidden;width:100%;&quot;&gt;&lt;div style=&quot;width:1px;height:1px;overflow:hidden;&quot;&gt;3Vhdb+soEP01eWzl2IkTPzbddu9KW+lKlbbdR2KwjYpNhHE++us72ION4ySbarNN9+YhMgcY4JwZGBgF9/n2d0VW2ZOkTIx8j25HwW8j34+mE/g3wK4BQn/eAKnitIHGHfDM3xmCHqIVp6zsNdRSCs1XfTCWRcFi3cMSKXAINLYiqTXfAc8xEUP0hVOdNejcDzv8B+NpZocZh1FTU+qdtUFZQiqhb2oI6kx1TqwtnMjWs6tEAzsEwKYdq+j1eJcy7wGKlR1ZuF7eX39B1r0uS6koUz1I8OLNJTJ4AC2VlGDIfOXbeyaMnlaraRTPyTiaTWicRBM6v2nsPJ7bvF2dYgVO9t+aRI7XRFRIxwtbllyzgTRKVgVlxs54FCw2GbR5XpHY1G7AeQHLdC6wuuaXLOu+ppzLtVNSUhPtlHEOTGmGnn/OSjvKIXyYzJlWO+Md1r1QJAwdf4rlTeebfohY5vhlFDQYQWXT1nTHK3wgtWfSjDHg0AwkvIE7+QEq4DANtiBAobAoM7IyYCxkBaa/P+vTCG1Y1mezAetzhFzSQ+x2UdLHQ+duWcfxflHW7cqvwbrpe4z14pdi3VKKrAdTtPkVrM9p4ocw0XgSzMJoeWAfH1ANp5XhmXIFRz2X5oQsZWVm6vJaaiOWPcC/B9OB9ecTe7nd7i++le8zjSmZw/QfhWapIobTcuSHAkYHltfwmZpPCy0hAvoIjN1rtycYMGjwgTj3UkiTiBSyFjThQuxBRPDU6BsD4yZnWRg9OKRqd1iRc0rNMAejTELrRMgNIBm0Y9BhkUCY/sBZuB60YaWZo6n+C4qQiDUe0dRGdfn6/uPt5QJzTBzdSD3gPzbPu6j/4I7g+M+TLFI5UN/uhxToKbVUx9Q6Gbv/BZttqNl9L8JLicPmocTKYhdlE4d2TxQKtxIsSqUzmcqCiIcOBZezmaxxT4c/tuX61cC3Uyz9jY2AK7VzqkzR1DWsE6XvlKoDJhakLHls4UeIzZ4UZnafFAJWJytVS37Cn2C0lB2zU2+fQ0EVExCp6/6ELirP8IZ3AXnsdy1Op0cjzzh09YHqtv4nUxxWVN/hjOUzdYsrtW6vPZcS8cg17KSIzSF4DRVtwH9Kxh5v30zTa8pYXwWvouKBO89XqujN+ipO/sciNun1V6gIb4AxPIoFY+JNwniK7ztu+vD69OcZqaObhRmSP5UlCrJkYkHit7R2AZttwo0uqX+tGviQiON0L2X/lIEc9tWjKciNdzsLPTz7z+Yczf2UHMbtmsgkKUHofVHaUQ/pBMXuna9p3j3gBg8f&lt;/div&gt;&lt;/div&gt;
--&gt;


&lt;p&gt;Even if at the beginning of our journey we identified two separate concerns:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;serving the actual &lt;a href=&quot;http://www.uswitch.com/car-insurance&quot;&gt;website&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;integration with multiple insurance APIs for real-time brokerage&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Although our experience was already suggesting that Microservices could be an excellent solution for the problems we were going to solve, we wanted a fast development cycle minimum friction between changes and access to production; we also didn&amp;rsquo;t want to get distracted in building solutions that won&amp;rsquo;t add much value for our Release 1. We explicitly chose to build a monolith &lt;a href=&quot;http://rubyonrails.org/&quot;&gt;Ruby on Rails&lt;/a&gt; application, with a well defined internal boundary between the web code and the integration layer.&lt;/p&gt;

&lt;h2&gt;&lt;a name=&quot;support-business-workflows&quot;&gt;&lt;/a&gt;Stage 2: Support business workflows&lt;/h2&gt;

&lt;p&gt;Once the new product went live sales reports from our partners started to flow in (mostly as CSV files over FTP). With sales data we started to identify KPIs and draw correlation between the web traffic, partner offers and the different conversion rates. We knew that the data aggregation and analysis could be done manually for a short time of period, but we had to automate the workflow before the volume was growing. We therefore introduced a new system responsible for sales data ingestion and for producing analytical dashboard.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/ArchitectureV2.1.png&quot; style=&quot;border:0&quot; alt=&quot;Architecture for good support of the business flow&quot;&gt;&lt;/p&gt;

&lt;!--
&lt;div class=&quot;mxgraph&quot; style=&quot;position:relative;overflow:hidden;width:100%;&quot;&gt;&lt;div style=&quot;width:1px;height:1px;overflow:hidden;&quot;&gt;3Vnfb+I4EP5reOwJEgjksfTa60q3Uk+sbu8eTewEqyZGjvnVv37HyZjYSUBUS6G7PKD4szO2v2/GHju98GG5+0uR1eKrpEz0gj7d9cI/e0EQj4bwb4B9BUTBpAIyxWkFDWpgxt8Ygn1E15yywmuopRSar3wwkXnOEu1hqRTYBRpbkcyar4FZQkQb/c6pXlToJIhq/JnxbGG7GURxVVPovbVBWUrWQt+VENSZ6iWxtnAgu76dJRrYIzDB8ork3pDepFx6FhQraq5wutyffk423itzqShTHiR4/uryGD6ClEpKMGSelrsHJoycVqpRnEzIIB4PaZLGQzq5q+w8ndv8QLBiOQ72Z00ixRsi1kjHdzYvuGYtZZRc55QZO4NeON0uoM1sRRJTuwXfBWyhlwKrS37JvHzXlJdy45SU1EQ7ZRwDU5qh458z05pyiB4ml0yrvXEO610oEkZOMMLytnbNIEJs4bhlHFYYQWWzg+maV3hAas+kGUPAoRlIeAV3CkJUwGEabEF8QmFaLMjKgImQazD9+VkfxWjDsj4et1ifIOSSHuFrFyV90HbuA+vY32/Kup35LVg37x5jPf+tWLeUIuvhCG1eg/UJTYMIBpoMw3EUzzvW8RbVsFsZnilXsNNzaXbIQq7NSF1eC23Esvv352A6tP58Yi23y/3Fl/Im05iROUx/yTXLFDGcFr0gEtA7sLyBx8w8WmgOEeAj0LfXriEYMGjwljgPUkiTiOSyFDTlQjQgInhm9E2AcZOzTI0eHDK1e6xYckpNN51RJqF1KuQWkAW0Y/DCNIUwfcZRuB60ZYUZo6n+F4qQh1UeUdXGZfn2/tNv5AI2T3QjtcN/bJ53Uf/BFcHxn68yz2RLfbseUqCn0FIdU+tk7H4Em4dQs+tejGcSh82uxMpiF2UTu3Z3FAqHEixKpRcykzkRjzUKLmczWeOeDn9sx/V/Bv5jhKX/sRFwpfZOlSmauop1ovS9UmXAJIIUBU8s/ASx6UlhRvdOIWB2cq1KyU/4E/SWsWN2yuWzLahiAiJ14w/oovK0D3gXkMc+l+LUelTyDCJXH6g+1L8wxWFG5RnOWD5Tt2StNodjz6VEPHIMOylitQneQkUb8O+S0ePtk2l6SxnLo+BNVOw481xTxf7YV3H4C4tYpdfXUHEckmE8IJACzydkTPF+x00fZnABB3ln/0ueQTIGaWDwdA8q7iHhA/hnbnE+5l7G3tlhjt5xLWMPUm72ML5E9tAkE/txc7H97J+/f51cbDj0c7F4dL1UrElmx0XWx+71jU3h+ivHkdj0Vo5Ol7vFwoFn4Y/MlMsaJ1OGUHcl+iTr/Tmq3SyBbg6ufdvw/O3byxlXBe6p25D8rlsBQeZMTEnympUeYG8X4AYvLX+nVjP8lIRdu1+PHJ06nfPoKncHyQNsC95Kh72drQAaf5EcBlE3kWlagOpNiQ5j6FINivVHnqp5/fEufPwB&lt;/div&gt;&lt;/div&gt;
--&gt;


&lt;p&gt;In order to give reliable visits to sales conversion rates the newly built dashboard had to have access to some web-centric data(such as number of unique visitors, number of completed journeys etc etc). We introduced a simple REST APIs on the web layer and use cron jobs to do scheduled data transfer from one system to another. This solution allowed us to move forward, and because it was flawed by choice (data duplication, poor resiliency) it forced us to think over time about what we really need in that space.&lt;/p&gt;

&lt;h2&gt;&lt;a name=&quot;separation-of-concerns&quot;&gt;&lt;/a&gt;Stage 3: Separation of concerns&lt;/h2&gt;

&lt;p&gt;It was time to move our architecture towards &lt;a href=&quot;https://en.wikipedia.org/wiki/Service-oriented_architecture&quot;&gt;SOA&lt;/a&gt; to benefit from much clearly defined &lt;a href=&quot;http://martinfowler.com/bliki/BoundedContext.html&quot;&gt;bounded contexts&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/ArchitectureV3.1.png&quot; style=&quot;border:0&quot; alt=&quot;Architecture for separation of concerns&quot;&gt;&lt;/p&gt;

&lt;!--
&lt;div class=&quot;mxgraph&quot; style=&quot;position:relative;overflow:hidden;width:100%;&quot;&gt;&lt;div style=&quot;width:1px;height:1px;overflow:hidden;&quot;&gt;7Vpfk9o2EP80PF7G8j/g8bhemnSa9jpkmvRR2MJ4zlhUFneQT5+VvcKyDT4C9sGlZRhAK7GW97e/1WrlgXO33Pwq6GrxiYcsGdhWuBk4vwxse+y58KkE20Lg26NCEIk4LESkFEzjbwyFFkrXcciyykDJeSLjVVUY8DRlgazI5jzBS6CyFY20+lIwDWjSlH6JQ7lAKfHHZccHFkcLvM7I9ouOTG61jpDN6TqRN7kI+lT3kmpdOJGNVTQ9vOIW28RH66xoWvnDN86XFYFgWWkrvN24evspfar8ZcZFyERFlMTpo2lH5x6gFJyDIvVrubljiYJTQ+X7PpmFrj0kjIQ+m90Uet4fO3xnYMFSnOy5KtHETzRZozm+sFkWS9ZARvB1GjKlhwycyfMCxkxXNFC9z+C7IFvIZYLduX3pLP+vai/5k9ESXFJptHEOTEiGjn/MnZYmB/YwvmRSbJVzoG/gnSFxXNsp2s+GZ/peIVsYTjlEbCkCG+00l2aFH2jZI62M1zas/DGVLBJUxjzNXtPU8zhJ7njCC0d25vkL5JkU/JEZPVb+gh6YZRgDCrov5Skom2QLGvJnaKsxfQDoOIjEVSCIcXgvSMoCBiCZpELeCpFbJ0holsWBFr8H859BERY2IvBL9oU587XIfaeF/zC3iB3Sk9v9IE42waCrcfKw3an9EWeDQR8+f34ANb9N//yjgQ24IdxMG0vgTZM4UstEABZUgX2i/DeG5ewWO5ZxGKo/TBI6Y8mEBo9RDvo+/pwY4HDdxaHmUtuCa+6LB/G4sd7ZloNLLmKi3VewBELOU9WH9uGE2h94DLMoh/D5PAM3qQO5m8Rp2GIWYGALBnwESGwH3dOAFnRB8oIRaKWEQcLXoPr6lyS/HtE0U4yINho2A5rfAtTJhMJLG0Yf2H6iWJOp7Mm0uf/vWqU0E0h32I2e2C0MIe47Z6xePhl5juWsNuVg+BWp7ymkh7DCWR/TiGUSeINXgQkXFyqGvfV0gzgYoRDbXdJrYGuPcQWrgNvHakXwhvZRSq8KPyWlHG3iS1CKtAQycPSfyOp644ZW93ScvojV8UKmaSFNmmKTC7ngEU9pcl9KwUoHkje2ieVX4/c/asg77/i0LliLp13Y6itra8/I3HE1FrmaJEes9Bpht7ZU1VUUCSP+66x0gIwCahNG3TkhM8u90emkwaKvn37/wRQv35R0nOJ1m8QVbtvE8NQUTWd/tYCoV4J+MziN2Q9xsMKU/gh5JRxs2xUdycFxbxxsGgCzl/8B7RLQGje9eu53AFAwCVUz0cNWakBeNdp/HU9XQGpT3RUFXxiv51X6UzGDzrzLadbDbsGXthCazyyG9VKI8nC6ugavi+tmIUrH/K5T+/rq2KzXfuJpxBtW0zllCMmg2nYpfr5gu6IEqCv3vW2UrFruqKOcYU1vT+7YRVWpbkzEtdvMsYhlOrLlPSnM0+hSzTzqXT7m7Sn/7fW4M/KUU8HBkpXp6dvpX81E8Go93R1W4wbRYfYCno5r15XskfryZjRcmzcfqJ327s3N0sADz2QEe5a349DOCDmpQ7de9C7g0L1s+s8I3fpUzPD08mDsBE/vfGPokmo0cscIplZRMKuRfL6oyKvPpb/SwCm7zDe9Xh+IIu2ndQf2Mb2HOF1q6BoeuwWfIXixgRCcfVmuoyUPTMRwV/lDG2+PsHCIV+EZHB+cRlgyrB3Q6rD9CrW8ZhKHx7Z307/feklvv/+3ncsSd1hdQTH9vopj2cbtNB/O6oTOwxY6E3hqp1M6szRsBmsQdhGqO2e841VLTPAQzmmMrytyX2+J1qcx/w3G5xRpfRIDKH85jkOzfBqxGF4+Zercfwc=&lt;/div&gt;&lt;/div&gt;
--&gt;




&lt;!-- ORIGINAL
The integration layer had been living at the boundary of the web system so far, but it was now time to pull it out in an independent service and let it evolve independently from the web. The new service was responsible for pure data transformation: receiving the internal representation of a user profile, transforming it to the different XML flavours expected by the different integrations and transforming the responses back in a normalized representation ready to be used by our website. We felt that the problem space was a good fit for a functional language and we embraced [Clojure](http://www.clojure.org/). The integration between the website and the new aggregation service was HTTP POST with JSON as data type. We also started understanding more of our analytics need: a [Postgres](http://www.postgresql.org/) instance logically close the Integration layer became our analytics data source.
--&gt;


&lt;p&gt;We knew from the very beginning that the integration layer and the websites were two different contexts; while one is responsible to collect and present information the other is responsible to communicate with the external partners and transform data between multiple representations. The integration layer had been encapsulated at the boundary of the web system so far, but it was now time to reify it in an independent service and let it evolve independently from the web. The new service was responsible for pure data transformation: receiving the internal representation of a user profile, transforming it to the different XML flavours expected by the different integrations and transforming the responses back in a normalized representation ready to be used by our website. We felt that the problem space was a good fit for a functional language and we embraced &lt;a href=&quot;http://www.clojure.org/&quot;&gt;Clojure&lt;/a&gt;. The integration between the website and the new aggregation service was HTTP POST with JSON as data type. We also started understanding more of our analytics need: a &lt;a href=&quot;http://www.postgresql.org/&quot;&gt;Postgres&lt;/a&gt; instance logically close the Integration layer became our analytics data source.&lt;/p&gt;

&lt;h2&gt;&lt;a name=&quot;decouple-and-scalability&quot;&gt;&lt;/a&gt;Stage 4: Decouple and scalability&lt;/h2&gt;

&lt;p&gt;At this stage we had consistent traffic and sales to really benefit from a more mature data pipeline and analytics platform. REST style integrations brilliantly supported us until this point but we were at a stage where we wanted to increase system resiliency. uSwitch teams have been long time users of &lt;a href=&quot;http://kafka.apache.org/&quot;&gt;Kafka&lt;/a&gt;. Kafka is a distributed message system with an eye on message durability. We decoupled the integration layer from the analytics data store(the data transformation was a stateless service by definition anyway) with a set of Kafka topics and few workers. Now the integration layer was just publishing useful information to the topics, enabling multiple consumers to fetch data to support different needs.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/ArchitectureV4.1.png&quot; style=&quot;border:0&quot; alt=&quot;Architecture for improved scalability&quot;&gt;&lt;/p&gt;

&lt;!--
&lt;div class=&quot;mxgraph&quot; style=&quot;position:relative;overflow:hidden;width:100%;&quot;&gt;&lt;div style=&quot;width:1px;height:1px;overflow:hidden;&quot;&gt;7VrdkqI4FH6avpwp+RO9bHt7dmZ3e7e3nNqZvYwQkGokVsBunaefEziBQJB2FNSeXcuyzEkM8fvOP9xYd6vtr5yslw/Mp/GNOfK3N9YvN6Y5dWz4FIJdIRibk0IQ8sgvREYlmEffKApHKN1EPk1rCzPG4ixa14UeSxLqZTVZwGK8BG62JqHcvhLMPRLr0i+Rny1Raoyn1cRHGoVLvM7EHBcTabaTe/g0IJs4e5eLYE5Mr4jcCw+yHSEabjHe4Vi5UlL7wTfGVjUBp2mFFf7dqP73E/Jc+8mCcZ/ymiiOkicVR+seqOSMwUbi22p7R2NBp6TKmXoTYkxd2/eCqe1P3hX7fDh0eQkwpwke9tQtEeJnEm8Qji90kUYZ1ZjhbJP4VOxj3FizlyWsma+JJ2ZfQHdBtsxWMU7n+JJF/lsxXrFnZcRZRjJljGegPKOo+If80wpysB7KVjTjO6EcqBtoKGg4tmkV4xdFM8dOIVsqSukitwSJDcudK1jhCyJ7IMp4bQXlT0lGQ06yiCXpOaEOoji+YzErFNkK8hfI04yzJ6rMjPIXzMAp/QhYkHMJS2CzWbokPnuBsVgzBIGWhUxcBYPoh1tJEggohKQZ4dkt5zk6XkzSNPKk+APAf4KJUF/zwK/hC2dmG57rTof9w9lCum+fHPe9PJlGw9IcHPeKP/KsWNDHz58fYZvf5n/9qXEDagh/pstK4E3iKBRhwgMEhWOfCf2NIJzd4sQq8n3xg1lMFjSeEe8pzElvs58jHRzGXVyqhtoOXnNd3MvHu9F7c2RhIEROpPpyGoPLea7rUBtPuPsji+AU1RIWBCmoSZPI8hDHcYtZgMItAPgElJgWqqdCLewFyQt6oLUQejHbwNZvICQ1PZq0FMWjTTClUR3auIOoow0KFUQBfQ6JHMSi0ackpKmwiDeeARgQvlS4DRkYFLgtow3vIQKIoWdapZZLR/1Tark11eP22bTc0DOv38lTQDTAJcxLuiUhA+8/W1MewQHylB+lj5XoNR6GQNa2Zb2DkddFI1aQnZ5NnzGkqJUD46DPJ6azQwDnTOoqaU504BxcogInZf0Cp3ve24TEO0g9rhC6sY0WJJ3oVHeihsxaBlc68dt9TjT5qZyobI0g7I7MhC7hRGXhpUILhcgch4xnSwbekcT3lRRQ2lMe0W2UfVW+/yuWvHcOL5y8DX8uTWKouqi75rGnWI/ITE7GvANy6dKwGslgc4uiJMNf9Ztwm3o1+zqhNdiHY/dKCO0qYg8kVHrKcxCKp/+f0D4JbSSyTjOk7SEUICHiJHLZWizIQ3v7dRxZlzSOWvZwX1kvz1XpU3GCY7UL7jYspgs3IGRiByPTxpayGnS/Pvzxgz2XvEvYc8+lu4XyowG5sCFdoY7tmch2jIORu2zFoPMduKeCKAwds4ey7qJw652NZiVgjTAbP4OTlrlZv5QUNJSknN/hnsiILYssyYi8ddmzl7VlK6Bxnb685tiFpN2cjBfUdQPP8Fq85gNLQra38+BDUZFmjAvWX6lPips18h7rYP0zWW111CBOSw3SR/9fQ1Mv/B5287/1KHS1aNrSI5fdSNzzEmgOUtAJcT04AFZ8V8YNMbhU9rhPnzrve+Wh4QSHdzQ9emvtkaVZCPnU29H3sYv/ouy5YUJ+CX0/pjw6Ihkq9T03hQ59l/fQFWU/KXL3HpW1Jr6BEMotCuPSorK+kVuvw7SN+ku4NNb1p4t6z7dKx6ZMlbxfvkaWvWbVzbV7m0u4ObT0/zA/LVGoPY+8BD2oO33TA3V2vV5R+Jk4NYZK9pQbb9dAG6ZP15k8yPpJf1Tmbv7P1XRtjnwWpl1Ju56FGZWJyFU8/KLTNVBXoGZmDTc4dq16gnKthtYSvtp96EUMTa9Jf2JDK/R0r6WBDjX6nHixS1gdDKunsIvl1dP11v13&lt;/div&gt;&lt;/div&gt;
--&gt;


&lt;h2&gt;&lt;a name=&quot;leverage-ecosystem&quot;&gt;&lt;/a&gt;Stage 5: Leveraging uSwitch technology ecosystem&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/ArchitectureV5.png&quot; style=&quot;border:0&quot; alt=&quot;Architecture for a better integration with the company technology ecosystem&quot;&gt;&lt;/p&gt;

&lt;!--
&lt;div class=&quot;mxgraph&quot; style=&quot;position:relative;overflow:hidden;width:100%;&quot;&gt;&lt;div style=&quot;width:1px;height:1px;overflow:hidden;&quot;&gt;7Vptc9o4F/01+ZiMXwn+WNJ2093Nbp6lM+l+6ghbtjUxFiObBPrre2VfYRmZlyUYSOdhGAZf2UI+574cXXPl3k0XvwkySx94RLMrx4oWV+7HK8cJfA8+pWFZGwbOsDYkgkW1yW4MY/aDotFC65xFtGidWHKelWzWNoY8z2lYtmwxz/AncLIZSdT0jWEcksy0PrGoTGvr0Bk09nvKklT9jD0I6pGiXKo5IhqTeVZeVyYYk8NToubChSys+tBHMJZ4bFtomJG8dcEPzqctg6BFgxXeLmvffk5eWpdMuIioaJkylj/rOLqfgErBOUwkv00XdzSTdCqq/CAcEju49aIwDrxoeF3P83nf01cAC5rjYt86JUL8QrI5wvFEJwUrqcGM4PM8onIe+8odvaZwznhGQjn6Cr4LtrScZjhc4Usm1bXyeMpftCPBS1Jqx7gGKkqKjr/PnTaQQ/RQPqWlWErnwEhB38LA8Ry3Pn5tPNMe+LUt1bzyFrklSGyymrmBFb4gsnuijL+tofwlL2kiSMl4XpwS6phl2R3PeO3Ibly9wF6Ugj9TbcSqXjACq4wYsKDGcp7DZKMiJRF/hWN5Th8Eui4ycREMYh7uJEkioBFSlESUH4So0AkzUhQsVObPAP8bQoRGRgbehS+smc9F5Ttb4h/WltBN81S4b+TJsVUWRp5UVj4q/sizFkH3X78+wjS/j//+y+AG3BBuZluUwJtkLJFlIgQEZWIfSf9lUM4+4MCURZG8YJSRCc1GJHxOKtK74ufABId1F0/VS+0WXitf3MjHtXXjWG47+yn3FTSDlPPS9qEunnD2R85gFc0pPI4LcJN1IleLOIxb1AcatwDgM1DiuOieGrUwF4gXzEAzaQwzPoep30FJWs9oKlK0jDa8NRPaYAtRBwcUOogG+hiEHNQi60ue0EJGxDtXAPagDbetCoNeQJSthXcfBcQ2ldbKy1Wi/iW93A3Mun0yL7dN5fUHeY6JAbiCOaULknDI/qMZFQwWUEl+tD42pl089KKIBpjGEVnnFoNYQzboQrYXfzYTyIecZEuooG8UtL045XouCDpygSq+vWMnr92UC/JfKheovT/C7quCfo5coPYPOrSgp8d4yEWZcghykn1qrIDSBpVPF6z8pn3/V55y4++v/8O5eFmFRF/yfrt09wKU1UqQqNS9hyRUDHtrmmZ9inpngVcdVzc65qZsN6Et2Ptj90II3bYX25NQlSlPQSiu/v+EHpPQNT3mr5e0DYQCJESuRJ02kydUpb37d3wlpdeWumpF7jhfravxp3oFh3qXbU1CdxA4gTPx3NibXKueuFZ1vz38+R97B1W368i9g+N2B+ogMj3q0L2/ait4WKdXLQUs5UftDbieFfvu7WQQwbfhcNLVn+YClNIFakzfwzmUPB9ifdLEjt8hMZXtLWLHwK3D2efjV1aGKRg/gvB7ghtN+Rx0pbEVqlrB6gkO3PAuMJUsnS6gVzxLbyYEUugN8vFdSA/Ok3lGxHcIEJCuMrwiJu3Q/YbrKCmkKQaZe98jP56PzqT2AJa5fercAxyjoWwS1NHa6kONAlpiKYfkFdXBhtKn+vpa3Wta+8eve2pnrneeu6P/DanscHZ62SsgI4qfFjsNWXLMeI5wYnY6yNnA4FnYwV3l6di5rNjZ56HN+dhRKfR0ma0dO3KCc7KDVeUy2DFUsKkLHnie8I0N0Qi0QlFyIRHcpQNawqG3tr7q46h9g+ox6TKro6d0jMeS5p6i/0RUjezr6qffv3bkom6fO4ezm7uHh+X4f+ae72Kd3W8/x7UH6Njn8PVeiu7+gtVzXWXQnsOcIQQ2ednWhF/xeI4QQO/QQuAfGhUpi+ut+vuIArfde7ADnPMcYYBzXsy+7fT+jkhvFzhnc3jzP6W97A1OqDA3NcW21tyKpOPjD4fNH1zrBl/zx2X3008=&lt;/div&gt;&lt;/div&gt;
--&gt;


&lt;p&gt;We are now 30 months from the go live  and this is our current architecture. The amount of data we produce and collect grew together with our business, and Postgres is not a viable solution anymore. We moved all our long-term analytical data to &lt;a href=&quot;http://aws.amazon.com/redshift/&quot;&gt;Redshift&lt;/a&gt;, getting us aligned to other uSwitch product teams that were already using it. Redshift now works as cross-channel data warehouse, enabling more in depth analysis and reports than before.
We also replaced some of the REST based integrations with more Kafka topics: this gives us better resiliency and the benefit of a set of internal tools build for replayability.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Javascript: how to create partial functions</title>
   <link href="http://www.lucagrulla.com/posts/partial-functions-in-javascript"/>
   <updated>2014-12-30T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/partial-functions-in-javascript</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Currying&quot;&gt;Currying&lt;/a&gt; and &lt;a href=&quot;http://en.wikipedia.org/wiki/Partial_application&quot;&gt;partial application functions&lt;/a&gt; are very powerful techniques widely adopted by many functional langagues.&lt;/p&gt;

&lt;p&gt;If you work with Javascript you can use the core function &lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind&quot;&gt;bind&lt;/a&gt; to easily create partial applications.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s look at an example.&lt;/p&gt;

&lt;p&gt;We have an array of objects:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cities&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Paris&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;France&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;London&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;UK&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Rome&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Italy&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;},{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Manchester&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;UK&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}];&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;and a function that given a city object and a specific country returns true if the city belongs to the given country:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;isIn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;city&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;city&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;===&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;isIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;UK&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;London&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;UK&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;What if we&amp;rsquo;d like to filter the array looking for cities that are in a specific country?&lt;/p&gt;

&lt;p&gt;A partial function is a good approach to solve the problem, and &lt;em&gt;bind&lt;/em&gt; makes the creation of it very simple.&lt;/p&gt;

&lt;p&gt;The syntax of  &lt;em&gt;bind&lt;/em&gt; is the following:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;fun&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;thisArg&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;arg2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;...]]])&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Where the first parameter is the value we want to bound the &lt;em&gt;this&lt;/em&gt; keyword to when the created function is invoked while the others are the actual parameters of the bound function.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;UKCity&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;isIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;UK&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;//don&amp;#39;t need to set the this keyword, just passing null&lt;/span&gt;

&lt;span class=&quot;nx&quot;&gt;UKCity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;London&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;country&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;UK&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;//true&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;We can now use the partial function &lt;em&gt;UKCity&lt;/em&gt; as argument of the &lt;em&gt;filter&lt;/em&gt; function:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;UKCities&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;cities&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;UKCity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//UKCities === [{name: &amp;quot;London&amp;quot;, country: &amp;quot;UK&amp;quot;}, {name: &amp;quot;Manchester&amp;quot;, country: &amp;quot;UK&amp;quot;}]&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;//get the list of the Italian cities is as simple as:&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;cities&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;filter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;isIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Italy&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//[{name: &amp;quot;Rome&amp;quot;, country: &amp;quot;Italy&amp;quot;}]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In the example the creation of a partial application function allows us to seamlessly compose our initial &lt;em&gt;isIn&lt;/em&gt; function with a &lt;a href=&quot;http://en.wikipedia.org/wiki/Higher-order_function&quot;&gt;higher order function&lt;/a&gt; like &lt;em&gt;filter&lt;/em&gt; to achieve more sophisticated outcomes.&lt;/p&gt;

&lt;p&gt;A gist with the whole example code is available &lt;a href=&quot;https://gist.github.com/lucagrulla/67661d178e4f83812a3d&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Clojure: graceful shutdown of an embedded Jetty instance</title>
   <link href="http://www.lucagrulla.com/posts/graceful-shutdown-of-an-embedded-jetty"/>
   <updated>2013-07-15T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/graceful-shutdown-of-an-embedded-jetty</id>
   <content type="html">&lt;p&gt;At &lt;a href=&quot;http://www.uswitch.com&quot; title=&quot;uSwitch&quot;&gt;uSwitch&lt;/a&gt;, several of our services are actually &lt;a href=&quot;http://clojure.org&quot;&gt;Clojure&lt;/a&gt; applications deployed with an embedded Jetty server(via the &lt;a href=&quot;https://github.com/ring-clojure&quot;&gt;Ring&lt;/a&gt; adapter) which are managed via the standard Unix service interface.&lt;/p&gt;

&lt;p&gt;For the business critical services, zero downtime is a fundamental requirement: here comes &lt;a href=&quot;http://www.eclipse.org/jetty/&quot;&gt;Jetty&lt;/a&gt; graceful shutdown.&lt;/p&gt;

&lt;p&gt;Once the ready to be released uberjar is deployed, we signal the Unix service that wraps our Clojure application with a restart. As part of the shutdown process Jetty will immediately close the HTTP listener(freeing the used HTTP port and making it available to the newly deployed embedded instance) while it will still take care of completing the ongoing HTTP connections.&lt;/p&gt;

&lt;h2&gt;Ring 1.3.x and Jetty 7&lt;/h2&gt;

&lt;p&gt;If you are using Ring 1.3.x or older you are embedding Jetty 7. In that scenario this is the necessary configuration:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/e3c650b0995abb9b4573.js&quot;&gt; &lt;/script&gt;


&lt;h2&gt;Ring 1.4.x and Jetty 9&lt;/h2&gt;

&lt;p&gt;with Jetty 9 the web container is now capable of keeping track of the open threads and to completely shut down itself once the threads are completed(rather than waiting for a fixed amount of time). With Ring 1.4.x and higher the code will then look like:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/8ca1126f330e91221d84.js&quot;&gt; &lt;/script&gt;

</content>
 </entry>
 
 
 
 <entry>
   <title>Web development in the large</title>
   <link href="http://www.lucagrulla.com/posts/web-development-in-the-large"/>
   <updated>2013-03-10T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/web-development-in-the-large</id>
   <content type="html">&lt;p&gt;Web development has drammaticaly changed over the past 5 years. Frameworks like &lt;a href=&quot;http://rubyonrails.org/&quot;&gt;Rails&lt;/a&gt; imposed themselves as the go-to choice for an increased productivity; new stacks like &lt;a href=&quot;http://nodejs.org/&quot;&gt;NodeJS&lt;/a&gt; emerged and offered alternatives ways of tackling web products development.&lt;/p&gt;

&lt;p&gt;Despite all these goodies offered by these tools, web development often ends up being way harder than what it should be. Teams sink in a never ending bug list, often adding unneeded techical complexity in the attempt to offer a better user experience and hence very quickly transforming the application in an uncontrolled ball of mud.&lt;/p&gt;

&lt;p&gt;From my direct experience in building public facing web products, there are few core ideas that have to be the pillars of any web products; these are language/framework agnostic &amp;ndash; even if certain tools support these principles better than others.&lt;/p&gt;

&lt;p&gt;These reccomendations are mostly related to a scenario where a pure single page web app is not a viable solution(check the &lt;a href=&quot;#target-audience&quot;&gt;this&lt;/a&gt; section for a more in depth analysis). Some of these principles are appliable even if you are targeting that style but might be less effective.&lt;/p&gt;

&lt;h2&gt;&lt;a id=&quot;target-audience&quot;&gt;&lt;/a&gt;Understand your target audience&lt;/h2&gt;

&lt;p&gt;You want to have a very clear idea of the browsers you have/want to support. Building a product that works only on HTML5 friendly browsers while the 50% of your audience is on IE8 is not the best way to give your product the right boost. If you are replacing an exisiting product use &lt;a href=&quot;http://www.google.com/analytics/&quot;&gt;Google Analytics&lt;/a&gt; historical data to understand the current browsers segmentation, while if you are building something totally new invest some time in understanding who your customers will be. Knowing your audience can influence heavily the architecture of your application: a single page app can be a perfect fit for a mobile only app( most of the mobile browsers are HTML5 friendly) but it might be a bad choice for a product that has to be consumed by less modern browsers.&lt;/p&gt;

&lt;h2&gt;Use aggressively progressive enhancement techniques&lt;/h2&gt;

&lt;p&gt;Build every feature ground up. The more your website works without javascript, the more extensible it wil end up being.&lt;/p&gt;

&lt;p&gt;What this really means?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Your product &lt;strong&gt;has&lt;/strong&gt; to work without javascript. Of course this is heavily influenced by the &lt;a href=&quot;#target-audience&quot;&gt;previous guideline&lt;/a&gt;, but unless you are building a 100% single page app you should always ask yourself how do build a feature starting from the HTML over HTTP flow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once the HTML over HTTP feature is there, enhance components via javascript in order to improve the experience.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Go for multi layered enhancement approach.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Look at what &lt;a href=&quot;http://caniuse.com/&quot;&gt;HTML5 features&lt;/a&gt; are available on the browsers you want to support and if possible rely on them(datepicker and validation are two good examples of HTML5 features that are getting more and more support).&lt;/li&gt;
&lt;li&gt;If there&amp;rsquo;s no native support for certain browsers then smoothly degrade to a javascript version&lt;/li&gt;
&lt;li&gt;Finally if the javascript version results in an heavy experience on specific devices just leave the basic functionality without any bells and whistles.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;The advantage in this case is a consistent reduction of the code you have to take care of over time; because HTML5 features are natively built into the browsers you will have a performace boost for free. Also they are often already supported on mobile browsers, giving for free a native experience in the mobile version of the product.&lt;/p&gt;

&lt;h2&gt;Prefer html snippet over JSON&lt;/h2&gt;

&lt;p&gt;JSON is extremely powerful and easy to use, but it&amp;rsquo;s not the solution for everything. Often we need to pass data from the server side to the browser as a consequence of an AJAX request to build new parts of the interface.&lt;/p&gt;

&lt;p&gt;Unless you are thinking of consuming the exposed JSON data from an heteregenous set of clients you should just expose HTML snippet that you can then embed directly into your page.&lt;/p&gt;

&lt;p&gt;This approach gives you:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Progressive enanchement out of the box.&lt;/li&gt;
&lt;li&gt;A substantial reduction in client side computation, something that is critical for less modern browsers.&lt;/li&gt;
&lt;li&gt;A massive reduction of of your front-end code spread
If you let the server-side to build the HTML snippet you  you can use your favourite markup/markdown without the need of hand rolling your version client side or importing yet another dependency into the browser.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Use HTTP Status codes&lt;/h2&gt;

&lt;p&gt;The &lt;a href=&quot;http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol&quot;&gt;HTTP protocol&lt;/a&gt; contains everything you need to control and define the interaction between different parties in a scalable and fault tolerant way.
When you need to return a specific status to your ajax call there&amp;rsquo;s no need of reinventing the wheel sending any custom JSON object to say that an error happened or that the specific operation is not acceptable, just use the right &lt;a href=&quot;http://httpstatus.es&quot;&gt;HTTP status code&lt;/a&gt;. Embracing a HATEOAS architectural style can help you in shaping your systems and APIs, going beyond the basic CRUD with a more holistic view of your system as a good citizen in the HTTP stack.&lt;/p&gt;

&lt;h2&gt;Leverage HTTP caching&lt;/h2&gt;

&lt;p&gt;Thr HTTP protocol gives you a wide range of &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html&quot;&gt;caching options&lt;/a&gt; through header directives. Before introducing a cache at the domain model layer ask yourself if the same couldn&amp;rsquo;t be achieved at HTTP level.&lt;/p&gt;

&lt;h2&gt;Think about resource shareability (urls with resource id)&lt;/h2&gt;

&lt;p&gt;The web  is really about sharing and URLs are the way we share resources.&lt;/p&gt;

&lt;p&gt;Use URLs containing the resource id to epxose the different states of your resources to the world and use authentication and authorization layers to control resource access.&lt;/p&gt;

&lt;p&gt;Don&amp;rsquo;t be tempted to to trade off unicity of the resource URL with the pretty link bells; links that are easy to read and rember for humans are a nice to have, but not all the time this style supports the needs of your application. Even if your web application doesn&amp;rsquo;t demand the share sharing this is a valid test to verify the solidity of your system: would it be easier to expose a resource to a third party? Is a specific state of a resource uniquely identified by a URI? If the answer to these questions is no there&amp;rsquo;s a clear smell that the application is not using the right semantic to move from an internal state to another.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Flow control in Javascript</title>
   <link href="http://www.lucagrulla.com/posts/flow-control-in-javascript"/>
   <updated>2011-09-26T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/flow-control-in-javascript</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://www.markhneedham.com/&quot;&gt;Mark Needham&lt;/a&gt; recently wrote a &lt;a href=&quot;http://www.markhneedham.com/blog/2011/09/25/jquery-collecting-the-results-from-a-collection-of-asynchronous-requests/&quot;&gt;blog post&lt;/a&gt; on how his team worked around a Javascript asynchronous unwanted behaviour.&lt;/p&gt;

&lt;p&gt;They want to iterate over a collection, executes some code for each element of the collection and only when all the collection has been traversed execute a final step.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1240760.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;This didn&amp;rsquo;t work as expected. Due to the asynchronous nature of Javascript the &lt;em&gt;do something with grid&lt;/em&gt; block is invoked before the grid itself is filled and nothing interesting happens.&lt;/p&gt;

&lt;p&gt;Their solution to this was removing any possible event driven behaviours and handling control in a fullly imperative way, explicitly calling functions in the expected sequence.&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1240766.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;This works but it&amp;rsquo;s not leveraging Javascript nature; also the code itself results harder to understand then what it should be.&lt;/p&gt;

&lt;p&gt;How the same problem can be solved embracing asynchronous thinking ?&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1240807.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;The way to achieve control flow in Javascript is with events.&lt;/p&gt;

&lt;p&gt;When a block is completed it emits an event. All the interested parties will be listening to the specific event and execute their specific task, contributing to our overarching business flow. This alternative solution is probably also more idiomatic and as a consequence more coincise and easier to read.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Introducing node-tail: a NodeJS tail library</title>
   <link href="http://www.lucagrulla.com/posts/node-tail-a-nodejs-tail-library"/>
   <updated>2011-09-15T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/node-tail-a-nodejs-tail-library</id>
   <content type="html">&lt;p&gt;In the &lt;a href=&quot;http://www.lucagrulla.com/building-a-firehose-with-nodejs&quot; title=&quot;firehose&quot; target=&quot;_blank&quot;&gt;previous blog post&lt;/a&gt; I described the architecture of the firehose we built at &lt;a href=&quot;http://www.forward.co.uk/&quot; title=&quot;forward Internet Group&quot; target=&quot;_blank&quot;&gt;Forward&lt;/a&gt; with NodeJS.&lt;/p&gt;

&lt;p&gt;At the lowest level each node has to tail a log file.
&lt;a href=&quot;http://www.thattommyhall.com/&quot;&gt;Tom Hall&lt;/a&gt; and I couldn&amp;rsquo;t find any useful cross-platform (i.e. not relying on the unix &lt;em&gt;tail&lt;/em&gt; command) node module for that task so I ended up writing &lt;a href=&quot;http://www.lucagrulla.com/node-tail&quot;&gt;node-tail&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Using node-tail is very simple:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/1212271.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;node-tail is also available via npm, just install it with:
&lt;code&gt;npm install tail&lt;/code&gt;&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Building a firehose with NodeJS</title>
   <link href="http://www.lucagrulla.com/posts/building-a-firehose-with-nodejs"/>
   <updated>2011-09-12T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/building-a-firehose-with-nodejs</id>
   <content type="html">&lt;p&gt;In &lt;a href=&quot;http://www.forward.co.uk/&quot; target=&quot;_blank&quot;&gt;Forward&lt;/a&gt; we handle a huge stream of real time data and we are always looking for interesting ways to use that.&lt;/p&gt;

&lt;p&gt;We already have a&amp;nbsp;&lt;a href=&quot;http://hadoop.apache.org/&quot; title=&quot;Hadoop&quot; target=&quot;_blank&quot;&gt;Hadoop&lt;/a&gt;&amp;nbsp;cluster for high latency analysis (mostly reporting), but recently we started building a set of tools that can give us a near real-time view of what&amp;rsquo;s going on. With this goal in mind I have been recently involved in building a data firehose with&amp;nbsp;&lt;a href=&quot;http://nodejs.org/&quot;&gt;NodeJS&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The result is the following:
&lt;img src=&quot;/assets/firehose.png&quot;&gt;&lt;/p&gt;

&lt;p&gt;The lowest layer of the firehose is a thin component installed on each server that tails the log file we care about and publishes each log entry to a collector (called firehose-master) via &lt;a href=&quot;http://www.zeromq.org/community&quot;&gt;ZeroMQ&lt;/a&gt;. The master collects the log entries from all the nodes and republishes everything to the rest of our software ecosystem as a single stream via a single &lt;a href=&quot;http://www.zeromq.org/community&quot; title=&quot;ZeroMQ&quot; target=&quot;_blank&quot;&gt;ZeroMQ&lt;/a&gt; end point.&lt;/p&gt;

&lt;p&gt;With this architecture we easily preserve the horizontal scalability of our main service, in fact adding a new node to the firehose is as simple as installing the tail component on the new server and adding its IP address to the master configuration file.&lt;/p&gt;

&lt;p&gt;This stream can now be the core foundation of clients that consume the firehose for different purposes, from real-time trends visualisation to &lt;a href=&quot;http://wiki.apache.org/hadoop/HDFS&quot; title=&quot;HDFS&quot; target=&quot;_blank&quot;&gt;HDFS&lt;/a&gt; data bulk load.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Javascript testing</title>
   <link href="http://www.lucagrulla.com/posts/javascript-testing"/>
   <updated>2010-06-15T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/javascript-testing</id>
   <content type="html">&lt;p&gt;Javascript has become in the last year &lt;em&gt;the&lt;/em&gt; language for rich web applications, but still it rarely receives the level of attention it deserves.&lt;/p&gt;

&lt;p&gt;Libraries such &lt;a href=&quot;http://www.jquery.com&quot; title=&quot;jQuery&quot; target=&quot;_blank&quot;&gt;jQuery&lt;/a&gt; boost our productivity but the code we often end up writing tend to be a &lt;a href=&quot;http://en.wikipedia.org/wiki/Big_ball_of_mud&quot; title=&quot;big bal of mud&quot; target=&quot;_blank&quot;&gt;big ball of mud&lt;/a&gt;, with an entangled mix of presentation logic, busines logic and server side interaction, all incredibly hard to test and to maintain.&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s time to move away from this approach and start writing better quality Javascript.&lt;/p&gt;

&lt;p&gt;The very first step required to avoid Javascript spaghetti code is start thinking to &lt;strong&gt;Javascript as a&lt;/strong&gt;&lt;strong&gt; first class language&lt;/strong&gt;, and start dealing with it with the same mindset and approach we would use for any server side language.&lt;/p&gt;

&lt;p&gt;With this new approach in the same way we identify roles and integration points in server side code we want to start building &lt;strong&gt;abstractions&lt;/strong&gt; in our Javascript codebase.&lt;/p&gt;

&lt;p&gt;With the right abstractions in place we are defining clear boundaries between different parts of the system, and as a consequence our code is simpler, we promote reuse and the &lt;a href=&quot;http://en.wikipedia.org/wiki/Don&#39;t_repeat_yourself&quot; title=&quot;DRY principle&quot; target=&quot;_blank&quot;&gt;DRY principle&lt;/a&gt;, and we are finally enabling better testing.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s look at any standard Web 2.0 Javascript code from this new perspective: now the DOM and HTTP are two clear integration points.&lt;/p&gt;

&lt;p&gt;Our javascript code manipulates the DOM adding &amp;amp;nodes or changing existing nodes content in the same way any other language would interact with a database.Each call to a server over HTTP via Ajax is exactly the same of calling a web server from our server side code.&lt;/p&gt;

&lt;p&gt;With these very two first abstractions in mind, we can start rewriting our code, isolating these interactions behind clearly defined objects.&lt;/p&gt;

&lt;p&gt;Now the javascript code is not a ball of mud anymore, but a network of objects that collaborate. With these smaller objects in place we can now&lt;strong&gt; favour interaction based tests&lt;/strong&gt;, moving away from any dependency on the DOM and on the HTTP protocol.&lt;/p&gt;

&lt;p&gt;The identified abstractions let me actually mock and stub things out and test if the different tiers in my javascript code are exchanging the right messages. This separation of concerns keep the business logic nicely isolated from the user interface transformations, enabling also a cleaner state based testing for that specific part of the code (there are no more dependencies on the DOM).&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Italian Agile Day 2009: date announced</title>
   <link href="http://www.lucagrulla.com/posts/italian-agile-day-2009-date-announced"/>
   <updated>2009-08-02T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/italian-agile-day-2009-date-announced</id>
   <content type="html">Friday, 20th of November 2009, the &lt;a href=&quot;http://www.agileday.it/front/2009/italian-agile-day-2009/&quot; title=&quot;Italian Agile Day&quot; target=&quot;_blank&quot;&gt;6th Italian Agile Day&lt;/a&gt; will be held in Bologna.

It&#39;s a great opportunity to share experiences and practices, learn, discuss and meet other praticioners part of the Agile community...and  it&#39;s free :-)

I&#39;ll see you there !
</content>
 </entry>
 
 
 
 <entry>
   <title>What has to be ready for the beginning of a project?</title>
   <link href="http://www.lucagrulla.com/posts/what-has-to-be-ready-for-the-beginning-of-a-p"/>
   <updated>2009-07-05T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/what-has-to-be-ready-for-the-beginning-of-a-p</id>
   <content type="html">&lt;p&gt;The beginning of a project is always a hectic period where several things have to be put in place in order to be able to start the actual development from a solid position.&lt;/p&gt;

&lt;p&gt;Interestingly enough, I see that what is important to have ready for ThoughtWorkers most of the time is not what has to be ready for other people.&lt;/p&gt;

&lt;p&gt;Given that obviously every project is different and deserves specific attention, here is my list of things that has to be ready before the kick off of iteration 1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Infrastructure&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A repository, a Continuos Integration Environment with &lt;a href=&quot;http://www.studios.thoughtworks.com/cruise-continuous-integration&quot; title=&quot;Cruise&quot; target=&quot;_blank&quot;&gt;Cruise&lt;/a&gt; (or suitable alternatives) installed and working, a QA environment where we can deploy every successful build whenever we want, a basic build script (i.e. build/run tests/package). Pairing boxes, each one with exactly the same configuration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Architecture&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just identify  the core services/components, there&amp;rsquo;s no need to go into detail for each one at this time of the project. If we identify what is the main responsibility of a service is good enough for now, the details will be discovered later in the project. If we can easily identify the way services will communicate (web service? message broker?) good, if not through good OO principles we can abstract the low level mechanism and reduce the cost of change later, deferring the final decision to the point in the project where we have more understanding of the technological constraints.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Patterns&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Pairing and frequent pair rotation will help in spreading the knowledge of the approach to solve specific problems and in maintaining consistency throughout the code base, so most of the time there is no need of defining a sort of &amp;ldquo;project dictionary&amp;rdquo; of valid patterns at day 1.
If we&amp;rsquo;re introducing new approaches to solve a specific problem, it&amp;rsquo;s important to highlight pros and cons of the approach so that people know what they are doing once pairing.&lt;/p&gt;

&lt;p&gt;Most of the time these are probably enough to start Iteration 1.&lt;/p&gt;

&lt;p&gt;All the other decisions can (and sometimes should&amp;hellip;) be deferred to a later stage.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>QA productivity metrics</title>
   <link href="http://www.lucagrulla.com/posts/qa-productivity-metrics"/>
   <updated>2009-03-31T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/qa-productivity-metrics</id>
   <content type="html">&lt;p&gt;In a lot of companies the QAs productivityi s measured through the number of defects she raised: the more defects she finds, the harder she works, therefore the better she is.&lt;/p&gt;

&lt;p&gt;This approach has an interesting corollary: if you have really good QAs you don&amp;rsquo;t have good developers. If your QAs are finding a lot of defects this means that your developers are quite poor and are regularly introducing defects in the code base.&lt;/p&gt;

&lt;p&gt;This approach isn&amp;rsquo;t obviously team oriented: QA and Development are seen as two separate and independent entities that interact through a specific contract.&lt;/p&gt;

&lt;p&gt;If we truly believe in collaboration the most important productivity metrics are not related to a specific role/skills set but to the team capability of deliver quality software in time and in budget.&lt;/p&gt;

&lt;p&gt;We need to ask ourselves why the defects are finding their way into the application deployed in the live environment (incomplete acceptance criteria? not enough analysis or understanding of the domain? gap in the test suite?), and fix the issue as a team, not just using that number as the boundary between two work streams.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Local optimization doesn't necessarily mean improvement </title>
   <link href="http://www.lucagrulla.com/posts/local-optimization-doesnt-necessarily-mean-im"/>
   <updated>2009-02-14T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/local-optimization-doesnt-necessarily-mean-im</id>
   <content type="html">&lt;p&gt;Delivering software is a pretty complex activity that requires interaction between people with different skill sets.
One of the cornerstone of Agile Development is continuous improvement, and one of the tool often used to learn and improve is the &lt;a href=&quot;http://www.retrospectives.com/&quot; title=&quot;Retrospectives&quot; target=&quot;_blank&quot;&gt;retrospective&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In a context where the collaboration is not effective, people tend to look for local optimization instead of seeing the big picture, and you have things such the &amp;ldquo;QA retrospective&amp;rdquo; or the &amp;ldquo;Developer retrospective&amp;rdquo;.&lt;/p&gt;

&lt;p&gt;In this scenario a &amp;ldquo;QA retrospective&amp;rdquo; (as the Dev&amp;rsquo;s one, or a BA&amp;rsquo;s one) is probably more harmful than anything else; the specific issues that will be identified won&amp;rsquo;t address the whole activity of delivering software but will only be focused on that specific step (&amp;ldquo;we need &lt;em&gt;x&lt;/em&gt; to do y&amp;rdquo;).&lt;/p&gt;

&lt;p&gt;But what is the impact of that step in the overall process ?&lt;/p&gt;

&lt;p&gt;How that step fits into the chain of event that will take a business idea to be delivered as a software artifact (hopefully in a timely and quality fashion ) ?&lt;/p&gt;

&lt;p&gt;Don&amp;rsquo;t get me wrong: it&amp;rsquo;s definitively through specific improvements that you improve your overall process but if don&amp;rsquo;t frame your changes in the big picture, it&amp;rsquo;s more likely that your changes will impact your process in the wrong direction and actually cause an additional waste.&lt;/p&gt;

&lt;p&gt;Each attempt of optimization should therefore start from the clear analysis of what is wrong from a high level point of view and only then it&amp;rsquo;s time to shift our attention to the specific details of each step.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Acceptance Testing of Flex applications</title>
   <link href="http://www.lucagrulla.com/posts/acceptance-testing-of-flex-applications"/>
   <updated>2009-01-26T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/acceptance-testing-of-flex-applications</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Acceptance_testing&quot; title=&quot;Acceptance Testing&quot; target=&quot;_blank&quot;&gt;Acceptance Testing&lt;/a&gt; is a fundamental practice: it gives you confidence that your application behaves as expected from the end customer point of view.&lt;/p&gt;

&lt;p&gt;In the &lt;a href=&quot;http://www.adobe.com/products/flex/&quot; title=&quot;Flex&quot; target=&quot;_blank&quot;&gt;Flex&lt;/a&gt; world there are some projects that are currently emerging in the Acceptance Testing space, each one with specific advantages and weak points.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s have a look at some of these.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FlexMonkey&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://code.google.com/p/flexmonkey/&quot; title=&quot;FlexMonkey&quot; target=&quot;_blank&quot;&gt;FlexMonkey&lt;/a&gt; Open source but based on closed source API (the &lt;a href=&quot;http://www.adobe.com/devnet/flex/samples/custom_automated/&quot; title=&quot;Automation API&quot; target=&quot;_blank&quot;&gt;Automation API&lt;/a&gt; are released only with &lt;a href=&quot;http://www.adobe.com/products/flex/features/flex_builder/&quot; title=&quot;FlexBuilder&quot; target=&quot;_blank&quot;&gt;FlexBuilder&lt;/a&gt; and not with the open source Flex SDK), it&amp;rsquo;s based on the record-playback approach and as far I&amp;nbsp; have seen is not easily integrable with a Continuous Integration server.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flash-Selenium&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://code.google.com/p/flash-selenium/&quot; title=&quot;Flash-Selenium&quot; target=&quot;_blank&quot;&gt;Flash-Selenium&lt;/a&gt; is open source, and it works as an extension of SeleniumRC; the tests can be written in Java, .Net, Ruby or Phyton and the integration with a Continuous Integration server is therefore quite out of the box.
&lt;strong&gt;&lt;a href=&quot;http://sourceforge.net/projects/seleniumflexapi/&quot; title=&quot;SeleniumFlex API&quot; target=&quot;_blank&quot;&gt;
&lt;/a&gt;&lt;/strong&gt;&lt;strong&gt;SeleniumFLex API&lt;/strong&gt;
&lt;a href=&quot;http://sourceforge.net/projects/seleniumflexapi/&quot; title=&quot;SeleniumFlex&quot; target=&quot;_blank&quot;&gt;SeleniumFlex&lt;/a&gt; is another open source project.&amp;nbsp;it&amp;rsquo;s an extension of SeleniumIDE, test should be written in Selenese.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FunFX&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://funfx.rubyforge.org/&quot; title=&quot;FunFX&quot; target=&quot;_blank&quot;&gt;FunFX&lt;/a&gt; is based on the automation API (therefore you can use it only if you&amp;rsquo;re owner of FlexBuilder), the fixtures are&amp;nbsp; written in Ruby.&lt;/p&gt;

&lt;p&gt;At the moment there isn&amp;rsquo;t a de-facto solution: the community is quite dynamic and all these different tools are trying to find their space.&lt;/p&gt;

&lt;p&gt;Which one is my favourite ?&lt;/p&gt;

&lt;p&gt;It&amp;rsquo;s really hard to say, I think that the context matters a lot. I don&amp;rsquo;t like solutions that require the Automation API simply because this hooks you to a vendor just for testing; it&amp;rsquo;s also true that the pure open source solutions require some extra-hack (like exposing methods through &lt;a href=&quot;http://livedocs.adobe.com/flash/8/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&amp;amp;file=00002200.html&quot; title=&quot;ExternalInterface&quot; target=&quot;_blank&quot;&gt;ExternalInterface&lt;/a&gt;) that is less than ideal.&lt;/p&gt;

&lt;p&gt;Looking at the two pure open source tools I like Flash-Selenium for its out of the box integration with Continuous Integration server, while I prefer Selenium-Flex approach for handling the necessary ExternalInterface configuration.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Signs of poor communication</title>
   <link href="http://www.lucagrulla.com/posts/signs-of-poor-communication"/>
   <updated>2008-09-28T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/signs-of-poor-communication</id>
   <content type="html">&lt;p&gt;Walking in an office and just looking around for 10 minutes is enough to have a feeling of the level of communication in that environment.&lt;/p&gt;

&lt;p&gt;When:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;co-located people communicate mainly via IMs, mails, or comments on online collaborative tools instead of face-to-face conversation&lt;/li&gt;
&lt;li&gt;a heavyweight tool is the preferred way for driving the work flow instead of using it only for backup and tracking&lt;/li&gt;
&lt;li&gt;on the whiteboard you can read the outcomes of the retrospective of 7 months before&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;There&amp;rsquo;s &lt;em&gt;definitively&lt;/em&gt; something wrong.&lt;/p&gt;

&lt;p&gt;What about your team? How many of the above bullet points are you ticking off?&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Flex: How to achieve proper separation of responsibilities</title>
   <link href="http://www.lucagrulla.com/posts/flex-how-to-achieve-proper-separation-of-resp"/>
   <updated>2008-06-24T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/flex-how-to-achieve-proper-separation-of-resp</id>
   <content type="html">&lt;p&gt;In a &lt;a href=&quot;http://www.lucagrulla.com/posts/working-with-adobe-flex&quot; title=&quot;Working with Adobe Flex&quot; target=&quot;_blank&quot;&gt;previous post&lt;/a&gt; I was discussing on my experience with Flex and one of the highlighted pain points is the extremely poor quality of the available tutorials.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s have a look at the source code of the &lt;a href=&quot;http://learn.adobe.com/wiki/display/Flex/Part+I.+Creating+a+Simple+RIA&quot; title=&quot;Flickr Tutorial&quot; target=&quot;_blank&quot;&gt;Flick tutorial&lt;/a&gt;:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/67a8161d885a50e801e7.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;In a single page you have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The declaration of visual components (&lt;em&gt;TileList&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;the declaration of non visual component (&lt;em&gt;HTTPService&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;event handling (&lt;em&gt;photoHandler&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;data binding (&lt;em&gt;photoFeed&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;pure logic (&lt;em&gt;requestPhotos&lt;/em&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;If you decide to follow this development model you will obtain something that is extremely fragile to evolve or simply just to maintain.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s start assigning the right responsibilities to the right objects.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The first step&lt;/strong&gt; is creating our own Application object and use it as root in the mxml file:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/cd9b265e56ee17cf79f1.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;Now the HttpService component is not exposed anymore (and ideally can also be injected) and the events handling in the right place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The second step&lt;/strong&gt; is to extend the HttpService object to place the &lt;em&gt;requestPhotos&lt;/em&gt; behaviour in the service. The result is below:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/da81b4619e89bc5ba546.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;At the end of this refactoring our mxml file looks like this:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/86e3938fcde3f9c268f0.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;Here now we are declaring only visual components, and its only role is defining what we want to see  and how.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Working with Adobe Flex</title>
   <link href="http://www.lucagrulla.com/posts/working-with-adobe-flex"/>
   <updated>2008-06-21T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/working-with-adobe-flex</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/Rich_Internet_application&quot; target=&quot;_blank&quot;&gt;RIA&lt;/a&gt; is a pretty hot topic in these days; even in &lt;a href=&quot;http://www.thoughtworks.com&quot; target=&quot;_blank&quot;&gt;ThoughtWorks&lt;/a&gt; a lot of discussions are going on (if you have time  check fellow ThoughtWorkers posts &lt;a href=&quot;http://blog.jayfields.com/2008/05/argument-for-ria.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;, &lt;a href=&quot;http://memeagora.blogspot.com/2008/05/ria-platform-play.html&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://www.pgrs.net/2008/6/1/the-state-of-flex-development&quot; target=&quot;_blank&quot;&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;I&amp;rsquo;m quite involved in the conversation, mostly due to the use of &lt;a href=&quot;http://www.adobe.com/products/flex/&quot; title=&quot;Flex&quot; target=&quot;_blank&quot;&gt;Adobe Flex &lt;/a&gt;in my current project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is Flex ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Flex is the Adobe solution for RIA; based on &lt;a href=&quot;http://en.wikipedia.org/wiki/ActionScript&quot; target=&quot;_blank&quot;&gt;ActionScript&lt;/a&gt;, it promises quick development of rich UI, the ability of testing and TDD-ing, good tools for development and out of the box integration with Web Services and REST services.&lt;/p&gt;

&lt;p&gt;Everything sounds cool, but my experience with Flex highlighted few elements that worth a bit of attention&amp;hellip;let&amp;rsquo;s analyze those one by one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Testability&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;ActionScript is actually really hard to test.&lt;/p&gt;

&lt;p&gt;A Unit testing framework (&lt;a href=&quot;http://code.google.com/p/as3flexunitlib/&quot; target=&quot;_blank&quot;&gt;FlexUnit&lt;/a&gt;) is available but it cannot be used by command line because the test runner works only in your browser; this slow down your development cycle (red-green-refactor) quite a lot, reducing your effectiveness during the day.&lt;/p&gt;

&lt;p&gt;ActionScript is a half way between a static and a dynamic language (with a clear direction towards being a pure static language, my guess is that the language designers are trying to increase the language appeal to the Java and the .Net community).The main concert here is you miss the testing support of static languages(mock libraries mostly) and of a dynamic one you&amp;rsquo;re missing the complete dynamic approach(all the classes are sealed by default, and you can&amp;rsquo;t do methods override at runtime even for objects that are explicitly declared dynamic).&lt;/p&gt;

&lt;p&gt;In this scenario interaction testing is nearly impossible to do; sure, you can write your own mock library or stub everything out but this is a pretty strategic decision and a lot depends on the scope of the project.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Flex Security Model&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Another aspect that gave us more than one trouble is Flex security model.&lt;/p&gt;

&lt;p&gt;A Flex application can connect to a WebService or a REST service only if:&lt;/p&gt;

&lt;ul&gt;
    &lt;li&gt;the target service is on the same domain where the Flex application is deployed&lt;/li&gt;
    &lt;li&gt;the target service is on an external domain but in the target domain there is a &lt;em&gt;crossdomain.xml&lt;/em&gt; file that declares your domain as secure&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;What does it mean ?
That if I want to access a public feed (let&amp;rsquo;s say the BBC weather feed) BBC has to have my domain specified on its &lt;em&gt;crossdomain.xml&lt;/em&gt; file that lives on its server.&lt;/p&gt;

&lt;p&gt;This is a strong limitation: you cannot simply call BBC and ask to add your domain to their list of trusted site, and this take you down the path of over design your application (like adding a proxy web service on your domain just to be able to get the real data you need from BBC).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tutorials and suggested best practices&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A final comment is for the Adobe tutorials: it&amp;rsquo;s hard to see in 2008 something so poor.
The tutorials (have a look at the &lt;a href=&quot;http://learn.adobe.com/wiki/display/Flex/Part+I.+Creating+a+Simple+RIA&quot; target=&quot;_blank&quot;&gt;Flickr one&lt;/a&gt; to have an idea) are a collection of bad practices: the suggested development style is spaghetti-code, where you write all the code in the Script tag within your main Flex application file (mxml).&lt;/p&gt;

&lt;p&gt;And what about separation of responsibilities ?
Do we really think that this is the code you obtain doing TDD ?&lt;/p&gt;

&lt;p&gt;The heavily usage of the Script tag will take you down maintenance nightmares, transforming your application in something that is quickly out of your control and you cannot evolve.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Final thoughts&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Looking at these pain points I can&amp;rsquo;t sat that Flex is a mature technology.
Adobe promises a lot but a number of the promises are not there; TDD is simply too hard to do due to the lack of mock support(even if &lt;a href=&quot;http://www.adobe.com/devnet/flex/articles/unit_testing.html&quot; title=&quot;TDD in Flex&quot; target=&quot;_blank&quot;&gt;looks promising&lt;/a&gt;), the set of possible permissions you can give to the Flash player clashes with the new services oriented features (introducing cumbersome security model that take you to overdesign as a possible workaround), and tooling is quite poor (FlexBuilder, the IDE, crashes regularly and the Ant task is pretty basic).&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Article: Seniority, Respect, Authority and an Agile Team</title>
   <link href="http://www.lucagrulla.com/posts/article-seniority-respect-authority-and-an-ag"/>
   <updated>2008-05-25T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/article-seniority-respect-authority-and-an-ag</id>
   <content type="html">&lt;a href=&quot;http://www.infoq.com/news/2008/05/seniority-conflict-agile-team&quot; title=&quot;Seniority, Respect, Authority and an Agile Team&quot; target=&quot;_blank&quot;&gt;Here&lt;/a&gt; on &lt;a href=&quot;http://www.infoq.com&quot;&gt;InfoQ&lt;/a&gt; some interesting thoughts around Seniority and Authority in an Agile team.
</content>
 </entry>
 
 
 
 <entry>
   <title>Article: Patrick Kua on the Agile Coach role</title>
   <link href="http://www.lucagrulla.com/posts/article-patrick-kua-on-the-agile-coach-role"/>
   <updated>2008-05-25T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/article-patrick-kua-on-the-agile-coach-role</id>
   <content type="html">&lt;a href=&quot;http://www.infoq.com/articles/agile-coach-a-to-z&quot; title=&quot;Agile coach A to Z&quot; target=&quot;_blank&quot;&gt;Here&lt;/a&gt; a really good article from my friend &lt;a href=&quot;http://www.thekua.com/atwork/&quot; target=&quot;_blank&quot;&gt;Patrick Kua&lt;/a&gt; on the Agile Coach role.
</content>
 </entry>
 
 
 
 <entry>
   <title>Ivy: how to download dependencies to different folders</title>
   <link href="http://www.lucagrulla.com/posts/ivy-how-to-download-dependencies-to-different"/>
   <updated>2008-04-17T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/ivy-how-to-download-dependencies-to-different</id>
   <content type="html">&lt;p&gt;&lt;a href=&quot;http://ant.apache.org/ivy/&quot;&gt;Ivy&lt;/a&gt; is a dependency manager that lets you define in a declarative way directly in the build file the dependency of your project.&lt;/p&gt;

&lt;p&gt;In order to download dependencies in different folders (i.e. separate the runtime dependencies from the testing ones) you have to define configurations.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s say we have this project structure:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;lib

&lt;ul&gt;
&lt;li&gt;prod&lt;/li&gt;
&lt;li&gt;test&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;We need three different things to achieve our goal:&lt;/p&gt;

&lt;p&gt;The first step is defining in your ivy.xml a configuration for each folder:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/49c44d9ed4e9336ece80.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;Then we need to define the actual dependencies assigning to each one the right configuration(in this scenario both are extending the default one):&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/d53a0ff880551817f4ac.js&quot;&gt;&lt;/script&gt;


&lt;p&gt;Finally we need to define the pattern in the &lt;em&gt;ivy:retrieve&lt;/em&gt; tag&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/8f6b94d0b9e9d3995321.js&quot;&gt;&lt;/script&gt;

</content>
 </entry>
 
 
 
 <entry>
   <title>Integrate Ivy in a dotNet build</title>
   <link href="http://www.lucagrulla.com/posts/integrate-ivy-in-a-dotnet-build"/>
   <updated>2008-04-17T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/integrate-ivy-in-a-dotnet-build</id>
   <content type="html">&lt;p&gt;I&amp;rsquo;m currently involved in a .Net shop and I&amp;rsquo;m working on redesigning the build pipeline (good old CI stuff).
&lt;a href=&quot;http://ant.apache.org/ivy/&quot;&gt;Ivy&lt;/a&gt; appeared in our brainstorming sessions as a solution for having a more defined control on the projects dependencies requirement.&lt;/p&gt;

&lt;p&gt;The problem is that currently (but you never know about the future ;-) ) there isn&amp;rsquo;t a .Net native port of Ivy.&lt;/p&gt;

&lt;p&gt;This can be solved using the &lt;em&gt;exec&lt;/em&gt; tag from your NAnt script and using java as an external program.
Here is the bit to add to your NAnt build script:&lt;/p&gt;

&lt;script src=&quot;https://gist.github.com/lucagrulla/e276276fbdc79715e0b5.js&quot;&gt;&lt;/script&gt;

</content>
 </entry>
 
 
 
 <entry>
   <title>Essap 2008</title>
   <link href="http://www.lucagrulla.com/posts/essap-2008"/>
   <updated>2008-04-09T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/essap-2008</id>
   <content type="html">For the third year the European Summer School of Agile Programming(Essap) is a great opportunity to learn more about Agile Methodologies.

&lt;a href=&quot;http://essap.dicom.uninsubria.it/&quot; title=&quot;Essap&quot;&gt;Here&lt;/a&gt; the website of the school: check it out.
</content>
 </entry>
 
 
 
 <entry>
   <title>Just a bit of confusion...</title>
   <link href="http://www.lucagrulla.com/posts/just-a-bit-of-confusion"/>
   <updated>2008-03-29T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/just-a-bit-of-confusion</id>
   <content type="html">From a job offer recently received:

[...]Please note it is essential that applicants have worked in a structured development environment ideally **utilising the Agile (SCRUM, XP) methodology or any other similar methods such as Waterfall**, RAD or RUP[...]

Just awesome.
</content>
 </entry>
 
 
 
 <entry>
   <title>Express your business requirements through your code</title>
   <link href="http://www.lucagrulla.com/posts/express-your-business-requirements-through-yo"/>
   <updated>2008-03-02T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/express-your-business-requirements-through-yo</id>
   <content type="html">&lt;p&gt;Last week I was working with a colleague on the implementation of a fairly simple validation of a character: the criteria for validation was that the character had to be lower case or a digit.&lt;/p&gt;

&lt;p&gt;Looking at the Javadoc we spotted a couple of useful methods in the Character class: &lt;em&gt;isLetterOrDigit&lt;/em&gt; -this method is pretty straightforward- and is &lt;em&gt;LowerCase&lt;/em&gt; that returns false for upper case letter and everything is not a letter.&lt;/p&gt;

&lt;p&gt;The code we wrote looked like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if (!isLowerCase(aCharacter) &amp;amp;&amp;amp;!isDigit(aCharacter)) {
    //...
    //error !!
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;All the tests passed.
Fairly simple and coincise solution.&lt;/p&gt;

&lt;p&gt;But..&lt;strong&gt;are we actually expressing the business requirements ?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No.&lt;/strong&gt;
Not al all.&lt;/p&gt;

&lt;p&gt;Our code is not communicating clearly what we&amp;rsquo;re trying to  achieve: the API is not clearly expressing that punctuations are not allowed.&lt;/p&gt;

&lt;p&gt;The expected behaviour is there but the code is still not in an ideal shape: we need to be able to clearly express what we really need to validate.&lt;/p&gt;

&lt;p&gt;The refactored code looked like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;if (!isALowerCaseCharacter(aCharacter) &amp;amp;amp;&amp;amp;amp; !isDigit(aCharacter)) {
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;where &lt;em&gt;isALowerCaseCharacter&lt;/em&gt; was:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;private boolean isALowerCaseCharacter(char aCharacter) {
    return isLetter(aCharacter) &amp;amp;&amp;amp; isLowerCase(aCharacter);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is better.
We are might be  increasing the actual complexity of the condition but our code is now  expressive: if in 3 months time we pick up this code again we clearly know what business rule we&amp;rsquo;re applying without looking at &amp;lt;&lt;em&gt;any&amp;lt;&lt;/em&gt; additional resource.&lt;/p&gt;

&lt;p&gt;The code now is &lt;strong&gt;communicating our intention&lt;/strong&gt;.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>EasyMock experience</title>
   <link href="http://www.lucagrulla.com/posts/easymock-experience"/>
   <updated>2008-02-23T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/easymock-experience</id>
   <content type="html">&lt;p&gt;For the last two weeks I&amp;rsquo;ve worked with &lt;a href=&quot;http://www.easymock.org/&quot;&gt;EasyMock&lt;/a&gt; and coming from a JMock background it&amp;rsquo;s easy to make a comparison between the two libraries.&lt;/p&gt;

&lt;p&gt;I have to say that I&amp;rsquo;m less than impressed by EasyMock: the whole concept of the two different states (recording and active) for the mock library looks unreasonable.&lt;/p&gt;

&lt;p&gt;Let&amp;rsquo;s look on how we can create a mock with EasyMock:&lt;/p&gt;

&lt;p&gt;&lt;code&gt; MyInterface mock =EasyMock.mock(MyInterface.class);
//expectation
mock.myMethod();
//activation step
mock.replay();
//actual call to the mock
mock.myMethod();
//verification that the method has been called
mock.verify();
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;There&amp;rsquo;s also a more DSLish style of defining expectations, that I personally prefer (it differentiates clearly  the definition of the expectation from the actual method call).&lt;/p&gt;

&lt;p&gt;&lt;code&gt; EasyMock.expects(mock.myMethod());&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This style is the only one available when the expectation is more complex:&lt;/p&gt;

&lt;p&gt;&lt;code&gt; EasyMock.expects(mock.myMethod()).andReturn(true);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;But what if I want to define that a certain method will be called on the stub, no matter how many times ?&lt;/p&gt;

&lt;p&gt;I can either use a different way of creating the mock:
&lt;code&gt; EasyMock.createNiceMock(MyInterface.class); &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;or using the DSL way:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;EasyMock.expects(mock.myMethod()).anyTimes() &lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I think that having two ways of defining the same expectation is pretty confusing, specially when you&amp;rsquo;re using the API for the first time. What I&amp;rsquo;m looking for in a mock library is the capability of  defining the expectations in a coincise but expressive way and then inject the dependency in the object I want to test.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.jmock.org/&quot; title=&quot;JMock&quot;&gt;JMock2&lt;/a&gt; is pretty close, but I have to admit the the inner class notation with all those curly brackets around is not helping.&lt;/p&gt;

&lt;p&gt;A fellow &lt;a href=&quot;http://www.thoughtworks.com&quot;&gt;ThoughtWorker&lt;/a&gt; have just released &lt;a href=&quot;http://code.google.com/p/mockito/&quot; title=&quot;Mockito&quot; target=&quot;_blank&quot;&gt;Mockito&lt;/a&gt;: it looks like it&amp;rsquo;s taking the best from EasyMock and JMock and put in a single library. Might be worth a try.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>The last "D" in TDD means more than just "Development"</title>
   <link href="http://www.lucagrulla.com/posts/the-last-d-in-tdd-means-more-than-just-develo"/>
   <updated>2007-12-05T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/the-last-d-in-tdd-means-more-than-just-develo</id>
   <content type="html">&lt;a href=&quot;http://www.stephenchu.com/2007/12/last-d-in-tdd-means-more-than-just.html&quot; target=&quot;_blank&quot;&gt;Here&lt;/a&gt; some interesting thoughts on TDD.
</content>
 </entry>
 
 
 
 <entry>
   <title>Java enum as a strategy pattern</title>
   <link href="http://www.lucagrulla.com/posts/java-enum-as-a-strategy-pattern"/>
   <updated>2007-10-27T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/java-enum-as-a-strategy-pattern</id>
   <content type="html">&lt;p&gt;I&amp;rsquo;ve always thought that Java enums can represent a simple but powerful strategy pattern baked into Java.&lt;/p&gt;

&lt;p&gt;This idea has been reinforced by &lt;a href=&quot;http://www.cincomsmalltalk.com/userblogs/ralph/blogView?showComments=true&amp;amp;printTitle=Design_patterns_and_language_design&amp;amp;entry=3335803396&quot;&gt;this article&lt;/a&gt; by Ralph Johnson of GoF fame, where while talking about design patterns and language design he says:&lt;/p&gt;

&lt;p&gt;&lt;cite&gt; Design patterns are not made of stone.
[&amp;hellip;]
Over time, we should change our programming languages so that they build in things that used to be patterns.
&lt;/cite&gt;&lt;/p&gt;

&lt;p&gt;This evolution of modern languages will (hopefully) increase the number of people that are really able to write Object Oriented code, modelling behaviours and not only using objects as a dull namespace construct.&lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Useless comment</title>
   <link href="http://www.lucagrulla.com/posts/useless-comment"/>
   <updated>2007-04-25T00:00:00+00:00</updated>
   <id>http://www.lucagrulla.com/posts/useless-comment</id>
   <content type="html">&lt;script src=&quot;https://gist.github.com/lucagrulla/9f4d6f84a8e2643bcb0a.js&quot;&gt;&lt;/script&gt;

Can a name attribute in an Entity class represent something different than the name of the entity?
</content>
 </entry>
 
 

</feed>
