<?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[Agilion - Medium]]></title>
        <description><![CDATA[Consulting - Medium]]></description>
        <link>https://medium.com/agilion-product-development?source=rss----43d505a72b65---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Agilion - Medium</title>
            <link>https://medium.com/agilion-product-development?source=rss----43d505a72b65---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 02:29:16 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/agilion-product-development" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Decoding a Hosted CSV file in Elixir]]></title>
            <link>https://medium.com/agilion-product-development/decoding-a-hosted-csv-file-in-elixir-7aa0bb3f7468?source=rss----43d505a72b65---4</link>
            <guid isPermaLink="false">https://medium.com/p/7aa0bb3f7468</guid>
            <category><![CDATA[elixir]]></category>
            <dc:creator><![CDATA[Peter Brown]]></dc:creator>
            <pubDate>Fri, 21 Apr 2017 20:51:35 GMT</pubDate>
            <atom:updated>2019-08-12T21:02:16.623Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pgIJFo9H462zIUyUZeWlpA.png" /></figure><p>I’m currently working on a project that requires us to migrate a legacy database to a Heroku Postgres database using large CSV files. Due to the size of the files and Heroku’s limitations, we cannot read the files from the local file system.</p><p>When we started to think about ways to import the data, my first thought was to host the files on S3 and just run a mix task that streamed the file to a CSV decoder. It turns out that’s not as straightforward as I was hoping.</p><p>Our requirements:</p><ol><li>CSV files must be hosted remotely and accessible over the web to Heroku.</li><li>CSV files may be very large so they cannot not downloaded to the Heroku filesystem or read into memory.</li></ol><h3>Streaming CSV Data</h3><p>Normally if I was importing CSV data in Elixir, I would use a combo of <a href="https://hexdocs.pm/elixir/File.html#stream!/3">File.stream!/3</a> and <a href="https://hexdocs.pm/csv/CSV.html#decode/2">CSV.decode/2</a> to do something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/234454f81e3ec49fa3c231e34e668a27/href">https://medium.com/media/234454f81e3ec49fa3c231e34e668a27/href</a></iframe><p>File.stream! is awesome except it only works with local files. Since we can’t use the local filesystem to store these CSV files, I started researching how I could stream a remote file to the CSV decoder.</p><p>I wanted to be able to pass a URL to a function and have it behave exactly like File.stream!.</p><p>In other words, I wanted something like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4e249cb7c6a4c47586b3582c3a8d190/href">https://medium.com/media/d4e249cb7c6a4c47586b3582c3a8d190/href</a></iframe><h3>Streaming Resources</h3><p>I stumbled across this <a href="https://gist.github.com/avdi/7990684">outdated streaming example</a> from Avdi Grimm that used <a href="https://hexdocs.pm/elixir/Stream.html#resource/3">Stream.resource/3</a>.</p><p>Stream.resource is a bit of a Swiss army knife for creating streams in that it allows you to emit a sequence of values from any resource and do whatever you want with those values. It feels very similar to doing a <a href="https://hexdocs.pm/elixir/Enum.html#map_reduce/3">map reduce</a> where you use an accumulator to pass state from call to call.</p><p>Stream.resource takes three functions as arguments. The first function is called once at the beginning, the second function is called recursively with an accumulator until it returns {:halt, &lt;any_value&gt;}, and the third function is called once at the end, receiving &lt;any_value&gt;.</p><p>The example provided by the Elixir docs shows how you might use this to stream from a file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/530d4da35f6be27b5188798238506000/href">https://medium.com/media/530d4da35f6be27b5188798238506000/href</a></iframe><p>In the example above, the first “start” function opens the file and returns the IO result. The second function reads a single line from the file and returns a tuple containing the line to be emitted as an array, and the accumulator (the IO result) that will get passed to the next call. When it gets to the end of the file, it returns {:halt, file} passing file to the third function which closes the file.</p><h3>Reading the CSV</h3><p>With everything above in mind, we need to be able to replace File.open!/1 with something that supports a hosted file that can be read over HTTP(s). Avdi’s example used Hackney, and after looking at some alternatives like <a href="https://github.com/edgurgel/httpoison#async-requests">HTTPoison’s async functionality</a>, Hackney seemed like the simplest approach.</p><p>Hackney has a poorly documented <a href="https://hexdocs.pm/hackney/hackney.html#stream_body-1">:hackney.stream_body/1</a> function that allows us to stream chunks from a remote HTTP resource. It works in a similar way to <a href="https://hexdocs.pm/elixir/IO.html#read/2">IO.read/2</a>, but instead of reading one line at a time, it reads chunks of data like <a href="https://hexdocs.pm/elixir/Stream.html#chunk/4">Stream.chunk/4</a>.</p><p>In order to work with stream_body, we need to first open a connection to a remote file with :hackney.get() and pass a reference to that connection to stream_body.</p><p>Here’s a simplified example of using get() with stream_body() to stream a single chunk:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d85a1d0c7c2251d3f08a0dedfa5b5ac2/href">https://medium.com/media/d85a1d0c7c2251d3f08a0dedfa5b5ac2/href</a></iframe><p>One problem with using stream_body() is that the data streamed with each call is unlikely to end in a complete CSV row. Since the chunking is based on byte-size, most times it will return a few rows and end with a partial row. This is a problem because the CSV decoder requires each value streamed to it to be a complete CSV row.</p><p>To get around this problem, I am splitting out the last line of the data and passing that to the next function call as a “partial row”.</p><p>So for example if we had chunk that looked like:</p><pre>data = &quot;1,2,3,4\n5,6,7,8\n9,10&quot;</pre><p>I’m splitting apart the complete rows from the partial row, emitting just the complete rows, and sending the partial back with the accumulator:</p><pre>rows = [&quot;1,2,3,4,5&quot;,&quot;6,7,8,9,10&quot;]<br>partial_row = &quot;9,10&quot;</pre><p>The partial row to the next call so it can be prepending to the next chunk like so:</p><pre>next_chunk = &quot;11,12\n13,14,15,16\n17&quot;<br>partial_row = &quot;9,10&quot;</pre><pre>data = &quot;9,10,11,12\n13,14,15,16\n17&quot;</pre><p>Rinse, repeat.</p><h3>All together now</h3><p>The following is all the code I needed for streaming large CSV files. It will let us host the files on S3 or some other hosting provider and read them with an Elixir script running on Heroku.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d7cda814daafbe4723da9b6128090192/href">https://medium.com/media/d7cda814daafbe4723da9b6128090192/href</a></iframe><p>I haven’t worked with files very much in Elixir so this was a fun exercise. I experimented with reading large files to see how far I could push it.</p><p>Here’s an example that takes a 300MB CSV file and just grabs the first 30 rows. It’s fun watching it run because it’s really fast and uses almost no memory because it only streams what it needs and then ends. There’s no need to download the whole file:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a6b5fb9707078d5857a241086e12d041/href">https://medium.com/media/a6b5fb9707078d5857a241086e12d041/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7aa0bb3f7468" width="1" height="1" alt=""><hr><p><a href="https://medium.com/agilion-product-development/decoding-a-hosted-csv-file-in-elixir-7aa0bb3f7468">Decoding a Hosted CSV file in Elixir</a> was originally published in <a href="https://medium.com/agilion-product-development">Agilion</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How much is outdated technology costing you?]]></title>
            <link>https://medium.com/agilion-product-development/several-years-ago-i-worked-for-a-company-that-did-not-value-technology-2c9b48159055?source=rss----43d505a72b65---4</link>
            <guid isPermaLink="false">https://medium.com/p/2c9b48159055</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Miriam Moser]]></dc:creator>
            <pubDate>Mon, 30 Jan 2017 17:57:25 GMT</pubDate>
            <atom:updated>2017-01-30T18:28:46.179Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>How much is outdated technology costing you?</strong></p><p>Several years ago I worked for a company that did not value technology. Employees worked on very old computers that processed everything slowly. I was shocked when I witnessed a coworker’s computer spend 15 seconds loading a web page. Her job was managing digital campaigns so she needed to be online all day. A slow computer was causing her to lose 15 minutes an hour. This comes to around 2 hours a day/8 hours a week/40 hours a month, which is the loss of a full week. Skimping on technological resources for employees was actually costing our company up to 25% of their employee payroll costs.</p><p>Slow computers are not the only thing that wastes employee time. Outdated workflows and tools waste employee time in quantifiable ways. Not only does a clunky tool take longer to use, it also creates lots of halting breaks for employees, interrupting their flow and leaving room for distractions. Outdated, labyrinthine processes not only cost time, they cause errors. Fortunately, the right tools and technology can solve these issues.</p><p>Agilion can help your business grow by simplifying your workflow and process. We build technology that enables your employees to maximize their time and minimize their frustration. Our intuitive custom software is detailed enough that employees can log in and see exactly what they need to do next, while also giving you a high-level view so you can keep an eye on trends, costs, and profitability.</p><p>Do you have outdated tools at your company? Have you ever tried calculating how much time just one employee wastes on these tools? If so, we can help. <a href="http://www.agilion.com/contact/">Contact us</a> if you are interested in learning more about how we do this.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c9b48159055" width="1" height="1" alt=""><hr><p><a href="https://medium.com/agilion-product-development/several-years-ago-i-worked-for-a-company-that-did-not-value-technology-2c9b48159055">How much is outdated technology costing you?</a> was originally published in <a href="https://medium.com/agilion-product-development">Agilion</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>