<?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 Marcin Tustin on Medium]]></title>
        <description><![CDATA[Stories by Marcin Tustin on Medium]]></description>
        <link>https://medium.com/@albamus?source=rss-7356c6cedd59------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*a02UuKzSyF6Gas-A.jpg</url>
            <title>Stories by Marcin Tustin on Medium</title>
            <link>https://medium.com/@albamus?source=rss-7356c6cedd59------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 02:46:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@albamus/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[Fun with text generation pt. 1: markov models in awk]]></title>
            <link>https://medium.com/build-and-learn/fun-with-text-generation-pt-1-markov-models-in-awk-5e1b55fe560c?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e1b55fe560c</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[text]]></category>
            <category><![CDATA[literature]]></category>
            <category><![CDATA[markov-chains]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Mon, 11 Nov 2019 02:48:59 GMT</pubDate>
            <atom:updated>2019-11-11T02:48:59.000Z</atom:updated>
            <content:encoded><![CDATA[<p>Inspired by <a href="https://0x0f0f0f.github.io/posts/2019/11/really-fast-markov-chains-in-~20-lines-of-sh-grep-cut-and-awk/">Really fast Markov chains in ~20 lines of sh, grep, cut and awk</a> this series is intended to explore text generation, first with markov models, then with generative adversarial networks.</p><p>The very specific inspiration for this installment was the realization that I could write an even shorter implementation in pure awk.</p><h3>What are markov models?</h3><p><a href="https://en.wikipedia.org/wiki/Markov_chain">Wikipedia has the details</a>, but in this particular example, these are the important elements:</p><ol><li>A markov process is one where the probability of transitioning from one state (word) to another (the next word) is dependent only on the current state; and</li><li>we “learn” the probability distribution of transitioning from one word to another by observing the transitions in the underlying text we’re simulating.</li></ol><h3>A quick implementation</h3><pre>BEGIN{<br>    if(!RS) { RS=&quot;[^[:alnum:]]+&quot;; };<br>    if(!outlen) { outlen=100 };<br>    srand(systime())<br>    prevword = &quot;&quot;<br>}</pre><pre># form transition matrix<br>{<br>    nextwords[prevword]=nextwords[prevword]&quot; &quot;$0;<br>    prevword = $0;<br>    prevrt = RT # try to pick good initial words<br>}</pre><pre># choose an initial word<br>(rand() &lt; 0.1) &amp;&amp; !firstword &amp;&amp; prevrt ~ /[!?.]|^/ { firstword=$0 }</pre><pre>END {<br>    ORS=&quot; &quot;; # put spaces between words<br>    word = firstword<br>    for(i=outlen; i &gt;= 0; --i) {<br>        print word;<br>        split(nextwords[word], potential_successors, &quot; &quot;);<br>        word = potential_successors[int(rand() * length(potential_successors))+1]<br>    }<br>    ORS=&quot;\n&quot; # have a final newline<br>    print word<br>}</pre><p>The most salient thing about this model is that the assumed probability distribution is flat, and there is no attempt to model hidden states — we simply build the markov chain based on what we observe in the input text.</p><h4>How well does it work?</h4><pre>$ gawk -f hmm.awk -v outlen=12 -v RS=$&#39;[[:space:]&quot;%=|-]+&#39; goedel.u8</pre><pre>The FORTUNE PROGRAM If you should have been possible. This Fortune Cookie Directed by</pre><pre>$ gawk -f hmm.awk -v outlen=27 -v RS=$&#39;[[:space:]&quot;%=|-]+&#39; goedel.u8</pre><pre>Chambers and before you contribute 30 fortunes or .cshrc. file. Do not looking at selected theaters and display work. This still begs the curvature of the fortune is just</pre><pre>$ gawk -f hmm.awk -v outlen=27 -v RS=$&#39;[[:space:]&quot;%=|-]+&#39; goedel.u8</pre><pre>it now before the curvature of the pigeonhole principle. (3) I read today&#39;s fortune. In which you by the Inanities. There is soon to misconstrue all ) [to which</pre><p><a href="https://github.com/miguelmota/ASK-fortune/blob/master/data/fortunes/off/goedel">Goedel fortune here</a></p><p>Now, on Wuthering Heights:</p><pre>$  gawk -f hmm.awk -v RS=&quot;&quot; ~/wuthering.txt</pre><pre>The harm had never looked out of fever and poor thing as to answer Shall you have not comprehend it were smooth away as one night as I were invisible it was digging Linton slowly drew her he demanded who had left him out of this roof Then he replied because he Put your gruel cold blue in law on endeavouring to pass such marks of Gimmerden Sough And what they be dark skinned gipsy in the kitchen Set two feeble as your wife s affair except a Project Gutenberg tm work or is scarcely conscious of course of it will you</pre><pre>$  gawk -f hmm.awk -v RS=&quot;&quot; -v outlen=20 ~/wuthering.txt</pre><pre>with a concourse thickening outside It was mad or to thrust forward on an evil disposition to remind myself directly No but</pre><pre>$  gawk -f hmm.awk -v RS=&quot;&quot; -v outlen=26 ~/wuthering.txt</pre><pre>The poor For additional terms than my hands in Christendom and then he descended to knock him again Thear agean em properly but to discourse as soft with</pre><p>So…it’s OK.</p><h3>Where next?</h3><p>The most obvious next step is to use a <a href="https://en.wikipedia.org/wiki/Hidden_Markov_model#Learning">hidden markov model</a> (in short the assumption is that there are also hidden markov states; which in this case would correspond to the grammar).</p><p>The other part that we haven’t in any way automated or measured is how good the generation is. For that, we will need to develop a discriminator model.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e1b55fe560c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/build-and-learn/fun-with-text-generation-pt-1-markov-models-in-awk-5e1b55fe560c">Fun with text generation pt. 1: markov models in awk</a> was originally published in <a href="https://medium.com/build-and-learn">Build and Learn</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[15 Easy Questions for Easy Change Management]]></title>
            <link>https://medium.com/build-and-learn/15-easy-questions-for-easy-change-management-b0d902f5fe9e?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/b0d902f5fe9e</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[operations]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[change-management]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Sun, 22 Sep 2019 16:18:05 GMT</pubDate>
            <atom:updated>2019-09-22T16:18:05.558Z</atom:updated>
            <content:encoded><![CDATA[<h4>If your systems keep breaking when changes are made, answer these questions</h4><p>These 15 questions should be very easy for engineers to answer ahead of making a change; and if engineers balk at answering these questions you have a problem (or you’re cool with breakage). <strong>Work around those problems, and find out what they are with this questionnaire. This article is about a structured approach to change management in your technology.</strong></p><p>You’re probably looking at this article because your systems keep breaking after changes are made. While this isn’t a magic bullet, <strong>it is a tool to start thinking about how you ought to work.</strong></p><p>Skip downwards if you just want the questions to incorporate into your change management process for software development, operations, or infrastructure.</p><h3>Why these questions matter</h3><p>In short, if your engineering team can’t easily answer these questions:</p><ol><li>they haven’t thought about the change; or</li><li>your deployment and rollback process is too hard; or</li><li>your testing or monitoring tooling is too hard; or</li><li>Your systems are so entangled that understanding the impact of a change is hard.</li></ol><p>The point of this questionnaire is both to help you <strong>work around your problems now</strong> and <strong>identify what those problems are.</strong></p><p>In general, if your engineers can’t answer <strong>any</strong> or <strong>most</strong> of these questions, then you either have a culture that promotes making changes regardless of the consequences (case 1, not thinking, is rewarded), or your systems are too entangled to really predict what will happen.</p><h4>DevOps is about agility</h4><p>Incidentally, it’s OK to have a culture where things keep breaking; if you’re completely happy with how things are going, and everyone on your team is happy, then you do you. These questions are here to help you change how you work if you know you need a change, but don’t know how. In a truly self-organizing team, your engineering function will figure out how to make these questions easy to answer; in most places if engineers are required to answer these questions, management will start to hear about why they aren’t easy to answer, and these are your pointers as to what you might want to fix.</p><h4>The costs of being careful</h4><p>Let’s be clear that some changes are harder to make than others — getting a totally nailed down answer to all of these questions either means your environment makes it easy, or it means you spent the time to get all of these answers.</p><p>That’s why <strong>the questions about potential impact are so important</strong>: you probably want to take a risk-based approach to enforcing these questions as part of your change management process. If you know that the potential impact of a change is small, then maybe you don’t need to answer all the questions. Or, if you know how to back out a change and know how to detect a problem maybe that’s all you need, and you don’t need extensive testing.</p><h3>The 15 Easy Questions for Safe, Structured Change Management</h3><ol><li>What is this change?</li><li>Why are you making this change?</li><li>What is the expected outcome of this change?</li><li>Who is going to deploy this change?</li><li>When are you going to deploy this change?</li><li>How have you tested this change? (And what are the results of your tests)</li><li>What questions are left unanswered/what risks are left in this change after your testing?</li><li>Please describe the procedure to deploy this change (in such detail that another engineer could pick up this task)</li><li>Please describe the procedure to roll back this change (in such detail that another engineer could pick up this task)</li><li>What bad things could happen as a result of this change (and why couldn’t other bad things happen)?</li><li>Who in our organization will be affected by this change? Should anyone sign off on this change?</li><li>How will you know if this change has worked or not — how will you monitor this change?</li><li>How will you know if this change has worked or not — how will you test this change?</li><li>What criteria will cause you to roll back this change? Please describe specific observable criteria.</li><li>What criteria will cause you to consider this change successful and no longer in need of active monitoring (such that everyone could go home, have a few drinks, and go to bed)</li></ol><p>9. What bad things could happen as a result of this change (and why couldn’t other bad things happen)?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b0d902f5fe9e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/build-and-learn/15-easy-questions-for-easy-change-management-b0d902f5fe9e">15 Easy Questions for Easy Change Management</a> was originally published in <a href="https://medium.com/build-and-learn">Build and Learn</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spark: Aggregating your data the fast way]]></title>
            <link>https://medium.com/build-and-learn/spark-aggregating-your-data-the-fast-way-e37b53314fad?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/e37b53314fad</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[high-performance]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[spark]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Sat, 17 Aug 2019 21:43:33 GMT</pubDate>
            <atom:updated>2019-08-17T21:43:33.135Z</atom:updated>
            <content:encoded><![CDATA[<p>This article is about when you want to aggregate some data by a key within the data, like a sql group by + aggregate function, but you want the whole row of data. It’s easy to do it the right way, but Spark provides lots of wrong ways. I’m going to go over the problem, and the right solution, then cover some ways that didn’t work out and cover why.</p><p>This article assumes that you understand <a href="https://spark.apache.org/docs/2.4.0/rdd-programming-guide.html#parallelized-collections">how Spark lays out data in datasets and partitions</a>, and that partition skewing is bad. I’ve included links in the various sections to resources that explain the issues in more depth.</p><p>Even though I do understand the above, let’s be clear: it took experiments with every method that didn’t work to realise that they weren’t doing what I expected, and some pretty focused reading of docs, source code, and Jacek Laskowski’s indispensable <a href="https://jaceklaskowski.gitbooks.io/mastering-apache-spark/">The Internals of Apache Spark</a> to find a solution that does work as I expect.</p><h3>The problem: user level</h3><p>Consider data like these, but imagine millions of rows spread over thousands of dates:</p><pre>   Key        Date      Numeric     Text     <br> -------- ------------ --------- ----------- <br>  ham      2019-01-01         3   Yah        <br>  cheese   2018-12-31         4   Woo        <br>  fish     2019-01-02         5   Hah        <br>  grain    2019-01-01         6   Community  <br>  grain    2019-01-02         7   Community  <br>  ham      2019-01-04         3   jamón</pre><p>And what you want is latest (or earliest, or any criterion relative to the set of rows) entry for each key, like so:</p><pre>   Key        Date      Numeric     Text     <br> -------- ------------ --------- ----------- <br>  cheese   2018-12-31         4   Woo        <br>  fish     2019-01-02         5   Hah        <br>  grain    2019-01-02         7   Community  <br>  ham      2019-01-04         3   jamón</pre><h3>The problem: Spark level</h3><p>The problem with doing this for a very large dataset <a href="https://spark.apache.org/docs/2.4.0/rdd-programming-guide.html#shuffle-operations">in Spark is that grouping by key requires a shuffle</a>, which (a) <a href="https://spark.apache.org/docs/2.4.0/rdd-programming-guide.html#performance-impact">is the enemy of Spark performance</a> (<a href="https://jaceklaskowski.gitbooks.io/mastering-apache-spark/spark-rdd-shuffle.html">see also</a>)(b) expands the amount of data that needs to be held (because shuffle data is generally bigger than input data), which tends to make tuning your job for your cluster parameters (or vice versa) much more important. With big shuffles, you can have slow applications with tasks that fail repeatedly and need to be retried.</p><p>So, given this problem, what you want to do is shuffle the minimum amount of data. The way to do this is to reduce the amount of data going into the shuffle. In the next section, I’ll talk about how.</p><p>As an aside, if you can perform this kind of task incrementally, you can do so faster and with less latency; but sometimes you want to do this as a batch, either because you’re recovering from data loss, you’re ensuring that your stream processing worked (or recovering from it losing some records), or you just don’t want to operate stream infrastructure (and you don’t need low latency).</p><h3>The solution: Aggregators</h3><p><a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.sql.expressions.Aggregator">Aggregators</a> (and <a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.sql.expressions.UserDefinedAggregateFunction">UDAFs</a>, their untyped cousins) are the solution here because they <a href="https://jaceklaskowski.gitbooks.io/mastering-apache-spark/spark-rdd-ShuffleDependency.html">allow Spark to partially perform the aggregation as it maps over the data getting ready to shuffle it (“the map side”)</a> (<a href="https://github.com/apache/spark/blob/113f62dd8c6fb8e6f5c39a18c95af4cf95e334eb/sql/core/src/test/scala/org/apache/spark/sql/execution/PlannerSuite.scala#L57">see code</a>), so that the data actually going into the shuffle is already reduced; then on the receiving side where data are actually grouped by key (by the action of the groupByKey), the same reduce operation can happen again.</p><p>Another part of what makes this work well is that if you’re selecting a fixed number of records per key (e.g. the n latest), you will also remove partition skew, which again makes the reduce side operations much more reliable.</p><h4>Aggregator: example code</h4><p>In this specific example, I’ve chosen to focus on aggregating whole rows. <a href="https://jaceklaskowski.gitbooks.io/mastering-spark-sql/spark-sql-Aggregator.html">Aggregators</a> and UDAFs can be used to also aggregate part of the data in various ways; and again the more you do cut down on the width of your data going into a shuffle the faster it will be.</p><p>See <a href="https://docs.databricks.com/_static/notebooks/dataset-aggregator.html">this notebook</a> and the <a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.sql.expressions.Aggregator">API docs</a> for more examples</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f8361adf58b47195097205679234134/href">https://medium.com/media/2f8361adf58b47195097205679234134/href</a></iframe><p>Using real data, this took 1.2 hours over 1 billion rows.</p><h3>The solution to a different problem: Aggregate Functions, UDAFs, and Sketches</h3><p>UDAFs are the untyped equivalent to Aggregators, and I won’t say much more about them except that if you’re using a custom function that extracts exactly what you need, instead you’re going to get functionality very similar to sql groupby: you can get the original columns in the <a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.sql.Dataset">groupby</a> clause, and then the rest of the columns in your results are aggregates. It’s as fast as an Aggregator, for the same reasons, including that you narrow your data going into the shuffle.</p><p>The code looks a little bit like this:</p><pre>foods.groupBy(&#39;key).agg(max(&quot;date&quot;), sum(&quot;numeric&quot;)).show()</pre><p>Aggregate functions are simply built in (as above), and UDAFs are used in the same way.</p><p>Sketches are probabilistic (i.e. not fully accurate) but fast ways of producing certain types of results. <a href="https://github.com/apache/spark/blob/v2.4.0/common/sketch/src/main/java/org/apache/spark/util/sketch/CountMinSketch.java">Spark has limited support for sketches</a>, but you can read more at <a href="https://datasketches.github.io/">Apache Data Sketches</a> and <a href="https://github.com/google/zetasketch/tree/master">ZetaSketches</a>.</p><h3>Non-Solution: groupByKey + reduceGroups</h3><p>For some reason, this takes forever, and doesn’t do the map-side aggregation you’d expect:</p><pre>// version 1<br>in.<a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.sql.Dataset@groupByKey[K](func:T=%3EK)(implicitevidence$3:org.apache.spark.sql.Encoder[K]):org.apache.spark.sql.KeyValueGroupedDataset[K,T]">groupByKey</a>(_.key).<a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.sql.KeyValueGroupedDataset@reduceGroups(f:(V,V)=%3EV):org.apache.spark.sql.Dataset[(K,V)]">reduceGroups</a>((a: Food, b: Food) =&gt; Seq(a,b).maxBy(_.date)).rdd.values<br>// version 2<br>in.groupByKey(_.key).reduceGroups((a: Food, b: Food) =&gt; Seq(a,b).maxBy(_.date)).map(_._2)<br>// version 3 - as above but with rdd<br>in.rdd.keyBy(_.key).<a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.rdd.PairRDDFunctions@reduceByKey(func:(V,V)=%3EV):org.apache.spark.rdd.RDD[(K,V)]">reduceByKey</a>((a: Food, b: Food) =&gt; Seq(a,b).maxBy(_.date)).values.toDS</pre><p>I haven’t reproduced the query plan diagrams for any of these solutions, largely because none of them look distinctively crazy. Unfortunately, I also have retained the statistics from failed runs.</p><p>Using real data, over 1 billion rows, version 1 took 4.4 hours; version 2 took 4.9 hours, and version 3 failed after 4.9 hours.</p><h3>Non-Solution: mapPartitions + groupByKey + reduceGroups</h3><p>This ought to work. Maybe it can even be made to work. The idea is to do the map-side aggregation oneself before the grouping and reducing. This is what I tried, and it didn’t work for me. I suspect that I would have needed to not accumulate the whole map first before returning the iterator (maybe yield options, then flatMap the Option away)?</p><pre>in.<a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.sql.Dataset@mapPartitions[U](func:Iterator[T]=%3EIterator[U])(implicitevidence$7:org.apache.spark.sql.Encoder[U]):org.apache.spark.sql.Dataset[U]">mapPartitions</a>((i: Iterator[Food]) =&gt; {<br>  val latestRows = HashMap.empty[String, Food]<br>  i.forEach((r: Food) =&gt; {<br>    val latestFood = Seq(<br>       latestRows.get(r.key), Some(r)).flatMap(x=&gt;x).maxBy(_.date)<br>    latestRows.put(r.key, latestFood)<br>  }<br>  latestRows.iterator<br>}).groupByKey(_.key).reduceGroups((a: Food, b: Food) =&gt; Seq(a,b).maxBy(_.date)).rdd.values</pre><p>No timing result, as this fell over almost immediately.</p><h3>Non-Solution: combineByKey</h3><p>This one is kind of disappointing, because it has all the same elements as Aggregator, it just didn’t work well. I tried variants with salting the keys and such in order to reduce skew, but no luck. Fell over after 7.2 hours.</p><pre>in.rdd.keyBy(_.key).<a href="https://spark.apache.org/docs/2.4.0/api/scala/index.html#org.apache.spark.rdd.PairRDDFunctions@combineByKeyWithClassTag[C](createCombiner:V=%3EC,mergeValue:(C,V)=%3EC,mergeCombiners:(C,C)=%3EC)(implicitct:scala.reflect.ClassTag[C]):org.apache.spark.rdd.RDD[(K,C)]">combineByKeyWithClassTag</a>(<br>  createCombiner = {(x: Food) =&gt; x},<br>  mergeValue = ((a: Food, b: Food) =&gt; Seq(a, b).maxBy(_.date)},<br>  mergeCombiners = ((a: Food, b: Food) =&gt; Seq(a, b).maxBy(_.date)},<br>  partitioner = new HashPartitioner(numPartitions))</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e37b53314fad" width="1" height="1" alt=""><hr><p><a href="https://medium.com/build-and-learn/spark-aggregating-your-data-the-fast-way-e37b53314fad">Spark: Aggregating your data the fast way</a> was originally published in <a href="https://medium.com/build-and-learn">Build and Learn</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Streaming is a myth — Reactive vs Rigid is the real distinction]]></title>
            <link>https://medium.com/build-and-learn/streaming-is-a-myth-reactive-vs-rigid-is-the-real-distinction-c2f8cd581f0f?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2f8cd581f0f</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[reactive-programming]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[myths]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Sun, 19 Aug 2018 20:05:18 GMT</pubDate>
            <atom:updated>2018-08-19T20:05:18.960Z</atom:updated>
            <content:encoded><![CDATA[<p>Tl;dr — Streaming architectures are a special case of <a href="https://www.reactivemanifesto.org/">reactive architectures</a> (and not actually a myth). The distinction between reactive and rigid distributed architectures is much more important than streaming vs batch, which are two implementation styles. In this article I’m going to talk about reactive batch systems, and when you might use them instead of streaming. Streaming has a lot of awesome usecases and properties, I’m just not going to talk about them in this article.</p><h3>Why you care about reactive vs rigid not batch vs streaming</h3><p>In short: you want resilient — or “antifragile” — systems instead of fragile systems or specific buzzword compliance.</p><p>Anyone who has built multiple distributed systems (especially in the data space) knows that:</p><ol><li>batch processing is a really easy way to get started;</li><li>there are lots of tools for batch processing; and</li><li>synchronising one batch job to run after another is supposed to have completed is a pain, and will quickly fail.</li></ol><p>Streaming architectures are one fashionable response to this — and a good response — but adoption has been limited, in no small part because streaming is seen as more complex or difficult.</p><p>In fact, streaming systems <strong>are</strong> more difficult in the specific sense that there is not a widely diffused body of knowledge and tooling for developing and testing them. You also need monitoring and tooling to ensure that the streaming processes are always running (which could be as simple as a process supervisor like <a href="http://mmonit.com/monit/">monit</a> or <a href="http://supervisord.org/">supervisor</a>, or even a cron job).</p><h3>What is a “reactive” system anyway?</h3><p><a href="https://www.reactivemanifesto.org/">There’s a manifesto laying out the meaning of the term “reactive”.</a> In short, it means a system that is able to handle changes in load gracefully, be at least somewhat failure tolerant, and rely on asynchronous message passing.</p><h3>What’s batch got to do with it?</h3><p>Specifically, what has batch processing got to do with reactive systems? There are two aspects to this:</p><ol><li>How can batch systems even be reactive?</li><li>Why would I still want to use batch in this brave new world?</li></ol><h4>How can batch systems even be reactive?</h4><p>First, let’s answer how streaming systems are reactive: they buffer data, and spread processing over time. Even without elastic provision of computing resources, as long as system load doesn’t exceed a critical level, all data will be processed eventually, within the time guarantees of the system. Put another way: streaming systems process the data that’s available when it’s available.</p><p>Another aspect of streaming systems that makes them simple is that they usually eliminate any form of centralised control plane to ensure sequencing of jobs.</p><p>There is absolutely no reason that batch systems can’t also process the data that’s available, when it’s available. Instead, batch jobs can on each iteration check what data is available, use some form of explicit or implicit locking to ensure that another invocation doesn’t run on that data, and process away. With this style of processing, there is also no need for a centralised control system to ensure that jobs are running in sequence — their clocks can drift, and jobs can run “too long” for their allocated slots without the system as a whole falling behind.</p><h4>Tell me about some real reactive batch systems</h4><p><a href="https://medium.com/handy-tech/airflow-tips-tricks-and-pitfalls-9ba53fba14eb">The data processing pipeline we built out at Handy</a> was reactive by virtue of the following properties:</p><ol><li>Each invocation of the stream-to-hive transfer job used the timestamp of the objects (“files”) in s3 to know which of those it was supposed to be processing, and would not process later objects.</li><li>Each invocation checked to see if prior invocations had completed, and would pick up the work of previous invocations that had failed. If that meant it ran longer than its slot, the next job would simply fail by design, and then catch up on a later invocation. (This was by design because we didn’t have output locking, or guaranteed non-interference when the jobs were performing outputs to hive directories).</li></ol><p>In fact, there’s no reason why this should be built as a batch system now, but streaming solutions have come a long way in the last 4 years.</p><h4>Tell me about another reactive batch system</h4><p>This is a job to transfer data from a real streaming solution — kafkaconnect to hdfs time partitioned directories — to an environment where daily data sets are assumed to be complete, and not partial (i.e. it’s a time-synchronized batching environment).</p><p>This job checks that kafka connect has not output any new data for two of its flush periods (<a href="https://docs.confluent.io/current/connect/connect-hdfs/docs/configuration_options.html#connector">rotate.interval.ms</a>), and if that condition is met, copies the data to its target location. <a href="https://docs.python.org/3/library/fcntl.html#fcntl.lockf">A filesystem lock</a> is used to ensure that only one instance is operating on one dataset.</p><h4>Reactive batch systems: what are they good for?</h4><p>My second example is a great use of a reactive batch system: to bridge the gap between reactive land (including specifically streaming land) and systems that assume a batch-and-clock based view of the world.</p><p>Another good (or goodish) reason to use a reactive batch system is when you can’t get the operational support to install the infrastructure needed for a streaming or non-batch reactive solution.</p><p>Related to that, when you want to quickly patch in some reactivity before developing a streaming integration, this can be a good solution. If you develop your code in such a way that it does not assume a stream or batch oriented view of the world, (except at the edge of the system), you may even be able to reuse the core logic in a streaming context.</p><h3>What next?</h3><ol><li>Check out Kafka Connect from <a href="https://docs.confluent.io/current/connect/index.html">Confluent</a> or <a href="https://github.com/Landoop/stream-reactor">Landoop</a></li><li><a href="https://medium.com/build-and-learn">Follow my blog for more data engineering and management content</a></li><li>Read about <a href="https://medium.com/handy-tech/airflow-tips-tricks-and-pitfalls-9ba53fba14eb">airflow</a>, one way of implementing batch reactive (and non-reactive) systems</li><li>Clap 👏 for this post below, so other people can find it</li><li>Email me <a href="/service/mailto:marcin.tustin@gmail.com">marcin.tustin@gmail.com</a> about how I can help with your project or company.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2f8cd581f0f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/build-and-learn/streaming-is-a-myth-reactive-vs-rigid-is-the-real-distinction-c2f8cd581f0f">Streaming is a myth — Reactive vs Rigid is the real distinction</a> was originally published in <a href="https://medium.com/build-and-learn">Build and Learn</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Is Shapeless worth it? What is Shapeless anyway?]]></title>
            <link>https://medium.com/build-and-learn/is-shapeless-worth-it-what-is-shapeless-anyway-900cba6b717a?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/900cba6b717a</guid>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[scala]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Mon, 01 Jan 2018 21:45:42 GMT</pubDate>
            <atom:updated>2018-01-02T14:32:37.602Z</atom:updated>
            <content:encoded><![CDATA[<h4>Getting started with generic programming in Scala, and best practices for generic programming</h4><p>This article explores what generic programming is, how it can be used to solve the problem of reusing the same Spark code as concrete types change through your pipeline, and why <a href="https://github.com/milessabin/shapeless/wiki/Feature-overview:-shapeless-2.0.0">Shapeless</a> is largely the tool of choice for generic programming in Scala. I also present some style suggestions for working with Shapeless.</p><p>It’s worth noting that if you really want to go down this path in Spark code, the <a href="https://github.com/typelevel/frameless">Frameless</a> project aims to facilitate that.</p><p><strong>TL;DR:</strong> Yeah, Shapeless is kinda worth it. None of the alternatives are better. It gives you type safety where other techniques would not provide it, but it requirements a fair investment of time to learn how to write it. It’s easy to write it in a way that is easy to read even for people who don’t know it.</p><h4>What is generic programming and how does Shapeless fit in?</h4><p>Generic programming does not have a singular definition I can find, but synthesising <a href="https://en.wikipedia.org/wiki/Generic_programming">these</a> <a href="http://www.cs.ox.ac.uk/jeremy.gibbons/publications/scalagp-jfp.pdf">sources</a>, I would define it as writing programs for types to be specified later, where there is no meaningful base class onto which to stuff all the operations. To quote from the <a href="http://www.cs.ox.ac.uk/jeremy.gibbons/publications/scalagp-jfp.pdf">linked paper</a>:</p><blockquote>parametric polymorphism abstracts from the ‘integers’ in ‘lists of integers’, whereas [generic programming] abstracts from the ‘lists of’</blockquote><p>In fact, our example will focus on “the integers” where “the integers” are in fact case classes.</p><p>Shapeless fits in as the premier Scala library for generic programming. Its big advantage is that it doesn’t lose type safety, and in effect provides a type-based mini language for programming the compiler. In short, it’s the pre-written, compiler-checked option in this space in Scala.</p><h4>Why would I want to do generic programming?</h4><p>Any time the alternatives are copypasta or jamming something awkwardly on a remote base class, generic programming starts to look very good.</p><p>In general, in any case where you want to make sure exactly the same logic is used for multiple types, you have a good case for generic programming.</p><h4>Show me a problem being solved with generic programming right now</h4><p>Consider the following problem: We want to bring together data about when certain set top boxes are tuned to certain channels (viewership), join it with information about what was playing on those channels (schedules), and roll it up into time segments (for ease of querying) based on the viewership and schedule characteristics. Later, the schedule information changes, and so we need to compute refreshed final data. Ignoring the option of storing our intermediates (data size and master data management issues make this relatively unattractive unless the necessary infrastructure is in place), the next option is to rematch the schedule data against the final data.</p><p>One solution is to use a dynamically typed solution (Python generally, or DataFrames in any Spark-supported language). This option allows us to write uncluttered code, and is an excellent solution in many cases. Indeed, the ability to write generic code without any particular ceremony is a huge reason to use dynamic languages. The disadvantage of this style of programming is that there is no automated, compile-time check that the data being passed in conforms to the schema that the code assumes it has. In data-heavy work, this can make code much more difficult to change, as commonly implicit assumptions about the shape of the data are scattered through the code. (As an aside: any generally applicable suggestions for solving that problem are welcome). Reflection-based approaches suffer from the same lack of type-checking, although they may be easier to test.</p><p>One solution to solving the schema-assumption problem is to make the schema explicit, and tag the code with the types involved. With concrete types it looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/476de3afd93076ef44533145ca16ff4d/href">https://medium.com/media/476de3afd93076ef44533145ca16ff4d/href</a></iframe><p>Very good so far — we have made the schemas explicit, put them in our parameter list, and the compiler will check them for us.</p><p><strong>A Parametric Solution: </strong>If we don’t want to return to DataFrames, our options are to copy and paste with different type signatures, or abstract over the types of the case classes. Here is a preliminary version:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4b2fd7d3ff0b20003460b890b97288a/href">https://medium.com/media/d4b2fd7d3ff0b20003460b890b97288a/href</a></iframe><p>This should compile just fine. Unfortunately, we now have no guarantee that this will actually work at runtime, because we don’t know what’s in viewership any more — it could be anything.</p><p><strong>A Generic Solution</strong>: So, we want to specify that viewership has the time columns we expect. We also still want to bring through all the columns that were on viewership, but now we have to handle that there will be clashes between the column names on our final data (it will have program_id) and the schedules data.</p><p>Let’s tackle the type constraints first:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ff7709dc145f7284590a36abc570a4cd/href">https://medium.com/media/ff7709dc145f7284590a36abc570a4cd/href</a></iframe><p>Looks good so far. Now let’s tackle filling out the columns to select at line 39. Being as we’re using Spark, we could probably recover the column names from the DataSet objects. That’s not a bad solution, but we put our schema information in the case classes, not the DataSets. While I can’t think of a concrete problem with that, we’re inviting some kind of lost in translation problem, so let’s avoid it.</p><p>Take a deep breath: this is going to be a big change.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00eb013fb4e934ebcdfe216545328b9a/href">https://medium.com/media/00eb013fb4e934ebcdfe216545328b9a/href</a></iframe><p>Hopefully this is fairly easy to read. We have added some not insignificant boilerplate, but we have very clearly described to the reader and the compiler the requirements we place on our input data, and we have avoided writing any reflection-based code ourselves to retrieve the keys.</p><p>Incidentally, the one piece of safety we are missing here is that we don’t automatically check that the result type is conformable with the selected columns from the input types. For that, we would need to move the column merge into the type parameters, and compare with the fields in RESULT. With that change, this code would be bulletproof.</p><p>Writing this code was harder than reading it — there isn’t great step-by-step documentation for Shapeless, and frequently I had to refer to the code to find out how it all fit together. A lot of the time the compiler generates helpful error messages, but sometime the error messages took me on a wild goose chase. <a href="https://stackoverflow.com/questions/46525541/how-to-generically-extract-field-names-with-shapeless">Indeed, this StackOverflow post was instrumental in getting this code to work.</a></p><p>That said, I could probably have read this <a href="https://github.com/underscoreio/shapeless-guide">book length guide to Shapeless</a> and picked up a lot that way; indeed I probably will read it.</p><h4>Was it worth it? Would I do it again?</h4><p>On the whole, I think I will do this kind of thing again. Learning to work with Shapeless will be effort amortized over using it. I really hate it when my ETLs die in production, and I hate chasing down data shape issues.</p><p>Library writers make some <a href="https://github.com/milessabin/shapeless/wiki/Built-with-shapeless">wonderful generic interfaces</a> which require no boilerplate on the part of the library user. A<a href="https://github.com/milessabin/shapeless/wiki/Built-with-shapeless"> list of some of them are here.</a> The more boilerplate you’re generating in your own code, the more I would recommend looking at Shapeless.</p><h4>Let’s talk about style</h4><p><a href="https://github.com/underscoreio/shapeless-guide">The Type Astronaut’s Guide to Shapeless</a> has a whole chapter dedicated to style, and I have also relied on the <a href="https://gitter.im/milessabin/shapeless?at=5a480133edd2230811f512ca">guidance given here.</a></p><p>Look at the code above again, and hopefully you will notice a few things:</p><ul><li>Descriptive names of implicit parameters that are of any interest later in the code</li><li>Types we want to specify explicitly MUST be in a different type parameter list from types we want calculated by the compiler</li><li>Comments explain what the implicits are, because they are code</li><li>Implicit parameters should be laid out in logical order leading up to what we want</li><li>Unfortunately, because implicit resolution happens in textual order, we had to put the ToTraversable instances at the end</li><li>You need to put all this implicit magic at the entry point to generic code — the TypeTags help make the types so tagged (i.e. the T in TypeTag[T]) available in the body of the function, but because types are erased by the compiler in conformity with Java’s erasure rules, the compiler cannot fully infer the necessary implicits on further nested calls.</li></ul><h4>Conclusion</h4><p>See the TL;DR at the top of the article, but in short if you like type safety and you don’t like copypasta, it’s a strong option. Your other options will likely involve a zone of non-safety and testing around that.</p><p><em>If you learned from this article, please hit the “Clap” button. Claps help bring this article to the attention of more readers in the Medium network.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=900cba6b717a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/build-and-learn/is-shapeless-worth-it-what-is-shapeless-anyway-900cba6b717a">Is Shapeless worth it? What is Shapeless anyway?</a> was originally published in <a href="https://medium.com/build-and-learn">Build and Learn</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Can you make a data application as good as FRED?]]></title>
            <link>https://medium.com/@albamus/can-you-make-a-data-application-as-good-as-fred-bf5ddc43bc31?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/bf5ddc43bc31</guid>
            <category><![CDATA[user-experience]]></category>
            <category><![CDATA[master-data-management]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-visualization]]></category>
            <category><![CDATA[user-interface]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Wed, 27 Dec 2017 05:22:56 GMT</pubDate>
            <atom:updated>2017-12-27T15:46:30.928Z</atom:updated>
            <content:encoded><![CDATA[<h4>What makes the Federal Reserve’s data explorer so good?</h4><p>FRED is the St. Louis Fed’s tool to explore economic data series, manipulate them, and then visualise them. It makes it easy to generate graphs like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lfccdW5moVQn5QxOE3vsuA.png" /><figcaption>Relative inflation of apparel vs all goods in the US</figcaption></figure><p>FRED is an undeniable joy to use. It’s really fun to explore these datasets. What makes the FRED experience so good, and how can we learn from it?</p><h3>The interface makes it easy to perform the operations you likely want to</h3><p>a. The interface follows well established metaphors to deliver the functionality</p><p>b. Accordingly, it is fairly easy to explore all the options available to the user</p><p>c. Use of algebraic input to manipulate the data series (normalise, combine, etc) means users are using a metaphor they know very well. Attempts to make this easier generally make it harder for everybody.</p><p>d. Almost everything has contextual help, which provides enough description such that the user can start anywhere and gather context about the whole application.</p><h4>Takeaway for us</h4><p>Try to use an off the shelf interface that has documentation and a strongly consistent interface. If you choose to make your own, less is more in many ways. Taking that into account, don’t be afraid to create your own custom, lean interface.</p><h4>The datasets are richly indexed, with tags, date ranges, sources, and descriptive names. Most datasets also have textual descriptions about their origin.</h4><p>Unfortunately most organisations don’t understand the benefit of data cataloguing and curation. The ability to easily discover data sets that one wants to work with is really essential to FRED appealing to anyone whose job isn’t using FRED every day. If you don’t believe me, compare <a href="https://www.ons.gov.uk/timeseriestool">the UK’s equivalent with FRED</a>.</p><p>The ONS Time Series Tool seems similar, but just isn’t as easy. The selection area on the left is static, rather than dynamic. In FRED it changes dynamically to reveal more detailed tags. The selection tool in FRED shows you all your options (at the current level) all at once; the ONS tool just has drop downs, so you can’t look at the options except by interacting with the drop down specifically. No leisurely consideration for UK researchers.</p><p>The FRED display of each search result is taller — it takes up more screen height. The big letters make it very easy to scan the titles. The titles are pretty good, although some are cryptic. You always get the date range, and you get a description of data frequency and units. The ONS results probably contain more information to those well versed in the terminology used. However, these are all in codes. You won’t see the date range available, but you will see the publication date.</p><p>Finally, units — Fred knows what units a series is in by default, and how to transform it to other types of units.</p><h4>Takeaway for us</h4><p>Establishing a standard to describe the data is important; but the content of the standard does matter. Consider who your users are, and what they really need to see. The ONS tool is clearly designed for people who use it every day. FRED is clearly intended for the professional user, but accomodates new users.</p><p>Consider making data curation a part of your data users job — think of something like a wiki, but structured, and integrated with search and data visualisation experience.</p><p>Unfortunately there are not good open source data cataloguing tools, and even commercial BI tools have very uneven built in cataloguing. Looker is built around data curation, but there is really no way to publish the metadata to ones users. Domo has pretty good support here, but isn’t super smooth.</p><p>There are commercial tools in this space. You’ll want to carefully evaluate the experience of both consuming and publishing data through these platforms.</p><h3>Almost nothing in the way of bells and whistles beyond the core functionality</h3><p>FRED lets you do three things: find data sets, manipulate and visualise them, and download or publish the visualisation. Other than displaying some metadata and customising the display, that’s it.</p><p>What’s good about this minimalism is that the less you can do, the easier it is to figure out the functionality that is there. There’s only so much clicking around you can do before you learn enough about the interface to get oriented.</p><h3>TL;DR</h3><p>Keep your data applications simple (small, coherent set of features) and make it easy for users to find the data sets and keep them in good order for themselves and their colleagues.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bf5ddc43bc31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Perfect table migrations in redshift and hive]]></title>
            <link>https://medium.com/build-and-learn/perfect-table-migrations-in-redshift-and-hive-3bf12c47ad70?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/3bf12c47ad70</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[redshift]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[data]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Sat, 16 Dec 2017 22:46:44 GMT</pubDate>
            <atom:updated>2017-12-30T15:13:07.791Z</atom:updated>
            <content:encoded><![CDATA[<h4>Always do your migrations like this</h4><p>Here’s a neat little trick due to <a href="https://www.linkedin.com/in/davidhell/">David Heller</a> at <a href="https://www.alooma.com/">Alooma</a> — perform any migration in redshift (or other columnar store) without any need for downtime, table locking or any other unpleasantness.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/db1068a0b15cc0d2058485de4e419e06/href">https://medium.com/media/db1068a0b15cc0d2058485de4e419e06/href</a></iframe><p>What makes this perfect is that there is no loss of production availability to read data OR to write events to the right table.</p><p>Even in a non-transactional environment, if any current events get sent to the old table, the final copy copies them over. (Note that the old table effectively acts as a buffer, so from the period of readers of the new table, events sent to the old table during this procedure will have the extra lag of the final copy).</p><p>There is also no risk of data loss, because operating by renaming means you can always recover your prior state.</p><p>The only risk of data loss is if your event streaming solution doesn’t buffer events before they are finally committed to the database store. In that case, cutting over to the new table presents a risk if the schemas don’t match; that said, if you can’t buffer events somewhere, you’ll always lose events if you have to change your table schema.</p><p>If you model all your table migrations on this one, you should enjoy many years of tear-free operations.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3bf12c47ad70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/build-and-learn/perfect-table-migrations-in-redshift-and-hive-3bf12c47ad70">Perfect table migrations in redshift and hive</a> was originally published in <a href="https://medium.com/build-and-learn">Build and Learn</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick notes on Strata 2017 NYC]]></title>
            <link>https://medium.com/data-science/quick-notes-on-strata-2017-nyc-9c92679fbed4?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c92679fbed4</guid>
            <category><![CDATA[strata-data-conference]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[business]]></category>
            <category><![CDATA[conference]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Sun, 01 Oct 2017 18:10:44 GMT</pubDate>
            <atom:updated>2017-10-01T18:10:44.175Z</atom:updated>
            <content:encoded><![CDATA[<h3>I now understand why tensorflow is a big deal</h3><p>It’s a concise way of doing linear algebra and optimization that can take advantage of multiple backends. It also comes with a bunch of precanned algorithms developed by Google’s large staff of mathematicians dedicated to the task.</p><p>You can use it for traditional machine learning, non-traditional optimization based tasks (e.g. Spline fitting), and anything that works as linear algebra. Expect the next thing in computing fast to be casting more operations as linear algebra. <a href="https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/61150">Shout out to Ted Dunning for bringing that home to me.</a></p><h3>Tensorflow may be the killer app for Google cloud</h3><p>It seems like most other ways of <a href="https://www.tensorflow.org/deploy/">deploying tensorflow</a> are a pain. I guess it’s time to ramp up on google cloud if you’re a devops person.</p><h3>ModelOps is becoming a thing</h3><p>Lots of stuff about putting machine learning into production. Because models (as currently made) are essentially trained on one context, and are timeless and spaceless, current techniques demand an operational approach.</p><p>In particular, reduce your model training method to an automated pipeline. Then, retrain for each new context (as granular as a single clinic or single truck).</p><p><strong>Retrain your model when the distribution of output predictions diverges significantly from the distribution in the training set.</strong> Significant divergence criteria are a matter of judgment.</p><p>Monitor effectiveness — your model changes how people behave which destroys its validity. This is so both for good actors (e.g. Doctors making decisions about who to keep in hospital) and bad actors (e.g. Hackers trying to fool your hacker detector).</p><p>In particular, where training data is sparse, you will need to think about alternate approaches to prediction and training. <a href="https://www.pacific.ai/">David Talby</a> (<a href="https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/60333">talk</a>) gave the example of detecting fraudulent behavior in banks via their email streams. A simple classifier won’t work, because the classes (bad message vs good message) are so unbalanced that all standard approaches will overfit to the good class, and say every message is good (perhaps 1 in a million is bad). Instead he and his team had a regressor predict probability of badness, displayed messages to the (existing) human review team, and retrained based on the human responses.</p><h3>Model designers must incorporate causality or GTFO</h3><p>There are enough rules of thumb and enough GPUs that using standard model types is quickly being automated. <a href="https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/59747">There are already commercial tools and open source tools that largely automate tuning</a>. Feature engineering and model type selection are about to be automated.</p><p>Making a modeling pipeline that takes labeled data, and trains a model on it without any human effort to understand features or models or tune them is going to be a standard engineering task in 5 years, and completely productised in 10. In large part this is because current techniques are pure, contextless pattern learners. As humans learn how to use these techniques, the heuristics and techniques of development are being operationalised as their own kind of optimization algorithm that allows automated navigation of the solution space.</p><p>Data prep isn’t going away. Better tooling exists, and for things that iterate slowly, humans will be on the data prep side. For things that go quickly, data engineers will build online and automated systems that at the very least cut down the manual handling to a manageable amount.</p><p>So much for what’s on the way out. <strong>Causality is what’s on the way in.</strong></p><p>This has at least two dimensions:</p><ol><li>Choosing mathematical models that correspond to the underlying process; and</li><li>Modeling parts of the underlying process to create a complete model that incorporates the known causal relationships</li></ol><p>An excellent example of the first was given by <a href="https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/61259">a speaker who modeled the relationship between futures volume and volatility by fitting cubic splines to the data</a>. In this case, the model is at least more tractable to train, but also limits the amount of retraining needed (because spline segments effect on their neighbours dies out over the number of links in the spline). The process also continues forever, over time, with potential changes in the environment and market, so a spline is a much more natural model for the process, than attempting to fit one giant polynomial to all of time.</p><p>Not coincidentally, another buzzword right now is “interpretability”. There are vendors focusing on techniques to understand the dynamics of the standard non-linear models (most notably neural networks). <a href="https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/59747">The talk from H2O</a> was interesting, and smart, and you’ll probably want to use those techniques if you need to care about what your general purpose models are doing. However, if you do choose to use a model that actually corresponds to the underlying process, interpreting the trained model should be vastly easier.</p><p><a href="https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/61017">An excellent example of the second</a> was a <a href="https://conferences.oreilly.com/strata/strata-ny/public/schedule/speakers">speaker</a> whose company (<a href="https://www.vnomicscorp.com/">VNomics</a>) builds “digital twins” of physical trucks. There’s a lot of interest in that talk — and in fact I wish it had been scheduled as a one day workshop — but most relevant to this is that his company has models for the performance of each part of the truck (e.g. this model of truck with this particular model of drive train and this braking system). Those models are used as a first pass to extract sensor readings into features that are fed into a more general regression model of fuel economy. In this way, the model (a) incorporates knowledge of what is happening, rather than just blasting raw data into a model and relying on the regressor model to sort it out; and (b) the extraction models are themselves composable and reusable, allowing each truck to have a customised feature extractor pipeline without writing new code.</p><p>A second part of the power of these “digital twin” models is that they can be used a baseline to A/B test changes in the physical model (e.g. a different way of inflating the tires). Again, if you want to interpret what’s up with your model, deliberately engineered feature extraction and changes in the thing producing the data will help.</p><h3>Unsexy Tech is Still Important</h3><h4>The capability gap is ever wider, and late come organisations are being left behind</h4><p>While some of us are nodding our heads sagely at presentations about operational aspect of machine learning, other people are attending 40 minutes presentations with the basic message of <a href="https://conferences.oreilly.com/strata/strata-ny/public/schedule/detail/61029">“this is actually hard, your team will need time to ramp up on the tech”</a> and people describing what a data warehouse on cloud infrastructure looks like.</p><p>If your team are discovering that big data is hard, or you want to go into your project with a plan, do contact me. I and my team will be happy to sort you out with planning, training, and execution.</p><p>The exhibitors included a lot of people selling solutions to support data science teams, and commercial in memory distributed databases with no obvious differentiation from what can be achieved with open source tools, but really no-one selling genuine on-ramp solutions. Notably absent was anything that ties together end-to-end execution, other than Cask. <a href="http://astronomer.io/">Astronomer.io</a> wasn’t exhibiting, although I think they’re the only party trying to compete to provide a real hosted on ramp.</p><p>There were a lot of solutions for data prep, and data discovery, with fewer focused on data plane security and control. The open source solutions in the data discovery, cataloguing, and control space remain awful figleaves from the major vendors, or in the case of <a href="https://github.com/FINRAOS/herd">herd</a> (from FINRA), an apparently very full featured solution, but with little documentation.</p><p>My suspicion is that the low cost option in this space will be catalogues tied to orchestration solutions, as in AWS’ Glue, or <a href="http://astronomer.io/">Astronomer.io</a>.</p><h3>Focus on the business case</h3><p>Experience continues to bear out that data engineering or analytic work have to happen in the context of a business case, and an ongoing commitment to data as an asset. There is a temptation to treat “big data” and “deep learning” like magic pixie dust that engineering can sprinkle on the business to achieve magical results.</p><p>Unfortunately, that’s not the case, and there are vendors that would love to sell you solutions with that premise. In fairness to many of them, their solutions may accelerate your engineering team’s progress by insulating them from architectural mistakes, but you’ll still have a half-baked data platform looking for an application.</p><p>If you do see opportunities in data, but aren’t quite sure how to plan for it, contact me. I and my team can help you develop the strategy, the product vision, set up your engineering team for success, and guide you toward the vendors and solutions that make the most sense for you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c92679fbed4" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/quick-notes-on-strata-2017-nyc-9c92679fbed4">Quick notes on Strata 2017 NYC</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing and Error Handling in http4s]]></title>
            <link>https://medium.com/@albamus/testing-and-error-handling-in-http4s-2a05572e535d?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a05572e535d</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[typelevel]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Sat, 26 Aug 2017 21:30:06 GMT</pubDate>
            <atom:updated>2017-08-26T21:30:06.336Z</atom:updated>
            <content:encoded><![CDATA[<h4>The missing docs for testing, error, handling, and JSON decoding</h4><p>Read this if you are trying to get started with http4s, or are looking for a minimal scala web framework. Skip to the heading “http4s testing” if you know all about http4s and the libraries it depends on.</p><p><a href="https://github.com/marcintustin/http4s-example">An example project containing all the code used in this tutorial is here.</a></p><p>http4s Is an idiomatic, purely functional HTTP layer for Scala. It pitches itself as being an equivalent to Rack or WSGI, but with its DSL is a lot more like Sinatra or Flask (in my opinion, and not that of the <a href="https://github.com/rossabaker">maintainer</a>s).</p><p>If you want to do web services in Scala without the overhead of an all encompassing framework, it’s a good choice. <a href="http://scalatra.org/">Scalatra</a> or <a href="https://twitter.github.io/finatra/user-guide/index.html">Finatra</a> aim to be more fully featured. The advantage of http4s is that it is primarily built on the <a href="https://typelevel.org/">Typelevel</a> and <a href="https://github.com/scalaz/scalaz">Scalaz</a> library stacks. If you like them, you’ll likely like http4s.</p><h3>General http4s tutorial</h3><p><a href="http://http4s.org/v0.15/">The http4s tutorial is here</a>. It’s good. This tutorial is explicitly based on that tutorial extends its examples, and supplements it. This article provides a very brief introduction to the http4s model in order to make error handling and testing easier to understand</p><p>This is the version for 0.15, which is the latest release. <a href="http://http4s.org/versions/">Later versions provide a transition path to cats-effect and fs2 to replace Task and scalaz-streams</a>.</p><h4>The http4s model</h4><p>The http4s APIs exist on two levels: “plain” objects that describe requests, responses, JSON, and the like, and APIs that return scalaz.concurrent.Task objects that wrap plain objects.</p><p>Tasks are like a purer, delayed, future. Because they are trampolined, they don’t need their own thread. You do need to explicitly run them, and you can rerun them over and over (which should be safe if all your code is pure within them; http4s’ code is pure). That’s the important thing: you’re getting a monadic (wrapper) object that needs to be run explicitly.</p><p><a href="https://github.com/indyscala/scalaz-task-intro/blob/master/presentation.md">A good description of the differences is here</a> and <a href="http://timperrett.com/2014/07/20/scalaz-task-the-missing-documentation/">the best known documentation is here</a>.</p><p>Finally, http4s uses scalaz-streams (or later, FS2, the successor project) for dealing with streams. For our purposes, that means generating and modelling request and response bodies. If Tasks represent a delayed computation, Streams represent a delayed computation of a (possibly infinite) sequence of values. <a href="https://github.com/functional-streams-for-scala/fs2/blob/series/0.10/docs/guide.md">More about that here.</a></p><p>If you’re confused about streams, consider the difference between reducing a sequence, and getting only the final result, and performing a reduce where you incrementally request each reduced value in turn. The former is like a Task; the latter is like a Stream.</p><p>The other <a href="https://blog.scalac.io/2017/06/01/why-should-you-care-about-monix.html">major scala stream library is Monix.</a></p><h3>http4s Testing</h3><p>The http4s tutorial does not (yet) cover testing. The testing strategy shown below is a simple consequence of the layers of tasks and streams in play.</p><p>In short, you construct a request with a body, and run the task to get the underlying request to pass to your service. This gives you a task for a response, which you run, extract the body from, run that (or rather, runLast because you’re working with a Stream), and decode to compare the text with your expectation.</p><p>In this way, you can test any body or headers.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3761f937a8456fff56a1f1115d583815/href">https://medium.com/media/3761f937a8456fff56a1f1115d583815/href</a></iframe><h3>http4s Error Handling</h3><p>Now that we understand the basic model, it’s worth looking at our service again:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bd557bbf887230c9059454bff7836df/href">https://medium.com/media/7bd557bbf887230c9059454bff7836df/href</a></iframe><p>Note that in line 4, Ok(Json.obj(“message” -&gt; Json.fromString(s”Hello, ${name}”))) doesn’t create a response, but a Task[Response]. That’s why a for comprehension is used for the multiline examples in the tutorial — to work “inside” the Task monad. See also, <a href="http://http4s.org/v0.15/api/org/http4s/package$HttpService$.html#apply(pf:PartialFunction[org.http4s.Request,scalaz.concurrent.Task[org.http4s.Response]]):org.http4s.package.HttpService">the documentation of HttpService.</a></p><p>Accordingly, to handle errors in the request, we need to act monadically. First, we need to ensure that errors are returned as objects, rather than raised as exceptions (which is what the attempt in line 21 is doing). Secondly, we need to handle those exceptions using whatever monadic style we like; I find the use of pattern matching the simplest way to decide what to do.</p><p>Note that the nested match is because http4s will wrap the io.circe.DecodingFailure with an org.http4s.InvalidMessageBodyFailure, the latter of which does not have the same diagnostic as the show message of the former.</p><h3>Custom JSON Decoding</h3><p>This is as much a circe issue as an http4s issue, but neither of them tell you how to do custom decoding, because you likely won’t need it. If you do need it, you’ll need to become familiar with <a href="https://circe.github.io/circe/cursors.html">io.circe.HCursor</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c7d90faac599006a693bebcbb1ec30ef/href">https://medium.com/media/c7d90faac599006a693bebcbb1ec30ef/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a05572e535d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview research link dump]]></title>
            <link>https://medium.com/build-and-learn/interview-research-link-dump-68a52ac567de?source=rss-7356c6cedd59------2</link>
            <guid isPermaLink="false">https://medium.com/p/68a52ac567de</guid>
            <category><![CDATA[product-management]]></category>
            <category><![CDATA[user-research]]></category>
            <category><![CDATA[research]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[lean-startup]]></category>
            <dc:creator><![CDATA[Marcin Tustin]]></dc:creator>
            <pubDate>Thu, 18 May 2017 13:23:57 GMT</pubDate>
            <atom:updated>2017-05-18T13:30:02.266Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve used semi-structured interviews for both academic and user research (and you can have a semi-structured questionnaire too). I’ve been reading more into the subject recently, so here are some links of interest. Lawyers will likely find a lot of this familiar.</p><iframe src="https://drive.google.com/viewerng/viewer?url=http%3A//eprints.ncrm.ac.uk/3276/1/complete_proofs.pdf&amp;embedded=true" width="600" height="780" frameborder="0" scrolling="no"><a href="https://medium.com/media/6bdc85bc283e0d9649da8a7d4fbdbabb/href">https://medium.com/media/6bdc85bc283e0d9649da8a7d4fbdbabb/href</a></iframe><ul><li><a href="https://medium.com/interactive-mind/5-steps-to-create-good-user-interview-questions-by-metacole-a-comprehensive-guide-8a591b0e2162">5 Steps to Create Good User Interview Questions By @Metacole — A Comprehensive Guide</a></li><li><a href="http://www.qualres.org/HomePhil-3514.html">RWJF - Qualitative Research Guidelines Project | Philosophical Tension | Common Paradigms</a></li><li><a href="http://www.uxmatters.com/mt/archives/2014/09/getting-inside-your-users-heads-9-interviewing-tips.php">Getting Inside Your Users&#39; Heads: 9 Interviewing Tips</a></li></ul><p>The latter has tips on using unstructured and opportunistic sources of information; something much of the writing ignores.</p><p>Bonus research — great use of a single question as a form of structured research:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1021/1*XGbXOUnhPhgG3OguIFcsKA.png" /><figcaption>source: <a href="http://thisisntfuckingdalston.co.uk/"><strong>thisisntfuckingdalston.co.uk</strong></a></figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=68a52ac567de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/build-and-learn/interview-research-link-dump-68a52ac567de">Interview research link dump</a> was originally published in <a href="https://medium.com/build-and-learn">Build and Learn</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>