<?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 Ian Sugar on Medium]]></title>
        <description><![CDATA[Stories by Ian Sugar on Medium]]></description>
        <link>https://medium.com/@iansugar?source=rss-6966951a8953------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ejyCgXTOWtuOLTTV.jpg</url>
            <title>Stories by Ian Sugar on Medium</title>
            <link>https://medium.com/@iansugar?source=rss-6966951a8953------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:01:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iansugar/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[Automated Testing for Microservices]]></title>
            <link>https://medium.com/@iansugar/automated-testing-for-microservices-b472467b301f?source=rss-6966951a8953------2</link>
            <guid isPermaLink="false">https://medium.com/p/b472467b301f</guid>
            <dc:creator><![CDATA[Ian Sugar]]></dc:creator>
            <pubDate>Fri, 07 Feb 2020 14:40:37 GMT</pubDate>
            <atom:updated>2020-02-07T14:40:37.236Z</atom:updated>
            <content:encoded><![CDATA[<p>[Originally published on Audiogum blog 15 January 2018]</p><h3>How Audiogum’s testing strategies help us maintain a high pace of change</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*Iz921Fi6C3Hn-Kz3.png" /><figcaption>Four levels of microservice behaviour testing</figcaption></figure><h3>Overview</h3><p>At Audiogum, to achieve both high availability and rapid pace of change, we rely on repeatable, fully automated testing of our services.</p><p>Unit tests, acceptance tests, component tests, integration tests, system tests, end-to-end tests… These are just a few of the commonly used terms to describe different flavours of testing, but there is ambiguity in what these things mean and how they relate, as well as endless potential implementations.</p><p>In this post I aim to describe what we Audiogum engineers agree as reasonable definitions for the kinds of tests we think are important in the context of our microservices architecture, as described by Steve previously in the <a href="https://www.audiogum.com/blog/platform-overview"><strong>platform overview post</strong></a>. For each of these I describe the motivations and implications of these definitions and some strategies we have adopted at Audiogum that suit our context.</p><p>We have other types of testing such as performance and load testing that are important too but I will leave these out of scope and focus for now on the testing of service behaviour.</p><h3>Motivation: Tests Support Change</h3><p>We test because we need to confirm as best we can that what we create behaves as intended. Furthermore, testing helps us to prevent breaking things when we change them.</p><p>All too often though, tests can become barriers rather than enablers for change. They take time to create, to run, and to maintain. Our motivation has been to avoid some of the problems we’ve each encountered elsewhere in the past, including for example:</p><ul><li>Duplication of tests across multiple levels of testing -&gt; costs time</li><li>Inconsistency of approach causing confusion for new engineers on a project -&gt; costs time</li><li>Tests that are hard to understand therefore difficult to maintain -&gt; costs time</li><li>Tests that are hard to run due to fragile or hard to set up dependencies -&gt; costs time</li><li>Tests that are ignored, pointless or incorrectly modified (often due to above) -&gt; risk of regression and escaped bugs</li></ul><h3>Unit Tests</h3><h3>Unit Tests: Audiogum definition</h3><p>Unit tests are automated tests of small parts of a service. For example in our Clojure microservices, a function or set of functions in a namespace.</p><p>Unit tests avoid external dependencies (no I/O) by providing mocked implementations of dependencies wherever necessary.</p><p>Unit tests check the current internal implementation NOT overall system behaviour.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*Ygybfg9HcmQgu5mh.png" /><figcaption>Microservice unit tests</figcaption></figure><h3>Unit Tests: Motivation</h3><p>Whether taking the “test first” approach, writing tests afterwards or somewhere in between, unit tests should support the development of relatively detailed logic, independently of other parts of the system.</p><p>Programming languages like Clojure with its REPL allow us to interact directly with running code and data, testing as we write it. This is a large part of the productivity benefit we perceive in Clojure. Becoming comfortable with a REPL-based approach to programming can mean that unit tests no longer seem essential to the developer to feel confident that the details work as they intend as they create the code. However, unit tests create a repeatable record of such testing and so can be valuable for both the initial implementer and any future developers maintaining and extending the code later. They help prove that new changes haven’t broken previous behaviour unintentionally and they convey understanding of how the implementation is intended to work.</p><h3>Unit Tests: Implications</h3><p>Unit tests must be fast to run and easy to maintain so they are not blockers for change.</p><p>Unit tests are <em>optional</em> and <em>disposable</em> because they are useful only for internal details. We accept that refactoring breaks existing tests and they may need replacement or modification. Some services actually have very little internal logic and are mainly concerned with I/O and wiring other things together. In these cases it’s OK to have few or no unit tests at all. Other services perform some algorithmic process or complex transformation logic internally. It’s in these cases where unit testing has value as described above.</p><p>Therefore while <em>code coverage</em> can be an interesting indicator of test health, we do NOT consider it a goal in itself. 100% unit test code coverage for an entire microservice is impossible by our definition.</p><p>We certainly cannot rely on unit tests alone to check overall service behaviour — hence the other levels below!</p><h3>Unit Tests: Audiogum implementation</h3><p>Audiogum’s microservice unit tests are implemented in Clojure and run in-process with no network I/O. The tests run locally on demand and automatically as part of the CI job for the project.</p><p>Dependencies of the code under test, if any, are stubbed or mocked.</p><p>For readers interested in Clojure, here’s a Clojure-specific interlude on dependencies:</p><p>Past experience using testing frameworks like <a href="https://github.com/marick/Midje"><strong>Midje</strong></a> has caused a tendancy to redefine hard dependencies (e.g. using against-background or provided). One can achieve similar &quot;under the hood&quot; fiddling using something like with-redefs.</p><p>At Audiogum we believe that to avoid this style leads to better code structure, specifically separation of concerns. We prefer as much of our code to be pure as possible and avoid having hidden dependencies on non-deterministic or external stuff. Pure code is <em>predictable</em> and therefore <em>testable</em>!</p><p>Using clojure.test and avoiding function redefinition encourages us to make our code as pure as possible and clearly separate concerns by passing function dependencies and creating abstractions such as protocols where appropriate.</p><p>Unit testing such code then involves creating test implementations of the dependencies and passing them into the code under test. There is often nothing more to this than defining stub functions, but there are libraries such as <a href="https://github.com/bguthrie/shrubbery"><strong>Shrubbery</strong></a> we sometimes use to support more advanced mocking, in this case when using protocols specifically. Our approach to unit testing prompted the development of the <a href="https://github.com/audiogum/picomock"><strong>Picomock library</strong></a>, which provides some simple convenience tools for testing with dependencies and does not depend on protocols.</p><h3>Acceptance Tests</h3><h3>Acceptance Tests: Audiogum definition</h3><p>Acceptance tests are automated tests run against the external API of an instance of a microservice isolated from other environments.</p><p>The tests do not interact directly with the internals of the service.</p><p>Dependencies of the service are also isolated, either fixed or controlled by the tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*2WzEYy1zne21qa3c.png" /><figcaption>Microservice acceptance tests</figcaption></figure><h3>Acceptance Tests: Motivation</h3><p>Acceptance tests prove the correct external behaviour of a microservice, including its I/O boundaries, given specific known behaviours of its dependencies. This supports change and internal refactoring: we should be confident to change internal implementation as long as acceptance tests still pass — in contrast to disposable unit tests above!</p><p>Isolation of these tests and their dependencies is essential to allow developers to do their work independently, and to allow such tests to run reliably: there should be nothing outside the control of the project that can make them fail.</p><h3>Acceptance Tests: Implications</h3><p>We must ensure coverage of expected behaviour of each service is as complete as possible in its acceptance tests in order to prevent accidental breakage when adding new features or refactoring.</p><p>However, acceptance tests with fake dependencies as described are not enough alone to support continuous deployment of microservices within the larger system. The tests themselves may make incorrect or incomplete assumptions about dependencies. Hence the need for system tests as described later!</p><h3>Acceptance Tests: Audiogum implementation</h3><p>Our acceptance tests consist of Clojure code running against the API of a microservice (generally a REST API, e.g. using clj-http.client).</p><p>The service is hosted locally but not in the same process as the tests. This supports the idea that the tests don’t interact with the internals by preventing us “accidentally” mocking out internal parts.</p><p>Like unit tests, the acceptance tests can be run locally on demand and form part of the CI job.</p><p>External dependencies of the microservice are substituted for local surrogates controlled by the test. This is achieved by configuration of endpoints, e.g. using environment variables to supply URLs, NOT by changing the protocols or internal implementation.</p><p>For example:</p><ul><li>Dependency on DynamoDb: we use Amazon’s <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html"><strong>local DynamoDb</strong></a>, started and populated by the test</li><li>Dependency on another microservice or external REST API: we use <a href="https://github.com/whostolebenfrog/rest-cljer"><strong>rest driver via rest-cljer</strong></a> to create fake responses and check for expected requests</li></ul><h3>System Tests</h3><h3>System Tests: Audiogum definition</h3><p>System tests are automated tests interacting only with the external client-facing APIs of the system as a whole, not with any internal microservice APIs or databases.</p><p>They are run in a ‘like-live’ environment where all dependencies are identical versions to production.</p><p>They are run whenever a change is being prepared for production, prior to deployment to production.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*JlFpG1hAxRsg4NCA.png" /><figcaption>Microservice system tests</figcaption></figure><h3>System Tests: Motivation</h3><p>System tests prove the correct behaviour of the entire system from the client user’s point of view.</p><p>They support continuous delivery by determining that a new version of a microservice will behave correctly in the context of the currently live clients and dependencies. Since they use real dependencies they can catch certain kinds of problems that acceptance tests might not.</p><p>They also support re-engineering within the microservices system, in the same way as each service’s acceptance tests support internal refactoring: for example we can change how the microservices interact with each other as long as we don’t break the behaviour of the external API.</p><h3>System Tests: Implications</h3><p>We should ensure all important user-facing features are represented and all dependencies are exercised by system tests. However we do not need to cover all detailed behaviours in system tests — to do so would cause too much duplication of acceptance tests and therefore increased barrier to change.</p><p>Since system tests run in a ‘like-live’ environment rather than actual production, even with perfect versioning and environment isolation they cannot prove that the production system is still working. That’s where healthchecks come in, as described later!</p><h3>System Tests: Audiogum implementation</h3><p>In our definition we stated <em>“dependencies are identical versions to production”</em> and <em>“run whenever a change is being prepared … prior to deployment to production”</em>. The intention of course is to prevent other changes from affecting the test and giving us the wrong result. Strictly speaking this means we need complete isolation of the environment in which we are testing, and to change only one thing (microservice for example) at a time.</p><p>This presents a challenge: How can we provide this kind of isolation without blocking each other’s independent work? We choose a microservices architecture specifically because it supports fast independent change!</p><p>At Audiogum we have considered various potential solutions, including:</p><ul><li>The ‘delivery pipeline’ approach: Assuming a shared environment with all versions as per production, we automate a process such that we update only one microservice then run the system tests. Deploy to production if it succeeds. While we do all of this, block any other changes to the testing environment.</li><li>The ‘disposable environments’ approach: Create isolated environments on demand, potentially simultaneously, with all other versions as per production, in which to run the system tests for any change. Deploy that one change to production if it succeeds.</li></ul><p>The pipeline approach is a well understood and common solution to this kind of problem, however it has the potential to cause a bottleneck. We can imagine reducing the run time as much as possible to mitigate this, but there will still be blockages, particularly when tests fail and we want to fix forward.</p><p>The disposable environments approach solves this by allowing anyone to run system tests with their own change independently. We trade this at the cost of potential incorrectness: there’s nothing to prevent another change happening such that the production dependency versions are not the same as when we created the test environment. This may be a risk worth taking for the sake of independence and speed, but we must also consider the cost of automating the creation of the environment: not trivial in the case of a distributed system composed of many microservices, data stores etc.</p><p>At the time of writing, we have neither a strict pipeline nor disposable environments, but rather a compromise that involves trust and collaboration in favour of complexity and strictness.</p><p>We use a single ‘staging’ environment (involving among other pieces a <a href="https://kubernetes.io/"><strong>Kubernetes</strong></a> cluster hosted in <a href="https://aws.amazon.com/"><strong>AWS</strong></a>), identical to production but isolated from it. Engineers can deploy updates to any service at any time. The system tests, implemented again in Clojure, can be run against the staging environment on demand but also run on a regular schedule. The general rule is that each developer is resposible for checking that their change, having passed acceptance tests, also does not break the system tests after deploying to staging, before promoting the change to production.</p><p>While we are a small team collaborating continuously, this works well for us. We anticipate that as we expand the team, or increase the size and complexity of the overall system, we will take the next steps in order to maintain the pace of independent change at larger scale. A disposable environments approach is feasible for us since our infrastructure setup is already fully automated using <a href="https://www.terraform.io/"><strong>Terraform</strong></a>.</p><h3>Healthcheck Tests</h3><h3>Healthcheck Tests: Audiogum definition</h3><p>Healthcheck tests are automated tests interacting with the production system exactly as would a real client. They are run on a frequent scheduled basis, irrespective of changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/0*raxRx7sjvxxhWCfb.png" /><figcaption>Microservice healthcheck tests</figcaption></figure><h3>Healthcheck Tests: Motivation</h3><p>Healthchecks alert us when, despite the testing performed before deployment to production, some change breaks an important function of the system. This allows us to roll back or fix such changes quickly without relying on customers reporting a problem.</p><p>They can also alert us of breaks in functional availability that might not be picked up by system metric monitoring or logging, for example due to infrastructure changes, or 3rd party dependencies changing.</p><h3>Healthcheck Tests: Implications</h3><p>Since they run in production, it may not always be possible or appropriate to test every detailed feature, although as per system tests they should aim to exercise every dependency.</p><p>Since we want fast feedback, sanity tests should be as quick to run as possible.</p><h3>Healthcheck Tests: Audiogum implementation</h3><p>Audiogum’s healthcheck tests work essentially the same as the system tests, except they run against the production environment rather than staging. In fact we run identical test code, but we flag which tests are appropriate for production.</p><p>Just like system tests, we run the healthchecks on demand but also on a regular schedule and we have automated alerting when something fails. More about how this fits into our availability monitoring and alerting strategy can be found in Deon’s post: <a href="https://www.audiogum.com/blog/audiogum-service-status"><strong>Audiogum Service Status</strong></a>.</p><h3>Conclusion</h3><p><em>“Everything should be as simple as it can be, but not simpler”</em></p><p>It may seem that implementing an automated testing strategy with multiple levels must be arduous, but actually with pragmatism at each level, techniques like these can enable teams to work on large and necessarily complex systems with greater speed and safety.</p><p>The most important thing is that when problems do occur, we can find and fix them as quickly as possible. We do this with the help of trust and tools that facilitate changes, not block them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b472467b301f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MixRadio: Going solo with personalised playlisting]]></title>
            <link>https://medium.com/@iansugar/mixradio-going-solo-with-personalised-playlisting-52b06aa54c4c?source=rss-6966951a8953------2</link>
            <guid isPermaLink="false">https://medium.com/p/52b06aa54c4c</guid>
            <category><![CDATA[music-ser]]></category>
            <category><![CDATA[recommendations]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Ian Sugar]]></dc:creator>
            <pubDate>Mon, 10 Nov 2014 00:00:00 GMT</pubDate>
            <atom:updated>2016-02-18T12:02:55.877Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Originally published at </em><a href="http://dev.mixrad.io/blog/2014/11/10/Going-solo-with-personalised-playlisting/"><em>dev.mixrad.io</em></a><em> on November 10, 2014.</em></p><p>By <a href="https://twitter.com/iansugar">Ian Sugar</a></p><p>The recommendations and personalised playlisting engine is one of the key assets in the MixRadio back-end architecture.</p><p>In this post I’ll give a flavour of our technical choices, and a glimpse into the journey we have taken, from relying on third party partners for these features to <em>owning our own destiny</em> in this area, striving to live up to our strap line: “<em>your own personal radio station</em>”.</p><h3>Context</h3><p>Since our <a href="http://dev.mixrad.io/blog/2014/08/05/MixRadio-History/">early music store days</a>, our service has included some form of recommendations, something in the style of “if you like this you might also like that”. The smarts for this were provided by a 3rd party service, up until 2012 when we took into action some of our own experimental data science work that had started in 2010 to replace this dependency.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/0*stdu8amoeqJNUbbN.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/308/0*LDo6v0KuHHhEc2jw.png" /></figure><p>Meanwhile our product offering had evolved from the traditional download store, adding the streaming radio concepts that eventually became core to the MixRadio brand. Alongside the editorially created “mixes”, our first generated artist-based radio, dubbed “Create a mix” appeared in 2011. This was our first integration with our main personalisation partner.</p><p>During this time we worked on adding experimental playlist generation features to our own recommendations engine, but the game changed again in 2013 when we introduced new personalisation features to our user experience; in particular Play Me: a dynamic and personalised radio feature that learns what the user likes. The implementation of this feature deepened our integration with our partner, making use of their dynamic playlist and taste profiling capabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/307/0*NJ2M5vsWV15JrzgY.png" /></figure><p>As we continued to build our own data and analytics capabilities, we as an organisation considered our strategy with regard to 3rd party dependencies, and exactly what it is we consider our core business. Whilst we enjoyed a great relationship with our partner and admire their capabilities, we also have our own user experience aspirations, our own target audiences and our own unique challenges in each of our markets. We really must <em>control the whole end-to-end system to be able to differentiate and adapt fast</em>, especially when it comes to consumer data and the personalisation aspects which have become fundamental to our proposition.</p><p>This meant accelerating the initiative to build our own system to ultimately replace the dependency; fulfilling the existing dynamic, personalised playlist requirement, and whatever innovations came next in this area.</p><p>The news of the acquisition of our partner in February 2014 crystallised the strategic intent and we set ourselves a final target for making the switch to our own maturing capability.</p><p>The big question was this:</p><p><em>How can we achieve this major change without damaging the consumer experience?</em></p><h3>Foundations</h3><p>Don’t worry we will lay out some specific tech later, but first let me highlight some of the architecture choices that helped us in this challenging mission.</p><p>Some <em>general architecture principles</em> and engineering practices gave us a starting point that enabled flexibility:</p><ul><li><strong>Indirection</strong>: We avoid wherever possible direct integration from client to 3rd party. We have an API that is of our own design protecting the client from changes we make behind the scenes. This was vital in this case: we cannot force changes to the millions of installed clients out there.</li><li><strong>Microservices architecture</strong>: Separation of concerns means we can change only small parts of the platform. This enables continuous dev, build, test and deployment of required changes without impact to other teams.</li></ul><p>Of course we were not starting from scratch or in isolation. Aside from the history of research and experimentation on recommendations and playlist generation, there were other changes in progress and other existing assets on which we would build:</p><ul><li><strong>Taste profiling</strong>: We had already created a system to collect data about a user’s musical taste. This was necessary for delivering notifications about favourite artists, but we also used it for the <em>Play Me</em> feature to generate “seeds” for playlists, even when using 3rd party APIs to generate the playlists themselves.</li><li><strong>User History</strong>: We already had our own system for collecting user event data embedded in our clients and delivering high volumes to our back-end from millions of users worldwide; for example plays, skips, likes, dislikes.</li><li><strong>Publish-subscribe architecture</strong>: We introduced a pub-sub model to our platform architecture to complement the REST-based direct interactions, based on <a href="http://kafka.apache.org/">Apache Kafka</a>. This allowed multiple independent microservices to consume high volumes of data such as User History events. Taste is an example consumer of this data, and so would be our playlisting engine as described below. More on publish-subscribe in the <a href="http://dev.mixrad.io/blog/2014/08/22/MixRadio-Architecture-Overview/">MixRadio back-end architecture</a> post.</li><li><strong>Amazon Web Services</strong>: At this time we were also in the midst of <a href="http://dev.mixrad.io/blog/2014/09/19/Migrating-MixRadio-Infrastructure-To-AWS/">migrating our back-end to AWS</a>. This put us in a position to deploy new consumer-facing services cost effectively on EC2, and also to take advantage of other AWS services for the “big data” analytics tasks we would need.</li><li><strong>Catalogue</strong>: It almost goes without saying: without our catalogue of global music and related metadata collected and curated over more than a decade, we would have nothing.</li></ul><h3>MixRadio’s recommendations and personalised playlisting engine</h3><p>For brevity, let’s use our internal pet name: Rex.</p><p>Rex is a collection of back-end components, working with other services, generating dynamic and personalised playlists for our artist-seeded and Play Me radio use cases. The architecture has two main distinct parts:</p><ul><li><strong>Analytics (offline)</strong>: An infeasible amount of calculation and data access would be needed to derive personalised recommendations based on raw data at runtime, therefore the bulk of the data crunching is done offline, mostly in scheduled map/reduce processes. An army of such processes create data informing recommendations (what is similar to what) and other pre-processed metadata, such as what are the currently good tracks to pick for each artist. The final results of such processes are published to online storage for the Rex microservice to efficiently access on demand.</li><li><strong>API and playlist algorithms (online)</strong>: The Rex microservice itself is responsible for generating the dynamic sequences of tracks we refer to as play sessions. Data about the user’s musical taste, including artists and songs the user likes and dislikes, is taken from the Taste service. This is used in conjunction with above mentioned recommendations data and metadata as input to our playlist algorithms, to select appropriate sequences of tracks on demand. This service also subscribes to the User History event stream to respond appropriately to signals, for example to slightly change the make-up of the session if the user dislikes a song.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/455/1*pEySTsMMsBVOxvqvd6MLlQ.png" /></figure><p>Let’s take a look at some of the technology choices we are currently using in Rex:</p><ul><li><a href="http://clojure.org/">Clojure</a>: This is programming language of choice for most of our microservices. We use it in Rex in both online and offline worlds. Clojure’s functional approach comes into its own with algorithmic stuff — it’s all about the nuts of processing data efficiently, no real need for object orientation or mutable state here.</li><li><a href="http://aws.amazon.com/dynamodb/">DynamoDB</a>: Amazon’s highly available low latency data store is a good fit for Rex’s online data. We have also used <a href="http://aws.amazon.com/elasticache/">ElastiCache</a> in both <a href="http://www.memcached.org/">Memcached</a> and <a href="http://redis.io/">Redis</a> forms for various more transient data functions.</li><li><a href="http://kafka.apache.org/">Apache Kafka</a>: As mentioned earlier this is the heart of our publish-subscribe architecture. Rex includes a <em>Kafka consumer</em> to “listen” and react to user feedback events.</li><li><a href="http://cascalog.org/">Cascalog</a>: Most of our <em>map/reduce</em> programming is done in Casalog, a Clojure library providing a high level of abstraction over the <a href="http://hadoop.apache.org/">Hadoop framework</a>. We do also make use of <a href="https://hive.apache.org/">HIVE</a> for some of the data tasks that “feel more SQLish” and even some <a href="https://www.python.org/">Python</a> via the <a href="http://hadoop.apache.org/docs/r1.2.1/streaming.html">Hadoop streaming API</a>. Engineers tend to pick what feels best for them when imagining a solution to a data processing problem.</li><li><a href="http://aws.amazon.com/elasticmapreduce/">Amazon Elastic Map Reduce</a>: We run all of our map/reduce tasks in Amazon’s EMR service, enabling us to start up Hadoop clusters on-demand, in parallel as we wish, and terminate them when done. We do this on a scheduled basis for all production data processing tasks, plus ad-hoc for development, testing and experimentation. This gives us huge flexibility without the burden of maintaining one or more continuously running clusters. This does mean we need other places to store our big data…</li><li><a href="http://aws.amazon.com/s3/">Amazon S3</a>: In a traditional Hadoop setup for big data analytics, the master storage for input and output is the Hadoop distributed file system (HDFS). However, with EMR, the HDFS is only present as long as the job flow, it being part of the temporary cluster. Amazon’s S3 provides the permanent bulk storage we need for our processing inputs and outputs, neatly integrated with EMR and other data services.</li><li><a href="http://aws.amazon.com/redshift/">Amazon Redshift</a>: Amazon’s “data warehouse as a service” is not a core part of the Rex ecosystem, but is used at MixRadio increasingly for consumer analytics and KPI reporting, crucial to the Rex journey as described later. As engineers working on Rex we also use this for ad-hoc querying of data, for example to interrogate the results of our experimental algorithms. This has proved faster and more accessible than using HIVE on EMR to perform similar queries.</li></ul><p>For the sake of sanity as well as for obvious reasons, I can’t give too much detail on the actual processes that make our recommendations. What I can say is we have a hybrid strategy, combining several different algorithms and data sources. Sources include mass consumption data, music catalogue metadata, acquired metadata from external sources, plus in-house metadata created by our music experts. We continuously experiment with new sources and algorithms, adding to the hybrid when each contributes an improvement of some kind.</p><p>So that’s what our engine is made of! Now back to the problem of how to get it right before switching millions of current users to the new system.</p><h3>Performance and stability</h3><p>Having data and algorithms to produce a playlist is not enough. Equally important to maintaining our consumer experience seamlessly through the switch and ongoing is delivering a <em>highly-available, stable, low-latency service at scale</em>. How did we know we would have no technical surprises when we came to switch?</p><p>Performance testing in a pre-live environment can teach a lot, but there’s nothing quite the same as real live load in the context of the production environment. We resorted to a trick we have used before in the evolution of our back end when switching dependencies or data stores, something we call <em>request cloning</em>. In this case we made use of the indirection mentioned earlier, to pass requests silently to Rex at the same time as to the existing provider. The Rex response was ignored (even on failure) ensuring that the consumer experience was not affected. We made the percentage of requests to clone dynamically configurable so we could ramp up slowly or switch it off instantly in case of nasty noises.</p><p>Yes, as we ramped up, we did find some bugs missing features, but no animals were harmed in the testing and we were able to make the required changes and get ourselves comfortable with scaling to 100% load well in advance of affecting any real users.</p><p>Haven’t I mentioned <em>monitoring</em> yet? Oops. Yes we monitored everything we could think of and continue to do so. Graph addiction!</p><h3>Ensuring consumer experience</h3><p><em>“So, after all this is it any good?”</em></p><p>Good question. More importantly for us at the time, <em>will it be good enough</em> to avoid putting our users off by the time we switch?</p><p>The quality of a music listening experience is such a subjective thing, with local variation across the world, as well as of course individual variation between people’s tastes and preferences.</p><p>We knew that we could not create an identical experience to the existing, but anyway we didn’t necessarily want that. Based on years of feedback and based on our strategy as a business, we had opinions on how we wanted the experience to feel, how we would address specific issues in key markets, and ideas on how to address those ambitions technically.</p><p>How could we possibly know if it would work? We have no perfect answer, but we did spend a lot of effort trying to mitigate this uncertainty by getting feedback from real people as early as possible.</p><p>We decided the best way to have people try it is to <em>put it live</em>: use the live client app and real users with their own real taste profiles; but of course with careful control over <em>which</em> users and without any impact to the user population at large.</p><p>Again we were able to take advantage of the indirection in our architecture — effectively supporting multiple implementations at the same time. Some users get Rex, while others continue to get playlists generated by our partner as before.</p><p>There were three distinct phases in this testing:</p><ol><li><strong>Team user whitelisting</strong>: As soon as we had the very first rudimentary implementation working, we integrated it into the live API, but only used it for a configured whitelist of users. A few individuals involved in developing Rex were added to the whitelist. As we progressed into later phases, more internal interested users were added to this list and we used it to test new configurations and changes prior to letting anyone else suffer enjoy them.</li><li><strong>Internal trials</strong>: Once we were ready with a more mature solution, we opened up to a larger number of internal (MixRadio) volunteers recruited from across the world. Again a whitelist approach, but separate so that we could still experiment with features as a team without disturbing the trial — now two alternative Rex configurations live! A process involving surveys attempted to gauge the trialists’ subjective opinions on the experience, both before and after being switched to Rex. At the same time, ad-hoc feedback was gathered and discussed using an online forum. We learned a few bugs and some great ideas from here.</li><li><strong>A/B testing</strong>: Having analysed the feedback from the trials and implemented changes to address the key issues arising (plus the performance proving as described above) we were confident enough to <em>experiment with real people</em>! Rather than adding millions of users to a list, we chose a very simple algorithmic approach to deciding whether a user is in or out, based on the user’s randomly generated ID. This allowed us to choose a random cross-section of the user population, including users yet to be created, across all territories. We put an arbitrary 20% of real users on the new solution, leaving 80% as they were. And then we obsessed ourselves with yet more graphs!</li></ol><h3>A/B testing and consumption metrics</h3><p><em>“How did you know if the real users liked it?”</em></p><p>That’s the big question. There’s no substitute for direct verbal feedback, but that’s something we couldn’t get when it came to the randomly selected real users.</p><p>Of course, the point of A/B testing is to prove a hypothesis in terms of measurable things, key performance indicators in other words. What are the measurable things that could be proxies for user satisfaction?</p><p>Among many others, here are some of the metrics we observed and compared between the A and B groups, across each territory and globally:</p><ul><li>Skip ratios (how many songs skipped out of those consumed)</li><li>Like and dislike ratios</li><li>Numbers of tracks per session</li><li>Consumption (number of tracks overall)</li><li>Listening hours</li><li>Repeat visits (aka retention) for both new and pre-existing users in various timeframes</li></ul><p>The really important KPIs for us as a business are <em>listening hours</em> and <em>retention</em>. We know from experience not to draw hasty conclusions from indirect signals of user satisfaction, however, analysing all of these details were important for us, not least to find any signs of degradation in behaviour as quickly as possible.</p><h3>Real-time consumption monitoring</h3><p>To that point, while long-term reports were necessary to study overall success factors, we were not happy to wait for a build up of data and batch reporting. We wanted to observe what users do in real-time as soon as we make a change. What if consumption drops off a cliff or users skip 90% of the tracks? We’d better revert the change pronto and think again!</p><p>This is the same thinking as our service health monitoring, just counting different things. To create the real-time metrics we implemented a separate <em>Kafka consumer</em> to identify and count the relevant events from the User History message stream, broken down by territory and user (A/B) group. To visualise this data we made dashboards using <a href="https://github.com/graphite-project">Graphite</a>, the same open source tool we use for platform metric graphing.</p><h3>Taking flight</h3><p><em>“So how did our new engine do?”</em></p><p>Over the period of the A/B testing, as we analysed, dissected and watched the detail, we as a team along with our consumer analytics people were happy to conclude that the new engine is increasing engagement with the service and improving retention both for new and existing users. The evidence was certainly clear enough to make us confident to switch the remaining users and move forward with our own solution!</p><h3>Future</h3><p><em>“What’s next?”</em></p><p>While we are happy to have achieved “the switch”, this is only the beginning. We are far from done developing Rex, just as MixRadio is far from done with bringing new and improved personalised listening experiences to our users.</p><p>We are now applying the techniques we have learned to continuously improve, comparing current with new experiences!</p><p>I can’t give product plans away, nor could I truly predict what the future holds, but I am sure it will include some of these ingredients that will make it a fun ride:</p><ul><li>Big (bigger, different) data</li><li>Clojure (we love it)</li><li>Maths (some of us love it)</li><li>Interesting scale and performance challenges (prove things with live load!)</li><li>Experimentation (some will succeed, some will fail, we will learn)</li><li>Multi-variate testing (the users will decide!)</li><li>Real-time monitoring of user behaviour (service health does not imply users happy)</li></ul><p>Stay tuned!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/90/0*bTFsJgH-mq_X4QhB.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52b06aa54c4c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>