<?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[Parse.ly Engineering - Medium]]></title>
        <description><![CDATA[Posts from Parse.ly&#39;s fully remote engineering team. We&#39;re passionate about programming, data processing technologies, design, and user experience. - Medium]]></description>
        <link>https://medium.com/parse-ly-engineering?source=rss----3cf5297cc33---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Parse.ly Engineering - Medium</title>
            <link>https://medium.com/parse-ly-engineering?source=rss----3cf5297cc33---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 16:14:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/parse-ly-engineering" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Machine learning for news: the NLP engine behind Parse.ly Currents]]></title>
            <link>https://medium.com/parse-ly-engineering/machine-learning-for-news-the-nlp-engine-behind-parse-ly-currents-34df56cc81b6?source=rss----3cf5297cc33---4</link>
            <guid isPermaLink="false">https://medium.com/p/34df56cc81b6</guid>
            <category><![CDATA[naturallanguageprocessing]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[medium]]></category>
            <category><![CDATA[content-strategy]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Parse.ly Engineering]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 13:52:29 GMT</pubDate>
            <atom:updated>2019-03-27T13:57:37.684Z</atom:updated>
            <content:encoded><![CDATA[<p>Does Facebook control the news? Has Donald Trump hacked the media cycle? Are search algorithms creating filter bubbles? Is outrage the only currency on social networks? These questions, and many more, are top-of-mind for the citizens of the modern internet. But, do they have the concrete data to answer any of these questions? They didn’t, until today.</p><p>Today, we are launching <a href="https://currents.parsely.com/?utm_campaign=currents-ga&amp;utm_source=parselyblog&amp;utm_medium=post&amp;utm_content=currents-nlp-blog">Parse.ly Currents</a>, a new free product for understanding news, information, and attention flows online, at a detailed and quantitative level. For the first time in history, this information isn’t locked up in the data centers of big tech behemoths, but is instead openly and instantaneously available through a live dashboard, which you <a href="https://currents.parsely.com/?utm_campaign=currents-ga&amp;utm_source=parselyblog&amp;utm_medium=post&amp;utm_content=currents-nlp-blog">can access here</a>.</p><p>So, what is Currents, exactly? For years, Parse.ly has measured online attention through our market-leading real-time and historical analytics dashboard, <a href="https://parse.ly/analytics">Parse.ly Analytics</a>. We work with hundreds of media companies, tens of thousands of journalists and editors, and thousands of high-traffic sites and apps. We help them understand what content drives readership, engagement, sharing, and loyalty. Through this work, we have built up a petabyte-scale data set which includes billions of anonymous and aggregated news reading sessions. Atop this privacy-first data set, we have now built Currents, and made it available to the world.</p><p>To make sense of this data, we trained algorithms to parse hundreds of thousands of digital news articles per day into well-defined categories like Politics, Tech, and Business. Our algorithms also uncover millions of unique topics, like “Donald Trump” and “Elon Musk.” The data showcases not just what the content is about, but where the traffic came from — by platform, like Google vs Facebook vs Twitter vs Flipboard, and by geography, like East Coast vs Midwest states and cities.</p><p>Further, Currents automatically groups user attention into clusters of closely-related articles, which we call <strong>Stories</strong>. These “Stories” sound deceptively simple, but are actually a novel application of natural language processing technology. For this article, we’ll do a deep dive on how we built Stories into Currents, how they are implemented under the hood, and what it all means for future artificial intelligence applications in the space of online content and news.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*d2QCWJn-G8I2pLw3" /></figure><h3>When human intelligence and machine learning collide</h3><p>By combining the collective intelligence of billions of internet news readers with machine learning techniques applied to news and information articles, Parse.ly was able to bucket stories into topics and categories and group together articles with related storylines. Thanks to this, our system can understand sub-topics and sub-narratives.</p><p>To aid with the public’s understanding of online attention flow, Parse.ly’s dataset cuts across a number of platforms, and in so doing, acts as a check on each of them. Whereas engineers at Google have an insight into their daily web searchers, and engineers at Facebook has an insight into their daily newsfeed visitors, Parse.ly is the only company that has complete visibility <em>across all of the largest platforms, as well as the long tail of smaller sites and apps</em>.</p><p>We can compare the topics gaining momentum on Twitter today with the news that’s waning on Facebook, or the information very suddenly searched for on Google. We can see what political stories DrudgeReport is promoting, or not, and what lifestyle content is popular with lean-back weekend readers in aggregators like Flipboard and Google News. In short, this data is a kind of live poll of the internet and its interests.</p><p>Thanks to the our newfound understanding of the content itself via advanced natural language processing, we know this not just at the level of platforms, but even at the level of detailed topics, keywords, and real-world events.</p><p>Parse.ly’s attention analytics include not just what people search for, or what they share, but <em>what they actually read</em>. Not just what was published into the internet ether, with no indication of its popularity or level of engagement. But, instead, what was published <em>and read</em>, by <em>thousands</em> or even <em>millions</em> of people. That’s what Parse.ly can measure and reveal about internet content.</p><p>We believe this is a new category of internet attention understanding: not reading the tea leaves of search trends, nor wondering about the significance of social media monitoring, but instead <em>true internet listening</em> or <em>internet-wide attention analytics</em>.</p><h3>Automatic categorization into a content taxonomy</h3><p>Once we have all our data streaming in real-time and historically into a petabyte-scale warehouse where we can run arbitrary SQL queries, we can answer some interesting questions already. For example, we can rank all stories by unique visitors across the network. Or, discover stories gaining or losing steam in any given hour window. We can run these queries in seconds thanks to the warehouse’s massively parallel architecture. (Stay tuned for more about how we built this warehouse in a future blog post!)</p><p>But, we need interesting <em>dimensions</em> to aggregate/anonymize this traffic in a meaningful way. This is where Natural Language Processing (NLP) comes into the picture.</p><p>Our first approach here was to simply <em>classify</em> all of the content in our network into broad categories. For this, we used an existing content taxonomy published by the Internet Advertising Bureau, known as the <a href="https://www.iab.com/guidelines/iab-quality-assurance-guidelines-qag-taxonomy/">IAB Content Taxonomy</a>. A few off-the-shelf public cloud NLP APIs provide support for this taxonomy, including Google’s Natural Language API, but we found the need to take an alternative path for maximum quality against our news/article internet dataset. The end result is a system that can reliably classify content into broad categories such as Law, Gov’t, &amp; Politics; Business; Sports; and Health &amp; Fitness.</p><p>There are 80+ such broad categories, and a few hundred sub-categories, or “leaf categories,” in total. This does a great job of separating our content into a few logical areas that can then be further analyzed for better understanding using tuned language models.</p><h3>Topic extraction with the knowledge graph</h3><p>The next level of understanding is what we call a Topic, or what some NLP researchers may recognize more comfortably as an “Entity.”</p><p>The difference between a Topic and a Category is simple. A Category comes from a fixed taxonomy of content, and articles are placed into a category based on document classification rules. We try to place articles into very few categories. A Topic, meanwhile, refers to a specific person, place, thing, or concept that may appear in articles across every Category. The list of Topics is not fixed; it currently stands at millions of logical Topics, and tens of thousands in active use even in a 24-hour internet news cycle. “Elon Musk” and “Donald Trump” are Topics, but “Business” and “Politics” are categories.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wGDX2TIfIOiiuAEb" /></figure><p>To understand content about Elon Musk, our NLP engine makes use of a “knowledge graph.” This is an API with understanding of text not just from the standpoint of syntax and structure, but instead from the standpoint of actual meaning.</p><p>The most widely understood knowledge graph has been built up over years by the Wikipedia project, and its related projects, such as Wikidata. The idea here is that, in Wikipedia, we know that Elon Musk is not just a person, but also a well-known person, and one who is the CEO of several important companies, such as Tesla and SpaceX. Wikipedia has further information about Tesla and SpaceX, for example, it knows that Tesla sells products such as the Tesla Model 3 and that SpaceX is related to the aerospace and space travel industry. The kind of information you can learn about Elon Musk in this way, our NLP engine would think of as “traversing the knowledge graph”, jumping from node to node, in this case from “Elon Musk” to “Tesla” to “Model 3”.</p><p>Combined with a language model built up in code, we can reliably extract references to these important people, places, things, and concepts. So, we can tell that of the thousands of stories written about Elon Musk, some percentage are written about Elon Musk + Tesla, and some other percentage about Elon Musk + SpaceX. We can also start to learn that articles about Tesla tend to be “Business” articles, and articles about SpaceX tend to be “Science” articles. And so on.</p><p>All of these relationships are made plain and apparent in the Parse.ly Currents web interface, where you can type in any category or topic and instantly match to the ones that have traffic and content registered in our system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/968/0*JqIK4adaWlpajqnl.png" /></figure><h3>Clustering related stories with word vectors</h3><p>Perhaps the most novel and most recent NLP approach used in Parse.ly Currents powers our most impactful feature: Stories, which we refer to internally as “Story Clusters.” It builds on the NLP engine and time series engine described above, but goes even deeper on understanding, at a level one could truly call an artificial intelligence view of news and content.</p><p>To put it simply: a Story is a group of articles that are talking about the same thing.</p><p>They are distinguished by a few things:</p><ul><li>Rather than talking about specific topics (entities), they talk about specific events, which might include some number of topics. Traditional NLP can’t understand events. So, we have to approximate that using things that correlate with events that show up in language.</li><li>They cut across categories and topics of content.</li><li>They do not rely on any “learned” model or taxonomy of news events. It is entirely built up from word associations, and a statistical understanding of frequency of word/concept co-occurrence.</li></ul><p>So, what is an example of an “event”? Browsing Parse.ly Currents on September 9, I found that the top story cluster is labeled, “1. Serena Williams / US Open (tennis) / Naomi Osaka.” Here, the top 3 topics are used as the label — this cluster includes all the stories about the US Open tennis match between Serena Williams and Naomi Osaka. Two example headlines from this cluster:</p><ul><li>“Serena Williams To Umpire: ‘I Don’t Cheat To Win, I’d Rather Lose.’”</li><li>“It’s shameful what US Open did to Naomi Osaka.”</li></ul><p>There was a specific event: a tennis match between two tennis pros. There were 175 identified and verified articles in the Parse.ly network written about this event; our system automatically detected and grouped these into a Story. We labeled the cluster using the top Topics, which are the tennis players themselves, and the tournament in which they play. This all happens automatically based on the language and time series traffic understanding.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/0*5G26LbKsbFv9vG-J.png" /></figure><p>Speaking of that traffic understanding: we find that 1.7 million people read those 175 articles in a 24-hour period, an astounding 10,000+ clicks per article. For context, the average article in our network gets 169 clicks in the same period!</p><p>What we are discovering here is that Stories are <em>not</em> distinguished by topics. So, if you looked at the top topics of the day, you’d see “Donald Trump” every day. But the <em>reason</em> Trump is trending is different across different days. Trump has his fingers in anywhere between 1 and 5 stories each day. And there are many other topics that also do that like Elon Musk and Serena Williams.</p><p>If you ask people, “What’s in the news today?” that’s closer to what our “Stories” feature ends up modeling. Breaking the news down into narratives (storylines, clusters of attention) matches the way people actually think about the news cycle.</p><h3>Breaking down the concept of word vectors</h3><p>How are we able to do this so well and effectively with so little up-front training of our algorithms?</p><p>This is the power that comes from word vectors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/668/0*1ZQFEsXJ3GuwQkva" /></figure><p>Two words will have similar word vectors if they are distributed the same way in English text. That is, it doesn’t matter if two words <em>mean</em> the same thing; it is only important that they are semantically related, often by how they are used.</p><p>To give a stark example, Afghanistan and Iraq are latently semantically related in that they are both countries with which the US was embroiled in a long war. But they are not at all similar words, and the dictionary definition of these words (as countries) help us very little in understanding their common usage. This is where word vectors shine: by training off a large corpus of text, we can learn that Afghanistan and Iraq are “talked about” the same way, namely, in the context of war reporting or perhaps foreign policy. In this way the words are semantically linked, even if unrelated in both syntax and definition.</p><p>Our gateway to word vectors was to use <a href="https://fasttext.cc/">fastText</a>, an awesome open source library that provides a pre-trained model for text representation using these concepts.</p><h3>Improvements over word2vec</h3><p>The most popular word vector model in widespread use is <a href="https://en.wikipedia.org/wiki/Word2vec">word2vec</a>. So, why did we decide to use fastText?</p><p>Well, both word2vec and fastText are conceptually possible candidates for this model of understanding. At its core, word2vec did something very clever with neural networks. From a practical standpoint, it compressed the semantic relationships between words by using neural networks, and made it so that a very large corpus of text could be turned into a small, production-usable model. If you think about compression, it’s actually a kind of learning from data. In a way, it’s a smaller representation of data, where symbols in the compressed data represent patterns in the larger source data.</p><p>By contrast, fastText does not use a neural network, but instead uses a simpler algorithm that measures word co-occurrence. But it tried to preserve the properties that made word2vec so useful in production use. The key thing is that fastText is really optimized for speed. Plus, it’s language agnostic, as fastText bundles support for 200+ languages. These characteristics made it a perfect fit for the kind of global news and content understanding Parse.ly hopes to achieve over time.</p><h3>Clustering related articles with word mover distance</h3><p>Though word embeddings via fastText give us some level of understanding of articles at a more semantic level, we still need a way to consider two articles “closely related” on some metric. For this, we leverage a concept called “word movers distance,” with the rather unfortunate acronym of WMD.</p><p>The concept of WMD comes from something called “optimal transport” or “earth mover’s distance.”</p><p>The canonical problem goes something like this: let’s say you have a set of mines and a set of factories, and you are the manager in charge of ensuring efficient production. How do you place the factories to optimize the transport between mines and factories? It’s a kind of variant of the rather famous <a href="https://en.wikipedia.org/wiki/Travelling_salesman_problem">“traveling salesman”</a> problem in computer science.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/531/0*P1VkIHecLAHSAhFq" /></figure><p>In the case of words or language, we can reframe the question thusly: given an article A, how can we reposition the words in the article to be “closest” to the words in article B? The number of “semantic edits” required to transform article A to article B can be viewed as a measure of how related the two articles are. To take our earlier example, imagine article A is a piece of foreign policy analysis on the Bush years and the Iraq war, and article B is a foreign policy analysis of Obama’s handling of the Afghanistan war. We could ask the question, given a graph of word vectors and these two articles, what’s the shortest path I could take to transform article A to article B? I could change occurrences of “Iraq War” to “Afghanistan War”, and this wouldn’t move me <strong>too</strong> far in the vector space, since they are both American foreign wars (and recent ones, at that). I could change occurrences of “Bush” to “Obama”, and this also would not move me <strong>too</strong> far, since they are both US presidents, and recent ones. However, consider an article C which is a second article about the Bush Years and the Iraq War. In this case, transforming article A to C would take <strong>many fewer semantic moves</strong> than transforming article A to B. And now consider a fourth article, a recent article about the Serena Williams loss in the US Open. Well, this article, being totally unrelated, will take <strong>many more semantic moves</strong>, and thus its distance will be greater (and its relatedness lesser).</p><p>In this way, our NLP engine learns the relationships (or non-relationships) among articles in a completely unsupervised way, but in a way that models human understanding of news, information, and content quite accurately. We now cluster hundreds of thousands of such articles on a daily basis using this algorithm, and report the results in <a href="https://parse.ly/currents">Parse.ly Currents</a>.</p><p>In production, we generate Stories by doing the following:</p><ul><li>Check topic similarity using a simple information retrieval algorithm first. We use this to filter out topics to a smaller set of more “distinctive” ones, and give them a higher weight.</li><li>Calculate the distance between every article and every other article, in the semantic vector space offered by fastText. We take the intersection over the union. This helps us understand the total weight of the set of topics shared by the article over the total weight of topics across all articles.</li><li>Do some tuning/weighting to make the topics relevant, especially as labels for the Story.</li><li>Pick 1–3 relevant topics to label the cluster in a way that users will understand, e.g. “Serena Williams / US Open”.</li><li>Store the full set of articles in the cluster, their topics, and their categories.</li><li>Assign that cluster a unique identifier to allow it to acquire new articles over the course of a 24-hour period, and to allow Parse.ly to report on it with its traffic stats.</li></ul><h3>Putting it all together: Parse.ly Currents</h3><p>Our goal with developing Parse.ly Currents was to develop the world’s first transparent view of the ebb and flow of content and attention on the internet.</p><p>Making sense of petabyte-scale data, whether language or traffic data, is not easy. But, if you <a href="https://parse.ly/currents">sign up for Currents today </a>(it’s free!), making use of that data will seem very easy indeed. You can see all the Story Clusters trending today, which summarizes the day’s news, not from the standpoint of journalists and website operators, but from the standpoint of readers and engagement.</p><p>You can filter the traffic down to any source or platform, to understand what’s trending on Google News vs Twitter vs Reddit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/0*FrUDol7NgVt_wrqF" /></figure><p>By the way: Twitter makes up a small percentage of the traffic Parse.ly sees; 23M views out of 1.3B tracked views in this one-week period, or only 1.7%! Yet, entire industries seem to be focused on analysis of the chatter on Twitter. This is a good illustration of the bias that can stem from the lack of a cross-platform view of attention.</p><p>All of this data is available to you today, and queries across billions of data points will return to your browser within seconds.</p><p>We hope you’ve learned something from this detailed discussion how the NLP brain powering Currents does its thinking every day. We’d love to hear from you and how you’re using similar NLP technology in your own projects.</p><p>Or, <a href="https://currents.parsely.com/join?utm_campaign=currents-ga&amp;utm_source=parselyblog&amp;utm_medium=post&amp;utm_content=currents-nlp-blog">simply sign up</a> and tell us how you plan to get an edge from the Currents dataset. We’re eager to hear from you. We believe Parse.ly’s approach to NLP has advanced the state of the art for news understanding in the internet era, and we’re excited for this next chapter.</p><p>The two images in the post that referenced word vectors and embeddings (using example headlines related to President Obama) each came from the academic paper, “From Word Embeddings To Document Distances”, authored by Matt J. Kusner, Yu Sun, Nicholas I. Kolkin, and Kilian Q. Weinberger in 2015. The full paper PDF <a href="http://proceedings.mlr.press/v37/kusnerb15.pdf">is available here</a>.</p><p><em>Originally published at </em><a href="https://blog.parse.ly/post/7790/machine-learning-nlp-parse-ly-currents/"><em>blog.parse.ly</em></a><em> on September 24, 2018. It was written by Parse.ly’s co-founder and CTO </em><a href="https://medium.com/@amontalenti"><em>Andrew Montalenti</em></a><em> and Machine Learning Engineer Matthew Carrigan.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34df56cc81b6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parse-ly-engineering/machine-learning-for-news-the-nlp-engine-behind-parse-ly-currents-34df56cc81b6">Machine learning for news: the NLP engine behind Parse.ly Currents</a> was originally published in <a href="https://medium.com/parse-ly-engineering">Parse.ly Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Game of Thrones reigns supreme among AT&T’s assets.]]></title>
            <link>https://medium.com/parse-ly-engineering/game-of-thrones-reigns-supreme-among-at-ts-assets-c13252fd1c70?source=rss----3cf5297cc33---4</link>
            <guid isPermaLink="false">https://medium.com/p/c13252fd1c70</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[market-research-reports]]></category>
            <category><![CDATA[apple]]></category>
            <category><![CDATA[intelligence-services]]></category>
            <category><![CDATA[att]]></category>
            <dc:creator><![CDATA[Conrad Lee]]></dc:creator>
            <pubDate>Wed, 27 Mar 2019 13:44:23 GMT</pubDate>
            <atom:updated>2019-03-29T15:14:07.868Z</atom:updated>
            <content:encoded><![CDATA[<h3>Game of Thrones reigns supreme among AT&amp;T’s assets</h3><h3>Here’s how we used Wikidata’s entities and ontology to find that out.</h3><p>At Parse.ly, we measure how much attention content receives, and broadly speaking — it’s a lot. We directly track how many page views individual URLs receive from visitors. In the last three years we’ve tracked about 480 billion page views on about 250 million distinct pieces of content; most of this content consists of articles from leading U.S. and European publishers. That’s about 21 page views <em>from every human on earth</em> and 2 new articles <em>every second</em> for the last three years.</p><p>As part of our focus on measuring attention on content (e.g., news articles and blog posts), our system parses the full text of every piece of content in our dataset. We’ve built <a href="https://blog.parse.ly/post/7790/machine-learning-nlp-parse-ly-currents/">a system using Natural Language Processing</a> that automatically knows which people, companies, and products are mentioned on each URL.</p><p>In my role as Machine Learning Engineer, I’ve worked to enable anyone to view how any kind of entity is trending across all the content we track. This post goes over a subset of that work that focuses on identifying the assets within large companies that generate the most attention.</p><h3>The challenge: bringing together a large company’s most popular products and brands</h3><p>When we show people our <a href="http://currents.parsely.com/">Currents</a> dashboard, they often want to see how much attention a particular company receives, and why. Professionals in corporate communications, PR, and finance constantly need to understand the public’s reaction to a brand or product. This would allow them to see how people read directly about these companies on trusted websites (in an anonymized way), instead of relying on proxy signals like social media engagement.</p><p>For example, imagine you’re, say, Warren Buffet and you’re considering investing in a media/telecom behemoth. You’re baking AT&amp;T off vs Comcast. On the telecom side you can easily discover how many subscribers these companies <em>currently</em> have, because that’s publicly reported. But how do you value their media and entertainment brands and assets? E.g., how do you measure the value of brands like Superman (owned by DC Comics → Warner Bros. → WarnerMedia → AT&amp;T) or <em>Saturday Night Live</em> (owned by NBC Studios → NBCUniversal → Comcast)? Given that each of these companies owns thousands of these types of assets, how do you determine which ones are the most important?</p><p>What we really want is a way of comparing overall attention of AT&amp;T’s and Comcast’s brands, as well as a break-down of the most important brands/products that explains why one company is getting more attention than the other. In a world where Netflix is “<a href="https://www.marketwatch.com/story/netflix-thinks-fortnite-is-a-bigger-competitor-than-hbo-2019-01-17">competing with Fortnite</a>,” understanding what people pay attention to can map to where they decide how to spend their time, and dollars.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3KkidzRkoOKMGZMMsLjJA.png" /><figcaption>An inadequate view: page views on articles that mention ‘AT&amp;T’ or ‘Comcast’</figcaption></figure><p>Google Trends can show some intent data, but it can’t aggregate attention this way. While it’s our aim, so far our Currents product can’t either. Instead, these tools can only give us a chart like the one above. In the case of our data, it indicates how many times readers in our network read articles that featured either the company ‘Comcast’ or ‘AT&amp;T’.</p><p>This chart largely neglects the page views the company’s assets (brands, movies, T.V. shows) receive. The chart above really only tells us how much attention the top-level companies receive, either in their role as telecoms or public companies. The big spike in the end of 2017, for example, is caused by lawsuits surrounding AT&amp;T’s acquisition of Time Warner.</p><p>Now remember, you’re Warren Buffet still, and as Warren Buffet, you already know about that controversy, and know that it settled. What you really want to know is which media and entertainment assets are most valuable for these companies, and how attention to them is trending. You actually want the following plots, which shows how much attention AT&amp;T’s vs Comcast’s top assets and brands have received over a three year period:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7XdD-v_o9a94EE7nMMDuzg.png" /><figcaption>Page views on AT&amp;T’s top assets and brands</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G9geF34nCWiIL16F" /><figcaption>Page views on Comcast’s top assets and brands</figcaption></figure><p>To generate the charts above, I didn’t just select some arbitrary assets that belong to each company and plot them out together. I used an ontology to catalog <em>all</em> of the major assets belonging to each company, and sorted them by the number of page views they received. Before looking at these charts I had no idea that Game of Thrones was AT&amp;T’s most read-about entertainment asset (makes sense in hindsight though), and I didn’t know that AT&amp;T’s entertainment portfolio is stronger than Comcast’s, in terms of media coverage and people reading about it.</p><p>The charts above can provide investors and other professionals with insights that internal company data can’t provide: by this measure, AT&amp;T has a stronger portfolio of entertainment assets, especially via Game of Thrones and the DC comics brand.</p><p>A savvy investor would treat these lists as the starting point for a larger investigation, and look into the health of each of the top few dozen assets for each company. This investigation would reveal that Comcast’s Friends has been licensed by Netflix for (rumor has it) $100m — the investor should then ensure that the amount of attention being paid to Friends is not waning.</p><p>So, Warren, how do these charts affect your valuations of Comcast vs AT&amp;T?</p><p>Creating the charts above in an automated fashion is a hard problem for huge companies with byzantine, hierarchical structures like Comcast and AT&amp;T. In the rest of this post I’ll go over how I did it.</p><h3>The role of Wikidata: not only a set of entities to link to, but also an ontology</h3><p>When we run natural language processing algorithms over the full text of our content, one of the key things we extract is the list of entities (people, places, products, companies, idea, etcs) that are mentioned in that piece of content. This task is known as <a href="https://en.wikipedia.org/wiki/Entity_linking">entity linking</a>, and at a high level the goal is to extract nouns of interest and link them to a set of known entities.</p><p>The set of entities we use comes from Wikidata, a project closely linked with Wikipedia. Thus, the kinds of entities we can detect in our content are the kinds of things that have Wikipedia pages written about them. Basically, the entity linking algorithm takes the content’s full text as input, and, where possible, annotates each noun with a wikidata_id and a relevance score. We keep only those entities that have high relevance to the article at hand.</p><p>Linking entities to Wikidata is ideal for our purposes because it includes a disambiguated set of nearly all entities that are news worthy. However, there’s an added benefit — Wikidata is actually an <em>ontology.</em> An ontology can be thought of as a database of rich statements about how entities are related to each other. For example, if you visit <a href="https://www.wikidata.org/wiki/Q23572">the wikidata page</a> for Game of Thrones, you’ll see it contains statements establishing that ‘HBO is the original network of Game of Thrones’, and that ‘HBO is the production company of Game of Thrones’.</p><p>These statements also contain relationships about products:</p><ul><li>Foxconn manufactures the iPhone X</li><li>Apple designed the iPhone X</li><li>Random House publishes <em>The Cat in the Hat</em></li></ul><p>Thus, we can use Wikidata to link products/assets/brands with the companies that own then: we can attribute page views on Game of Thrones to HBO.</p><p>But that’s not quite good enough: how do we attribute that attention all the way back up to AT&amp;T? It turns out we can use Wikidata for this task as well: we just query it for parent/subsidiary relationships between companies. The result of such a query gives us a list of directed edges i→j, indicating that company j is a subsidiary of i.</p><p>If we connect all these edges, we’re left with a graph (i.e., a network) of public companies and subsidiaries. Ideally we’d have a separate, disconnected component for each public company, where each component contains a single parent company and a clearly directed hierarchical ownership structure. However, as is often the case with crowd-sourced data, the data contains some noise/garbage. Instead of neatly separated companies, in many cases different companies are connected to each other. In the worst such case — the giant connected component — we’re left with a hairball that I call the ‘monster’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*tDc7RrYAOHlsRW0C3SjX5Q.png" /><figcaption>The monster. Scary, indeed.</figcaption></figure><p>Zooming in on the monster, we see that it consists of communications, media, and entertainment companies. The central section of the monster features AT&amp;T at its center, connected to CBS, Vivendi, Sony, Viacom, and Orange. In the further periphery of the monster we find various oil and manufacturing conglomerates.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AYCzCDLIOFndBt1yCmBF8g.png" /><figcaption>Still a beast.</figcaption></figure><p>The existence of such a monstrous clump of companies connected together in the Wikidata ontology is problematic for two reasons:</p><ul><li>There are some companies that have multiple owners, and in such cases it can be unclear which public company attention should be attributed to.</li><li>The existence of <em>cycles</em> in this graph is even more problematic: cycles occur when one can follow ownership relationships around in a circle. Circular ownership schemes may exist in some private companies, but we don’t expect to see them in public companies.</li></ul><h3>Taming the monster by cutting it up</h3><p>It turns out that only a few stray edges in the monster prevent us from attaining this ideal situation. After looking into a a dozen or so of these stray edges, I found that they most referred to obsolete ownership relationships that was invalidated either by a subsequent merger or acquisition, or by a company simply being disbanded.</p><p>The good news is that Wikidata includes way of qualifying an ownership relationship so that it’s only valid for a particular interval of time. For example, here’s a list of statement showing who owns TriStar Pictures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/587/1*QDAbjAg475M2epULp0q6Ag.png" /></figure><p>Notice the <em>end time</em> qualifiers on the statements showing that CBS and Columbia Pictures own Tristar. If these were missing, then TriStar would appear to have three different owners, which is problematic.</p><p>After visualizing and examining this ‘monster component’ it became clear to me that I could fix the problem of stray edges by simply correcting Wikidata myself by hand. Stray edges are a problem, but they’re a rare problem — with visualization I could easily identify where the stray edges were, and with network analysis software (I use <a href="https://networkx.github.io/">NetworkX</a>) I could automatically identify cycles.</p><p>Using these two techniques to single out the problematic edges, it was a simple matter of reading the Wikipedia pages to figure out how I could correct the problems — for example figuring out when companies were sold to each other so that I could manually add the relevant ‘end time’ qualifiers to Wikidata.</p><p>After updating a few dozen obsolete parent/subsidiary relationships, I would regenerate the company ownership graph, revisualize it, and once again look for the most egregious stray edges. After several rounds of this, the monster component fell apart into several different cleanly separated companies, and I moved on the the next-largest component (a mess of energy and engineering companies), and broke that up.</p><p>You can view <a href="https://www.wikidata.org/wiki/Special:Contributions/Conradl">my wikidata contributions page</a> to get a sense of the edits I made — all in all I guess I made a couple hundred (I made half of them while accidentally logged out of Wikidata so they don’t appear under my contributions). It was tedious work that took about eight hours, but, given the wealth of information that Wikidata provided me, I was happy to contribute something back in return.</p><p>After carrying out these corrections, it was possible to much more cleanly visualize a company like AT&amp;T:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*IgpwFdv-pXj6GN-3hgYUbA.png" /><figcaption>A monster tamed: finally, a clean view of AT&amp;T and its subsidiaries</figcaption></figure><p>With this hierarchical structure in place, I could now cleanly associate subsidiary companies in Wikidata with their parent public companies. While a crowd-sourced dataset like this is never perfect, with just the minor corrections I made it was good enough to to perform meaningful analysis of how much attention public companies receive.</p><h3>Tying it all together into an automated process</h3><p>The goal we set out to achieve above was to make it possible to track the overall attention that any large company’s products and brands receive. I’ve gone over how Wikidata allows us to carry out two key tasks necessary for achieving that goal. First, Wikidata gives us a clean, disambiguated, and large set of entities that we can link words in articles to. Second, Wikidata’s ontology allows us to determine which companies own which products and resolve parent-subsidiary relationships.</p><p>With that data in hand, I can create the following revealing charts with just a few SQL joins, like these ones comparing attention for the top iPhone and Samsung Galaxy models over the last three years:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h_5vjtLdBvP74DHD" /><figcaption>Page views on Apple’s top phone models</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qyq1IoWrWk15H_Ro" /><figcaption>Page views on Samsung Electronics’ top phone models</figcaption></figure><h3>Future work: Adding positive or negative sentiment</h3><p>There is a lot to say about the charts above, because each large spike corresponds to some kind of event, launch, or problem. In the first chart, you can see that the most recent iPhone launch event attracted much less attention than the previous two. The second chart reveals that Samsung Electronic’s largest spike of attention corresponds to late 2016. This spike was caused by the notorious Samsung Galaxy Note 7, which was plagued by battery combustion problems. The phone caused fires, was banned on flights, and eventually recalled. Thus, not all attention is good attention.</p><p>We saw the same thing in the earlier charts above for AT&amp;T and Comcast — the large yellow spikes in AT&amp;T’s chart represent something positive: on the days where new Game of Thrones episodes aired, masses of people want to read about it. The huge spike in the bottom chart, on the on the other hand, represents something negative: Matt Lauer being fired by NBC due to allegations of sexual misconduct. There’s a lot more to say about these charts (and all the other one’s we’ve generated), but I’ll have to save that for a future post.</p><p>In conclusion, a word on what we’re working on now. We’ve recently started training language models based on recent deep learning breakthroughs in NLP to automatically classify an article as providing positive or negative sentiment towards companies. So far, this approach has produced promising results, and allows us to cleanly separate positive attention from negative attention — subscribe to the blog to get updates on our progress.</p><p><em>Originally published at </em><a href="https://blog.parse.ly/post/8414/among-atts-entertainment-assets-game-of-thrones-gets-the-most-attention-heres-we-used-wikidatas-entities-and-ontology-to-find-that-out/"><em>blog.parse.ly</em></a><em> on March 26, 2019.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c13252fd1c70" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parse-ly-engineering/game-of-thrones-reigns-supreme-among-at-ts-assets-c13252fd1c70">Game of Thrones reigns supreme among AT&amp;T’s assets.</a> was originally published in <a href="https://medium.com/parse-ly-engineering">Parse.ly Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What are the most confusing software development topics?]]></title>
            <link>https://medium.com/parse-ly-engineering/what-are-the-most-confusing-software-development-topics-df7ef1d72845?source=rss----3cf5297cc33---4</link>
            <guid isPermaLink="false">https://medium.com/p/df7ef1d72845</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[bigquery]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[stackoverflow]]></category>
            <dc:creator><![CDATA[Irina Truong]]></dc:creator>
            <pubDate>Tue, 31 Jul 2018 19:28:33 GMT</pubDate>
            <atom:updated>2018-07-31T19:27:37.558Z</atom:updated>
            <content:encoded><![CDATA[<h4>…or Take some StackOverflow and add a pinch of BigQuery</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*ol5uzrUD9Rraq0yGu4O7JQ.gif" /><figcaption>Struggling? Image source: <a href="http://mlp.wikia.com/wiki/File:FANMADE_Twilight_facedesk.gif">http://mlp.wikia.com/wiki/File:FANMADE_Twilight_facedesk.gif</a></figcaption></figure><p>StackOverflow question and answer data has been available <a href="https://cloud.google.com/bigquery/public-data/stackoverflow">as a public dataset on Google BigQuery</a> for quite a while. I read about it some time ago, and promptly forgot — until recently, when struggling with something at work, I had a thought: “Is it really that hard? Do other people struggle with the same thing?”</p><p>And then I thought, this dataset could provide an answer!</p><p>The dataset contains around 20 tables, but the relevant one here is the table of <strong>post_questions</strong>, with the field <strong>answer_count</strong> in it. Each row also contains <strong>tags</strong>, a pipe-separated string of tags that I will call <strong>software development topics</strong>.</p><p>Here is a query to return the number of answered and unanswered questions in every topic (<strong>tag</strong>). The data is sorted by the number of unanswered questions, in reverse order, then it is limited to the top 1000 records.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/623491b0034755b8460ba26e5f14fbfd/href">https://medium.com/media/623491b0034755b8460ba26e5f14fbfd/href</a></iframe><p>That magic with <strong>split(tags)</strong> and then <strong>unnest(tags)</strong> is there because we want to flatten the array of tags and see a separate record for every individual tag instead.</p><p>Once I had this data, I exported it in <strong>csv</strong> format and uploaded to Google Spreadsheets, for further exploration. I also added a new column, <strong>percent_unanswered</strong>, with values equal to <strong>(100 * unanswered) / total.</strong></p><p>Here is a subset of the top 20 records returned by the query:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ae8a77eec22ddf9008ed08e358570550/href">https://medium.com/media/ae8a77eec22ddf9008ed08e358570550/href</a></iframe><p>Here is a chart of the same:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*XZiesLKx-UtCOc5sA4Ztag.png" /></figure><p>Original at plot.ly: <a href="https://plot.ly/~itruong/2/">https://plot.ly/~itruong/2/</a>.</p><p>My first line of reasoning was that, surely if the topic generates a lot of unanswered questions, it must be very confusing? As we can see, <strong>javascript</strong>, <strong>android</strong>, <strong>java</strong>, <strong>php</strong> and <strong>c#</strong> generate the most unanswered questions. Then, are they the most confusing? I agree, modern javascript is intimidating (if you don’t believe me, read <a href="https://hackernoon.com/how-it-feels-to-learn-javascript-in-2016-d3a717dd577f#.z96rcx614">this</a>), but C# or Java… maybe not so much?</p><p>So perhaps those topics are something wildly popular that a lot of beginners take up. For the next attempt, let’s sort the dataset by the percentage of unanswered questions in total questions asked. If nobody can answer a high percentage of questions on the topic, surely they must be difficult questions? Here is another chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSDPYG24uvIFFeVz7ZSMEg.png" /></figure><p>Original at plot.ly: <a href="https://plot.ly/~itruong/7/">https://plot.ly/~itruong/7/</a>.</p><p>Topics that have the biggest percentage of unanswered questions: <strong>magento-1.9</strong>, <strong>jupiter-notebook</strong>, <strong>jsf-2.2</strong>, <strong>cordova-plugins</strong>, <strong>internet-explorer-11</strong>. Now, this looks as though we hit the other end of the spectrum: topics that are too specific or too obscure, so there are not enough experts to answer the questions.</p><p>Let’s try combining the two approaches, and sort the dataset by the number of unanswered questions again, but also apply a filter to only see the topics where 20% or more questions went unanswered:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dd010fcf1207f17dfaaf0bde9b746337/href">https://medium.com/media/dd010fcf1207f17dfaaf0bde9b746337/href</a></iframe><p>And a chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jm9DKK3rqtRyn4hFvx4naQ.png" /></figure><p>Original at plot.ly: <a href="https://plot.ly/~itruong/8/">https://plot.ly/~itruong/8/</a>.</p><p>Those must be <strong>very</strong> confusing, right? They generate a lot of questions, and nobody can answer a fair chunk of those questions. Leading the pack are <strong>facebook</strong>, <strong>cordova</strong>, <strong>google-chrome</strong>, <strong>android-studio</strong>, and <strong>opencv</strong>.</p><p>And look! The issue that I was struggling with belongs to the topic in this top 20 as well! (It was Apache Spark, at 15th position, and generating 24,460 questions, out of which 25% went unanswered).</p><p>Let’s combine the two approaches in a different way: sort the topics by the percentage of unanswered questions, and apply a filter to only see the topics that generated more than the 3rd quartile (75th percentile) of the number of unanswered questions. The 75th percentile here is <strong>2806</strong>. Here is the new top 20:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f641a47a844583c4f041601cc80e026/href">https://medium.com/media/7f641a47a844583c4f041601cc80e026/href</a></iframe><p>And a chart:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0XhvmbLsviN4AsbPKSx2Kw.png" /></figure><p>Original at plot.ly: <a href="https://plot.ly/~itruong/25/">https://plot.ly/~itruong/25/</a>.</p><p>Similar but different! Here, we have <strong>webpack</strong>, <strong>woocommerce</strong>, <strong>ionic-framework</strong>, <strong>visual-studio-2015</strong>, and <strong>server</strong> as the leaders. Incidentally, my old friend, <strong>apache-spark</strong>, landed on position 15 again. I would call the former top 20 “<strong>The topics confusing to the biggest number of developers</strong>”, and the latter top 20 “<strong>The topics confusing to, or experiencing the lack of experts</strong>”.</p><p>I feel slightly better now, knowing that almost 25K people had a problem with my topic that was difficult enough to make them go to StackOverflow and ask a question, and not a single expert was sufficiently knowledgeable to answer almost 6K of those.</p><p>Google BigQuery lets you process 1Tb of data per month for free. So if you’re interested, they have many <a href="https://cloud.google.com/bigquery/public-data/">public datasets</a>, and perhaps those can help you answer your burning questions.</p><p>Curiosity killed the cat, but it may actually be beneficial to us humans.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df7ef1d72845" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parse-ly-engineering/what-are-the-most-confusing-software-development-topics-df7ef1d72845">What are the most confusing software development topics?</a> was originally published in <a href="https://medium.com/parse-ly-engineering">Parse.ly Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[This Team Used Apache Cassandra… You Won’t Believe What Happened Next]]></title>
            <link>https://medium.com/parse-ly-engineering/this-team-used-apache-cassandra-you-wont-believe-what-happened-next-16c825143acf?source=rss----3cf5297cc33---4</link>
            <guid isPermaLink="false">https://medium.com/p/16c825143acf</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[apache-cassandra]]></category>
            <dc:creator><![CDATA[Parse.ly Engineering]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 15:53:28 GMT</pubDate>
            <atom:updated>2018-07-24T15:53:53.318Z</atom:updated>
            <content:encoded><![CDATA[<p>You know that old saying, “If it seems too good to be true, it probably is?” We technologists should probably apply that saying to database vendor claims pretty regularly.</p><p>In the summer of 2014, the Parse.ly team finally kicked the tires on Apache Cassandra. I say “finally”, because after years of using other distributed database technologies on our real-time analytics problems, I was tired of hearing from technologists — even ones on my own team — saying that our problem domain was “so obviously a fit for Cassandra”, that I figured we should at least entertain the notion.</p><p>After all, Cassandra is a highly-available, linearly-scalable data store. It is supposedly battle-tested at Facebook, Apple, and Netflix scale. It is supposedly the key to Netflix’s horizontal and elastic scalability in the AWS cloud. It is supposedly built to let your ops staff sleep easily at night, handling relentless write volumes of hundreds of thousands per second with ease and grace. It supposedly has an unassailable reliability model that lets you pull the plug on nodes without intervention, thanks to cluster auto-healing. And here’s the kicker — it’s supposedly optimized for Parse.ly’s data set: analytics data, and especially for time series data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*YChjQzY3yFFqyh-F" /></figure><p>That’s a lot of “supposedly’s!”</p><p>What we learned over the course of the next 6 months really, really surprised us. I think it’ll surprise you, too. We learned that Cassandra, though a very cool technology, is not a panacea for real-time analytics or time series problems. We also learned that the technology is loaded with traps that require deep knowledge of Cassandra internals to work around.</p><p>We also find the technology to very much violate the “principle of least surprise” — indeed, almost every Cassandra feature has some surprising behavior.</p><p>The rest of this article explores these surprises through the use of fun “Internet news style headlines” followed by a short explanation of the problem. We hope it helps other teams use Cassandra with more confidence and fewer battle scars.</p><p>Here’s a preview of the headlines:</p><ul><li><a href="https://blog.parse.ly/post/1928/cass/#cql-not-sql">INDUSTRY SHOCKER: CQL is not SQL</a></li><li><a href="https://blog.parse.ly/post/1928/cass/#compact-storage">We Didn’t Use COMPACT STORAGE… You Won’t Believe What Happened Next</a></li><li><a href="https://blog.parse.ly/post/1928/cass/#xsv">REVEALED: \x01 Separators Are Not The Ugly Hack They Appear To Be</a></li><li><a href="https://blog.parse.ly/post/1928/cass/#counters">Evil Cassandra Counters: They Still Hate Us! (Even in 2.1.x)</a></li><li><a href="https://blog.parse.ly/post/1928/cass/#row-size">Check Your Row Size: Too Wide, Too Narrow, or Just Right?</a></li><li><a href="https://blog.parse.ly/post/1928/cass/#the-dress">“The Dress” Breaks the Internet — and, Our Database</a></li><li><a href="https://blog.parse.ly/post/1928/cass/#dragons">For Future Travelers: Here By Dragons!</a></li><li><a href="https://blog.parse.ly/post/1928/cass/#living">Postscript: Living with Cassandra</a></li></ul><h3>INDUSTRY SHOCKER: CQL is not SQL</h3><p>Our team had studied Cassandra before the project had introduced CQL, the “Cassandra Query Language”, and the 2.x line of Cassandra releases. You would be wise to study Cassandra’s history before diving into CQL, because CQL has nothing to do with SQL, and any relationship will only lead you to surprises.</p><p>You see, in Cassandra 1.x, the data model is centered around what Cassandra calls “column families”. A column family contains rows, which are identified by a row key. The row key is what you need to fetch the data from the row. The row can then have one or more columns, each of which has a name, value, and timestamp. (A value is also called a “cell”). Cassandra’s data model flexibility comes from the following facts:</p><ul><li>column names are defined per-row</li><li>rows can be “wide” — that is, have hundreds, thousands, or even millions of columns</li><li>columns can be sorted, and ranges of ordered columns can be selected efficiently using “slices”</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/0*bb0TiGHs6cOr3c5C" /></figure><p>Cassandra’s data partitioning scheme comes from ensuring sharding and replication occurs on a row key basis. That is, ranges of row keys will establish cluster “shards”, and rows will be automatically replicated among cluster nodes.</p><p>Notice that I haven’t mentioned CQL yet. That’s because, CQL tries to hide every detail I described above from you, even though this knowledge is <em>critical</em> to running a Cassandra cluster. In CQL and Cassandra 2.x, column families are renamed to “tables”. Row keys become “primary keys” on those tables. A syntax that looks like a restricted subset of SQL (SELECT, INSERT, CREATE TABLE) offers a facade on these Cassandra facilities, but with none of the underlying SQL machinations.</p><p>The fact that rows can be wide or narrow falls out of how you design your CQL schema and how you use the resultant “tables” (that is, column families). We will discuss wide vs skinny rows later, so I’ll get there.</p><p>Here’s the core warning: CQL is SQL in the same way JavaScript is Java. (That is, it’s <strong>not</strong>.)</p><p>JavaScript was designed to look somewhat “Java-like”, because Java was trendy and well-understood by technologists when JavaScript was designed. But JavaScript is not Java. In fact, JavaScript, in all respects other than a superficial set of syntax similarities, couldn’t be more different than Java if it tried.</p><p>CQL was designed to look somewhat “SQL-like”, because SQL is trendy and well-understood by technologists today. But the relationship with SQL is the same: in all respects other than the superficial, it is a completely different beast.</p><p>I hope this warning helps. It will definitely help you interpret the following statement that is in Apache Cassandra’s Github README: “The Cassandra Query Language (CQL) is a close relative of SQL.” This is a false statement. You should ignore it. It’s more like a distant cousin — who later finds out she was actually adopted by her parents.</p><p>The way I read this line in the README is that the developers are excited, because CQL does actually make Cassandra easier to use. It does something important for the community: it unifies the client libraries around a single way of interacting with the database, like SQL did for many SQL databases. This is A Good Thing, but it doesn’t mean that CQL is anything like SQL.</p><p>There’s more to learn, so let’s keep going.</p><h3>We Didn’t Use COMPACT STORAGE… You Won’t Believe What Happened Next</h3><p>OK, so I cheated and re-used the headline format of this blog post itself, but I couldn’t resist. It just fit so well.</p><p>What’s COMPACT STORAGE, you ask?</p><p>Well, along with Cassandra 2.0 and CQL, the Cassandra project introduced some more capabilities that are built directly into CQL’s schema modeling capabilities. It tried to codify patterns from the community, specifically, ways of storing maps, lists, and sets of data inside a Cassandra row.</p><p>A Cassandra row is already sort of like an ordered map, where each column is a key in the map; so, storing maps/lists/sets in a Cassandra row is like storing maps/lists/sets inside an ordered map. This is an admirable goal, since it does provide some data modeling flexibility. Cassandra calls these CQL Collections, and, like sirens singing beautiful hymns off a sun-kissed shoreline, they seem very attractive.</p><p>CQL Collections required some enforced structure onto the rows that are stored in column families. This structure allows a mixture of map fields, list fields, and set fields to exist within a single logical table (remember: table = column family). Under the hood, Cassandra only knows about keys, column names, and values. So, this structure is built up by smartly inserting “marker columns” and embedding concatenated key names into column names appropriately. Imagine if in Python, rather than storing a dict in a dict, you needed to store the sub-dict keys inside the parent dict’s keys.</p><pre># &quot;embedding&quot; of unstructured data points = { &quot;point1&quot;: {&quot;x&quot;: 12, &quot;y&quot;: 10}, &quot;point2&quot;: {&quot;x&quot;: 8: &quot;y&quot;: 3}, # ... and so on ... } # vs &quot;encoding&quot; of unstructured data points = { &quot;point1::&quot;: &quot;dict&quot; &quot;point1::x&quot;: 12, &quot;point1::y&quot;: 10, &quot;point2::&quot;: &quot;dict&quot; &quot;point2::x&quot;: 8, &quot;point2::y&quot;: 3, # ... and so on ... }</pre><p>CQL Collections don’t really “embed” structure into cells, so much as they “encode” structure into columns. The cost of all of this structure: data storage on disk.</p><p>To be fair, Cassandra operates with the assumption that “disk is cheap”, but in a simple example we had at Parse.ly where we attempted to use a CQL Map to store analytics data, we saw 30X data size overhead vs using a simpler storage format and Cassandra’s old storage format, now called COMPACT STORAGE. Ah, that’s where the name comes from: COMPACT, as in small, lightweight. Put another way, Cassandra and CQL’s new default storage format is NOT COMPACT, that is, large and heavyweight.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*SjvQJEmOmkHl8hvG" /></figure><p>Now, the whole reason we were adopting Cassandra in the first place is because we have huge datasets. Terabytes upon terabytes of raw analytics and event data. Suffering a 30X data overhead for storage (and that’s even after compression) is not a trivial matter. We were actually hoping that Cassandra could store things <strong>more compactly</strong> than our raw data, but this wasn’t happening, due to the overhead of CQL Collections and the CQL 3.0 row format.</p><p>So, we did what any team that enjoys practicality over purity would do. We scrapped our hopes of using the “new shiny” and stuck with the appropriately-named COMPACT STORAGE. Though the Cassandra documentation is full of warnings about how COMPACT STORAGE is only for backwards-compatibility with CQL 2.0 and that this restricts your use of the more advanced features, what we found is that the cost of those features simply did not make sense at large data scale.</p><p>This team didn’t use COMPACT STORAGE, and the result was they got storage that wasn’t compact!</p><h3>REVEALED: \x01 Separators Are Not The Ugly Hack They Appear To Be</h3><p>Speaking of compact vs non-compact storage types, if we aren’t able to use Cassandra CQL 3.0 and CQL Maps to store unstructured data in Cassandra, how do we pull it off?</p><p>We decided to pick an extremely simple separated-value storage format for every analytics event, each of which goes into a column that is named with that analytics event identifier and timestamp. We lovingly labeled this scheme “xsv”, because the separator we chose to use is the Unicode escape character, \x01.</p><p>So, for example, in storing a visit to a specific URL from Twitter, we might store values like this:</p><pre>name=d, ts=2015-02-01T08:00:01.123Z:: http://site.com/url1x01http://t.co/1234 name=d, ts=2015-02-01T08:00:05.832Z:: <a href="http://site.com/url2x01http://t.co/1235">http://site.com/url2x01http://t.co/1235</a></pre><p>The way to read the xsv values is to imagine them being unpacked by Python that looks like this:</p><pre>&gt;&gt;&gt; url, urlref = xsv_parse(line) &gt;&gt;&gt; url &quot;http://site.com/url1&quot; &gt;&gt;&gt; urlref &quot;http://t.co/1234&quot;</pre><p>In other words, the keys for these separated values are not stored in Cassandra itself; instead, they are stored in our serialization/deserialization code.</p><p>This seems like a terribly ugly hack, but it’s actually really not.</p><p>The \x01 value shows up in a different color in Cassandra’s CQL shell, cqlsh. It is easy to split and serialize. It doesn’t require quoting of values, like traditional CSV would (because, every byte counts!). Of course, you need to worry about \x01’s showing up in your raw data, but you can escape these, and they are quite rare.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/0*kBWUO5dDwxM6rVf_" /></figure><p>The downside is that the schema stored in each row is not “self-describing”, as it might be with CQL Maps. But, the storage savings are so tremendous that we can live with that. And, since we use a consistent order, we can “grow” our schema over time by simply appending new values on the right side of the serialization form.</p><p>Here’s the other amazing thing. The client performance of these xsv values is much, much better than the CQL Collections equivalent, and even better than a schema we tried where we actually modeled every field directly in the CQL schema. Why? Because the client would spend most of its time decoding the “structure” of the row, rather than decoding the actual values, in both of those cases.</p><p>I know what you’re thinking — why not use something like Avro or Protocol Buffers? We considered this, but felt that this would make Cassandra’s data storage a bit too inscrutable. You wouldn’t be able to meaningfully use the CQL shell — thus eliminating one of the main benefits of CQL. We were willing to throw out CQL 3.0 and CQL Collections, but not the entire idea of having a usable CQL shell!</p><p>We also did some calculations and found that xsv performed similarly for our data set, anyway — since most of our values are strings, the binary serialization approach doesn’t actually help much.</p><p>So, to store large gobs of unstructured data in Cassandra, we recommend COMPACT STORAGE with serialized values in an “xsv” format. They are more storage-efficient and more CPU- and I/O-efficient. Go figure! It smokes all the “official” ways of modeling unstructured data in Cassandra.</p><p>That means our team’s advice is to ignore all the advice against using COMPACT STORAGE in the docs, and ignore all the fancy new CQL 3 stuff. Pretty weird — but, unlike the marketed features, this scheme actually works!</p><h3>Evil Cassandra Counters: They Still Hate Us! (Even in 2.1.x)</h3><p>Oh, my. I was dreading this section. I got burned badly by Cassandra Counters.</p><p>I shudder even now to think about the six-or-so weeks of development time I lost trying to make Counters work for our use case.</p><p>If you watch a lot of Cassandra presentations online, you’ll hear different things about Counters from different people. Cassandra old-timers will say things like, “Counters are evil”, “Counters are a hack”, “Counters barely work”, “Counters are dangerous, “Never, ever use Counters…” — you get the idea.</p><p>When I’m in a good mood, I sometimes ask questions about Counters in the Cassandra IRC channel, and if I’m lucky, long-time developers don’t laugh me out of the room. Sometimes, they just call me a “brave soul”.</p><p>In Cassandra 2.x, things are more hopeful. Counters received several sprints of development and the feature was starting to be better understood. First, a bunch of fixes in 2.0.x that made Counters more reliable. Then, a whole new Counters implementation in 2.1.x that improved their performance, especially under contention.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/0*GD8t90SAg5704cCo" /></figure><p>The reason Counters are so controversial and weird in the Cassandra community is because they seem to be at odds with Cassandra’s philosophy. Cassandra is meant to be a data store built on principles of immutability and idempotence. Incrementing a counter is a non-idempotent operation that seems to require an inherently mutable data store (like Redis or MongoDB).</p><p>Cassandra works around this by implementing Counter increments as “read-then-write” operation, similar to another Cassandra trap feature, Light-Weight Transactions (LWT). The implementation is clever and it works, but it does not have the same performance as plain Cassandra row/column INSERT’s, for which it is optimized.</p><p>Now, even if you can live with Cassandra’s different performance characteristics for Counters, you’ll discover other oddities. For example, column families that use counters have to live on their own, because the underlying storage is different. Counters can’t really be deleted — unless the delete is “definitive”, and even, then, there seem to be weird cluster bugs that surface with counter deletes. Related to counters not being deletable, you also learn that Cassandra’s time-to-live (TTL) features for data expiration simply do not work on Counters.</p><p>Finally, you’ll find that by opting into Counters, you threw out the baby with the bathwater — yes, you got a convenient durable data structure for storing counts, but you lost all the benefits of having an idempotent data store. This matters in analytics use cases, although we didn’t realize quite how much it mattered until we were well into it.</p><p>All of this is to say: Cassandra Counters — it’s a trap! Run!</p><p>Even in 2.1.x, when many of Cassandra Counters problems were fixed, we still find it’s a trap. Since we didn’t need Counters, we also decided to roll back to the “more stable” Cassandra line, 2.0.x. It still supports CQL, but has been in production longer, and is maintained as a parallel stable branch to 2.1.x.</p><h3>Check Your Row Size: Too Wide, Too Narrow, or Just Right?</h3><p>Remember when I mentioned how in Cassandra’s underlying data model, the row key determines how the system distributes your data?</p><p>It turns out, the most important data model challenge for Cassandra users is controlling your row size. In the same way a fashion magazine ebbs and flows on what the right waist size is for men and women, Cassandra ebbs and flows on the question of what the right row size is.</p><p>The short answer, that will be frustrating, is that you want your rows to be neither too wide, nor too narrow — but, just right. This is frustrating because you have no rules of thumb to go by. Cassandra theoretically supports rows with 2 billion columns, and is quite proud of this fact. But, you ask anyone in the community, and they will tell you — storing 2 billion columns in one row is a very, very bad idea. So, how many is right? 10,000? 100,000? A million? A hundred million?</p><p>We demanded answers, but we couldn’t get consistent ones. For our own data set, we settled on roughly 100,000 — and we also suggested that our average row should have many fewer columns than that — typically a few thousand. For our data set, this seems to strike the right balance between read performance and compaction/memory pressure on the cluster.</p><p>But, determining the right row size for your data will be an iterative process, and will require testing. So, think hard about it during schema design and during your integration tests. In our case, we decided to partition data by event type and on every tracked URL. We further partitioned the data by hour, so that the data for a single URL on a single day was stored in 24 row keys. This seemed to work well for 99.99% of our rows, until something awful happened.</p><h3>“The Dress” Breaks the Internet — and, Our Database</h3><p>The silly Internet meme about “The Dress” went around many of our customer sites, who are large news and information publishers. The result was that many customer URLs were receiving upwards of 40 million unique visitors <strong>per hour</strong> to a single URL. This meant that our partitioning scheme for Cassandra would get a “very wide row” — nowhere near 2 billion columns, to be sure, but definitely in the tens and hundreds of millions.</p><p>This put compaction pressure on our cluster and also led to some write contention.</p><p>Unfortunately, we couldn’t come up with a more natural partitioning scheme that would handle this rare case, so, instead, we had to introduce a “synthetic partition key”. That is, we have another system that tracks very hot URLs in a lightweight way, and when they reach a certain threshold, we systematically “partition the partitions” using a split factor.</p><p>So, 40 million events might now be spread among 400 row keys, ensuring that each only holds 100,000 columns of data, keeping our row size “just right”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*nkTWaW7uTBRn2h5W" /></figure><p>This introduced operational complexity, but was necessary to make Cassandra work for our use case.</p><h3>For Future Travelers: Here Be Dragons!</h3><p>A well-seasoned technologist friend of mine was not at all surprised when I walked him through some of these issues we had with Cassandra. He said, “You honestly expected that adopting a data store at your scale would not require you to learn all of its internals?” He has a point. After all, we didn’t adopt Elasticsearch until <a href="http://blog.parse.ly/post/1691/lucene/">we really grokked Lucene</a>.</p><p>But what about time series and analytics data? The funny thing about Parse.ly’s use of Cassandra is that our original adoption of it was driven by the desire to utilize its “time series analytics” capabilities. But it turns out, without any capability to group, filter, or aggregate (the core functions of any <a href="http://en.wikipedia.org/wiki/OLAP_cube#Operations">OLAP system</a>), Cassandra simply could not play that role. We had hoped that Counters would give us “basic aggregation” (by holding cumulative sums), but, no dice!</p><p>Instead, we ended up using it as a data staging area, where data sits before we index in our Lucene-based time series system. We discussed this a little bit over at the Elastic blog, in the article, <a href="https://www.elastic.co/blog/pythonic-analytics-with-elasticsearch">“Pythonic Analytics with Elasticsearch”</a>.</p><p>Now that we’ve come to understand its strengths and limitations, it works well in that role — because providing a time-ordered, durable, idempotent, distributed data store <strong>is</strong> something that Cassandra can handle.</p><p>If you adopt Cassandra for a large data use case, I recommend you heed the above advice:</p><ul><li>learn what CQL actually is;</li><li>avoid CQL Collections;</li><li>use COMPACT STORAGE;</li><li>adopt custom serialization formats;</li><li>don’t use counters;</li><li>stay on 2.0.x “most-stable”;</li><li>manage row size carefully;</li><li>and, watch out for partitioning hotspots</li></ul><p>With these guidelines in mind, you will likely end up with a better experience.</p><p>“If it’s too good to be true, it probably is.” Indeed.</p><p>But, overall, Cassandra is a powerful tool. It’s one of the few <a href="https://aphyr.com/posts/294-call-me-maybe-cassandra/">truly “AP” (Highly Available and Partition-Tolerant) data stores</a> with a very powerful data distribution and cluster scale-out model. Its main fault is over-marketing its bugs as features, and trying too hard to make its quirky features appealing to the mass market, by dumbing them down.</p><p>For experienced distributed systems practitioners, adopt Cassandra with the comfort of knowing the scale of its existing deployments, but with the caution that comes from knowing that in large-scale data management, there is no silver bullet.</p><h3>Postscript: Living with Cassandra</h3><p><em>I asked Didier Deshommes, a long-time Parse.ly backend engineer, if he had any tips for newcomers. His tips are included here as the postscript to this article.</em></p><p>Though this article discussed many of the traps we hit with Cassandra, there are many resources online for how to model data “the Cassandra way”. These can serve as some positive instruction.</p><p>I find that modeling data in Cassandra involves essentially one trick with several variations (wide rows).</p><p>Although there are several Cassandra how-to and data modeling tutorials, I usually keep going back to only a handful of links when I want to refresh my memory on them. The funny thing about these links is that many of them come from around the time CQL was introduced, or even before.</p><h3>The WHERE Clause</h3><p>Writing data is so easy in Cassandra that you often forget how to read it efficiently. The best guide I know for knowing what you can get away with is <a href="http://mechanics.flite.com/blog/2013/11/05/breaking-down-the-cql-where-clause/">Breaking Down the CQL Where Clause</a>.</p><p>As a nice side effect, this will also inform how to structure your writes so that you can take advantage of some of these rules.</p><h3>Time Series Models</h3><p>Cassandra is a one-trick pony, so sometimes you need a little creativity for fitting it to your problem. When I’m feeling stuck and worried I might run out of wide row tricks, I go back to <a href="http://www.datastax.com/dev/blog/advanced-time-series-with-cassandra">Advanced Time Series with Cassandra</a> to give me ideas.</p><p>This builds on Cassandra modeling techniques developed in 2011, in <a href="http://rubyscale.com/blog/2011/03/06/basic-time-series-with-cassandra/">Basic Time Series with Cassandra</a>. I don’t go back to this older article as often, but it does introduce the well-worn idea of time-based rollups.</p><h3>Tyler Hobbes</h3><p>Tyler Hobbes, the author of the advanced time series post, also recently put out <a href="http://www.datastax.com/dev/blog/basic-rules-of-cassandra-data-modeling">Basic Rules of Cassandra Data Modeling</a>, which is a great place to get started. It’s the article I point newer Cassandra users to right away.</p><p>Tyler is the primary author of Cassandra’s <a href="https://github.com/datastax/python-driver">CQL Python driver</a>, so there is also much to learn from him via his public slides, such as:</p><ul><li><a href="http://www.slideshare.net/tylerhobbs/intro-to-cassandra">Intro to Cassandra</a> — focuses on the “what makes Cassandra special” parts without marketing hype</li><li><a href="http://www.slideshare.net/tylerhobbs/cassandra-for-python-developers">Cassandra for Python developers</a> — these slides are interesting because they predate CQL</li><li><a href="https://speakerdeck.com/tylerhobbs/principles-of-cassandra-data-modeling">Principles of Cassandra data modeling</a> — visual aid for the above “rules of data modeling” blog post</li></ul><p>Avoid the traps, embrace the tricks. Good luck!</p><p><em>Originally published at </em><a href="https://blog.parse.ly/post/1928/cass/"><em>blog.parse.ly</em></a><em> on May 7, 2015.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=16c825143acf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parse-ly-engineering/this-team-used-apache-cassandra-you-wont-believe-what-happened-next-16c825143acf">This Team Used Apache Cassandra… You Won’t Believe What Happened Next</a> was originally published in <a href="https://medium.com/parse-ly-engineering">Parse.ly Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Picking a cloud database for analytics: the SQL options]]></title>
            <link>https://medium.com/parse-ly-engineering/picking-a-cloud-database-for-analytics-the-sql-options-5993af20e083?source=rss----3cf5297cc33---4</link>
            <guid isPermaLink="false">https://medium.com/p/5993af20e083</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google-big-query]]></category>
            <category><![CDATA[amazon-redshift]]></category>
            <dc:creator><![CDATA[Parse.ly Engineering]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 15:20:34 GMT</pubDate>
            <atom:updated>2018-07-24T15:19:54.711Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’re a developer, analyst, or data scientist, you have probably been hearing a lot about “analytics” these days. Some the most popular open source big data projects, like — <a href="http://spark.apache.org/">Spark</a>, <a href="http://cassandra.apache.org/">Cassandra</a>, and <a href="http://elastic.co/">Elasticsearch</a> — regularly tout their analytics abilities. But it’s only in the last 18 months that good old SQL has re-emerged as a formidable analytics technology.</p><p>What’s going on? I thought “NoSQL” was for analytics data, and SQL was for business data?</p><p>Well, we’re going to unpack that all today. In particular, we will discuss how SQL is used for analytics, and how analytics queries are supported by real-world cloud SQL services.</p><p>This post started with a tweet:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/631/0*QoC4_xjHte_S_Emk" /></figure><p>… and, keeping the promise of that tweet — and the many replies and likes it received — this post will compare:</p><ol><li><a href="https://aws.amazon.com/rds/postgresql/">Amazon RDS (Postgres)</a></li><li><a href="https://cloud.google.com/sql/">Google Cloud SQL (MySQL)</a></li><li><a href="https://aws.amazon.com/redshift/">Amazon Redshift</a></li><li><a href="https://cloud.google.com/bigquery/">Google BigQuery</a></li></ol><p>It will also serve as a guide for choosing between these options, including the technical pro’s and con’s of each.</p><h3>How SQL is used for analytics</h3><p>SQL — the language, the concept — actually excels at analytics.</p><p>What is analytics, from a technical point-of-view? It’s really two interlocking functions over your data: <strong>reporting</strong> and <strong>analysis</strong>.</p><p>Reporting answers the “how many?” question, and typically involves these three query components:</p><ol><li>aggregating some data</li><li>over some time period</li><li>with some filtering applied</li></ol><p>For example, the classic reporting query is, “how many hits did my website get in the last 7 days?” This could be expressed as a SQL query like the following:</p><pre>SELECT COUNT(action) as views FROM parsely.rawdata WHERE action = &#39;pageview&#39; AND ts_action &gt; current_date - interval &#39;7d&#39;;</pre><p>(Here, we’re using Postgres dialect of SQL.)</p><p>The SQL table is assumed to contain one row per event, with action = &#39;pageview&#39; indicating a pageview event, and where ts_action is the timestamp of the event. The aggregation, COUNT(...), is a simple count of all of those events. SQL has several common aggregates supported in the standard, including COUNT, SUM, MAX, COUNT(DISTINCT ...), etc.</p><p>Analysis is about drawing some conclusion from your data. Rather than answering the “how many?” question, we aim to answer the “why?” question.</p><p>For example, let’s say you determine that in the last 7 days you saw a spike in page views on your site, which you determined via one of th above reports.</p><p>You might wonder, “Yes, but why did traffic spike?” So then you may try to characterize everything you know about this week. For example, this SQL query could select all the data from this week, and break out all the traffic sources by referrer domain and the URL of the pageview.</p><pre>SELECT ref_domain as domain, url_clean as url, COUNT(action) as views FROM parsely.rawdata WHERE action = &#39;pageview&#39; AND ts_action &gt; current_date - interval &#39;7d&#39; GROUP BY 1, 2 ORDER BY 1;</pre><p>Now we’re digging into the spike and finding the domain and url that received the most clicks on that day, so we can try to understand it a little better. This is a simple query, but it starts to get into analysis — answering the “why?” questions around our sites and apps.</p><p>As you can see, SQL does well at both of these core analytics tasks: reporting and analysis.</p><h3>Why not SQL engines for analytics?</h3><p>So, if the <em>SQL language</em> is good at this stuff, why haven’t people been using <em>SQL engines</em> for analytics? In a word: <strong>performance</strong>.</p><p>The only reason SQL has not been the obvious first choice for analytics in the last few years is due to machine and data limitations of most common single-node SQL engines, specifically the typical Postgres and MySQL database setups you find powering the lion’s share of modern applications.</p><p>For example, if you install Postgres on a server, you will be limited by CPU, memory, disk, or all three.</p><p>Let’s say you have a 100 GiB disk for this database server. Well, you can only store a little less than 100 GiB of total data. Some websites have so much traffic that raw page view events would fill up a 100GiB disk pretty quickly — perhaps in a few days. So, that’s the disk limitation.</p><p>NoSQL stores solve disk limitations with horizontal data sharding strategies, such as the consistent sharding strategy famously used in <a href="http://cassandra.apache.org/">Cassandra</a>.</p><p>What about CPU or memory? Well, let’s take one of the most painful kinds of analytics for many SQL databases: COUNT(DISTINCT ...). If you have ten million page view events, and you want to count unique visitors across those events, you might need to write a SQL query like this:</p><pre>SELECT COUNT(DISTINCT visitor_site_id) FROM parsely.rawdata WHERE action = &#39;pageview&#39; AND ts_action &gt; current_date - interval &#39;7d&#39;;</pre><p>On Postgres and MySQL, the performance of this query will be quite atrocious if the number of page view events is high.</p><p>In each database, an in-memory set of the unique identifiers will need to be constructed by the database engine, and a full table scan will be performed. Even if your CPU keeps up with the scan, your memory probably won’t keep up with the cardinality of that set. If the disk of this server is 100 GiB, your memory is bound to be a fraction of that, like 16 GiB, so this query will simply fail — and perhaps even crash your server.</p><p>Open source technologies like <a href="http://elastic.co/">Elasticsearch</a> and <a href="http://spark.apache.org/">Spark</a> work around this problem by using multi-node parallelism, thus agglomerating CPU and memory from a cluster of machines. They also use approximation algorithms, known as “data sketches”, to achieve acceptable performance for the particularly problematic “count distinct” problem. But to do so, they end up moving outside of traditional SQL capabilities.</p><h3>Single-Node vs Multi-Node</h3><p>Traditionally, SQL engines are single-node. Thus, the only way to scale them is to get a bigger machine. One thing that NoSQL engines do well is multi-node, or cluster, operation.</p><p>In the case of a system like <a href="http://cassandra.apache.org/">Cassandra</a>, multi-node means that data can spread evenly across nodes, avoiding the limits of a single disk. In the case of systems like <a href="http://spark.apache.org/">Spark</a> and <a href="http://elastic.co/">Elasticsearch</a>, memory and CPU is spread across multiple nodes, as are the “working sets” of data and computation (such as aggregations).</p><p>So, when you run a query similar to the queries above, they “scatter-gather” across the cluster to speed up the query and use cluster-wide resources.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/0*pacfCfi5sEwelcv7" /><figcaption>This diagram shows how a scatter/gather query “chunks” your query into multiple queries that execute in parallel across several nodes (the scatter phase) and then return the results to a single node, which combines them before returning to a single client (the gather phase). All analytics databases and systems that are designed for scale work this way.</figcaption></figure><h3>Memory vs SSD vs Spinning Rust</h3><p>Traditionally, SQL engines run on machines with relatively little memory and large “spinning rust” disks. Because the database knows that memory is limited and disk access is expensive (from a performance standpoint), the database tries to use a fixed amount of RAM and speed up disk access using indices.</p><p>But in the case of modern cloud computing hardware and data centers, gobs of system memory have become cheaper, and SSDs have all but replaced spinning rust in standard deployments. Due to this, it can be faster to load large working sets of data into memory, or lay them out efficiently on SSDs, to provide interactive query speeds.</p><h3>Row-Wise vs Column-Wise</h3><p>A big difference between standard SQL engines, like MySQL and Postgres, and the new crop of NoSQL engines, like <a href="http://elastic.co/">Elasticsearch</a> and <a href="http://cassandra.apache.org/">Cassandra</a>, is what is known as row vs columnar storage.</p><p>To illustrate this difference, consider our millions of page views. Imagine if one database stored the millions of page views like this:</p><pre>row1 = {&quot;url&quot;: &quot;/article1&quot;, &quot;views&quot;: 1, &quot;starts&quot;: 0} row2 = {&quot;url&quot;: &quot;/article2&quot;, &quot;views&quot;: 1, &quot;starts&quot;: 0} row3 = {&quot;url&quot;: &quot;/article2&quot;, &quot;views&quot;: 0, &quot;starts&quot;: 1} row4 = {&quot;url&quot;: &quot;/article1&quot;, &quot;views&quot;: 1, &quot;starts&quot;: 0} save(&quot;events.db&quot;, [row1, row2, row3, row4])</pre><p>Whereas the other database stored them like this:</p><pre>column1 = [&quot;/article1&quot;, &quot;/article2&quot;, &quot;/article2&quot;, &quot;/article1&quot;] column2 = [1, 1, 0, 1] column3 = [0, 0, 1, 0] save(&quot;column1.db&quot;, column1) save(&quot;column2.db&quot;, column2) save(&quot;column3.db&quot;, column3)</pre><p>Now let’s imagine both databases have to store the entire “table” on-disk, and the format chosen is as follows. For the first database, 1 file, events.db, is stored. The file consists of 4 lines, with each row in row1..4 on each line. For the second database, 3 files are stored, named column1.db, column2.db, column3.db, and these store the data in each column in column1..3, each as separate lines.</p><p>To query either database, you need to load parts or all of the data into memory. But there’s a question of how much work you have to do to get the relevant data. If there millions of such events, the second database design — the column-oriented one — will have a much easier time counting the views.</p><p>Why is that? Well: it can just slurp that array of view integers, represented there by column2 and stored in column2.db, directly into memory, and calculate a fast SUM. The row-based database would need to <strong>load, parse, and scan all rows</strong> to count the views. This is the essential difference between column- and row-oriented storage.</p><p><a href="https://twitter.com/oceankidbilly">Rob Story</a>, in his presentation on <a href="https://www.youtube.com/watch?v=9nX35zrN20E">Simple’s use of a Redshift SQL Warehouse</a>, describes this distinction quite well in this slide:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/0*Jk3fWjjx-p4WGVOs" /><figcaption>A simple SELECT of two columns would scan all rows in Postgres, a row-oriented database, but would only scan the two columns in Redshift, a columnar database.</figcaption></figure><p>Obviously, column-oriented storage has some downsides. For example, if you modify or delete a “row” of data, you need to update N database files — one for each column in your database table. This can be make UPDATE and DELETE operations very slow. But column-oriented storage has so many extra benefits for query time. Column-oriented database systems can compress data more easily, filter data more quickly, and scan data more efficiently — all thanks to the column-stride format.</p><h3>NoSQL is cool, but I love SQL!</h3><p>Given the above advantages of NoSQL systems, are you doomed to use them instead of SQL forever? Do you now need to puzzle over their odd query languages and beg your devops staff to spin you up expensive clusters?</p><p>Nope! The cloud has the answer. And the answer is, unsurprisingly, a “hybrid approach”. The convenience of the SQL language and interface, mixed with the power of cloud and cluster computing. Enter: <strong>the cloud SQL engines.</strong></p><h3>Cloud Postgres and MySQL</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LtHCTUe0_hWXYIXr" /></figure><p>Amazon and Google recognize that a major part of any data center footprint involves regular SQL databases. They further know that the widespread success of the largest open source SQL communities — MySQL and Postgres — create network effects that are unbeatable.</p><p>As a result, it is no surprise that Amazon and Google each offer a “fully-managed” experience around these open source projects; let’s now dive into how these systems might work with analytics data.</p><h4>Amazon RDS</h4><p><a href="https://aws.amazon.com/rds/postgresql/">Amazon’s Relational Database Service (RDS)</a> is an established offering from AWS to run PostgreSQL in the cloud.</p><p>In their words, “you can deploy scalable PostgreSQL deployments in minutes with cost-efficient and resizable hardware capacity.” Sounds promising. So, what’s going on here?</p><p>RDS is not that different from running your own stock PostgreSQL engine. The key benefit is that you can elastically expand compute, disk, and memory via the Amazon control panel and APIs.</p><p>It does not provide any magic answer for the COUNT DISTINCT problem. That will still be slow on many events. But instead of being stuck with whatever server you pick up-front for your database, RDS lets you start with a small database with a slow disk, and pay more money for a bigger database with a bigger and faster disk. This can be helpful as you start to ingest more and more analytics-style event records into the DB.</p><p>You also get read replicas for free, which can be important for analytics use cases. By separating your read and write path, you’ll ensure your expensive analytics queries are not slowing down your database such that it can’t keep up with new data as it arrives.</p><p>For small scale use cases, RDS works perfectly fine, and benefits from lots of simplicity. Specifically:</p><ul><li>since it’s “just Postgres”, it works with all your existing drivers and tools</li><li>since it’s “just SQL”, you can use all the filtering, subselect, and aggregation tricks you’re used to with a SQL engine</li><li>since it’s hosted by AWS, you don’t have to worry about resizing clusters when you run out of space; this is something AWS can do with a few clicks</li><li>since it’s hosted by AWS, you can set up read replicas that are dedicated “analytics query nodes” used solely by your analyst teams</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PqJKSUcucY1TVAhS" /><figcaption>This view of the Amazon RDS control panel shows how your various SQL instances can be easily managed, backed up, restarted, restored, monitored and made highly available via Amazon tooling. But under the hood, these DB’s are just plain PostgreSQL instances!</figcaption></figure><p>One of the sore spots for using a tool like Postgres and RDS for analytics is its poor support for unstructured data that is common in analytics use cases. For example, if you have a “big pile of JSON” events, you’ll need to write your own tools to translate those into SQL INSERT statements, and you’ll need to be careful how you batch load those queries into your database. But, again, at small scale, this might not be a big deal.</p><h4>Google Cloud SQL</h4><p>Google’s Cloud SQL offering, which just exited beta, is similar to RDS, but in Google’s public cloud. It only runs on MySQL.</p><p>(Note: I know that Amazon RDS also supports MySQL, and even has a ‘special’ MySQL offering called Aurora. But for the purposes of this post and my own sanity, I’m going to avoid wading into those weeds.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/499/0*7vjLPkWCMvzs1uvX" /><figcaption>Man, does Google make it easy to create a database instance, and customize every detail about it, from CPUs to memory to disk throughput to storage. A really well-done interface for making your own little SQL analytics sandbox compatible with MySQL open source tools.</figcaption></figure><p>Similar to RDS, Google’s offering is fully-managed. They handle backups, replication, updates, etc. Just as with Postgres, you’ll find analytics queries will be limited to disk, CPU, and memory at certain scale. But at least you’ll be able to use Google’s snazzy control panel to resize your database nodes or setup replicas with zero ops work and minimal downtime.</p><h3>Analytics Engines on Cloud Clusters</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CXGEf0AzkrYjCedf" /></figure><p>Parallel Cloud Analytics Engines like Amazon Redshift and Google BigQuery are very different from the above two products. Rather than offering a hosted version of an open source SQL engine, these services offer fully-managed multi-node (cluster) for doing analytics, but targeted at SQL analysts. In each case, the underlying technology is <em>not</em> open source; they are proprietary analytics engines that offer varying degrees of SQL support.</p><p>So, in addition to being contrasted from the hosted SQL options above, they should also be contrasted from open source analytics engines, like Elastic, Presto, Spark, and Druid. Each of these systems <em>is</em> fully open source, like MySQL and Postgres are. You can run them on your own local development boxes, and on your own clusters and machines, in any cloud. That does mean you have to master them from both an operational and query language standpoint. Elastic and Druid have specialized query languages and data models, whereas Spark and Presto have limited SQL implementations.</p><p>Amazon Redshift and Google BigQuery can be viewed, from this vantage point, as offering hosted, <em>proprietary</em> approaches to cluster analytics. The carrot is an ease of data loading and querying, in some cases with full SQL compatibility; the stick is vendor lock-in.</p><p>Further, as was shown in <a href="https://twitter.com/amontalenti/status/747451029965266944">this small poll I did on Twitter</a>, Amazon and Google run the market-leading technologies in this category.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/561/0*AdfWFhbgJGOBw9xF" /></figure><p>Some other players exist, such as Snowflake’s cloud SQL warehouse and NewRelic’s SQL-flavored analytics engine that powers their “NewRelic Insights” product, but the truth is, I don’t see these coming up too often in the consideration set of practitioners in the field.</p><p>These days, CTO’s and VP’s of Data/Analytics, as well as product/data leads on small technical teams, are viewing the build vs buy decision as a battle of Spark / Hadoop / Elastic / et al for open source self-hosted options vs Amazon Redshift / Google BigQuery for proprietary hosted options, and sometimes they are even adopting “all of the above” for different products/apps within their business.</p><h4>Amazon Redshift</h4><p>Alright — so, RDS and Cloud SQL are fully-managed, but mainly single-node, SQL engines. They aren’t really “made for analytics”, but they can be used for analytics as long as you don’t hit the scaling limits.</p><p>Redshift is something else altogether. It’s very, very different.</p><p>Even though Redshift also runs in AWS and also offers a Postgres-flavored SQL interface, it is not your typical SQL engine.</p><p>Similar to RDS, Redshift is fully-managed. A few clicks in your AWS dashboard and you have a Redshift instance up-and-running. But unlike RDS, Redshift is not limited to single machines. Every Redshift database is actually a <strong>cluster</strong> of machines.</p><p>And, unlike an RDS-powered Postgres instance, data stored in Redshift uses “columnar storage technology to improve I/O efficiency and parallelizing queries across multiple nodes.”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/835/0*B1eD_14CqzlqCVNH" /><figcaption>Redshift inside the AWS control panel, with recently run queries.</figcaption></figure><p>Here’s a snippet from the best part of Redshift’s marketing material:</p><p>“Redshift uses columnar storage, data compression, and zone maps to reduce the amount of I/O needed to perform queries.”</p><p>Let’s break that down. Columnar storage means that when you load homogenous, structured data into a Redshift table, your aggregates can run per-column, rather than requiring full table-and-row scans. This saves a whole lot of CPU time and disk I/O.</p><p>Data compression — using Redshift schema extensions, you can have it compress data in the columns of your table that you expect to be repeated. This will trade a little CPU for decompression for a whole lot less disk I/O, which is usually a good trade.</p><p>Zone maps — this is an optimization for data that has a “typical” ordering. For example, time series data may be stored in Redshift in time order. To quote Amazon’s documentation, “When you sort a table, we use zone maps (cached in memory) to skip 1 MB blocks without relevant data. […] If a table has five years of data sorted by date, 98% of the blocks can be eliminated when you query for a particular month.”</p><p>Let’s continue to break down the marketing language, and interpret it for our pageview example:</p><p>“Amazon Redshift has a massively parallel processing (MPP) data warehouse architecture, parallelizing and distributing SQL operations to take advantage of all available resources. The underlying hardware is designed for high performance data processing, using local attached storage to maximize throughput between the CPUs and drives, and a 10GigE mesh network to maximize throughput between nodes.”</p><p>Ah hah. So, after all the above optimizations, you’ll still have to scan/count/sum <strong>something</strong>. But, Redshift lets you achieve strong performance even when it finally makes CPU your analytics bottleneck, through the classic techniques of parallel compute. It’ll have your data sharded on several Redshift “nodes”, and each of those nodes will do a subset of the aggregation in map/reduce style. Thanks to fast internal network, the scatter-gather will be faster than waiting for the single node.</p><p>Now, to give you all these awesome features, Redshift has to make some tradeoffs. For example, Redshift is not meant to be used for lots of random INSERT statements, and especially not for random UPDATE or DELETE statements. For these use cases, RDS will perform more predictably. Redshift performs best if your table is like an “append-only log”.</p><p>In fact, Redshift warns you against using INSERT statements altogether, instead pointing you toward their excellent COPY command, which can bulk copy data from S3. A newer product from AWS called Kinesis Firehose allows you to use the Kinesis streaming write API to collect events, and it will automatically batch your events into S3 files and bulk load them using the Redshift COPY command. These are the “right ways” to ingest data into Redshift.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*h2TxQEv2luEXEwOh" /></figure><p>This diagram from Amazon on Kinesis Firehose shows how streaming data might flow from connected devices to your AWS account and finally into Redshift and common SQL-based BI tools, like Tableau.</p><p>If that sounds a little onerous, consider this: most of the time, data analysts get heaps of JSON or CSV data, and need to “dump it” somewhere to run queries. Well, Redshift’s COPY command is specifically optimized for this kind of bulk loading use case. Indeed, the command will even do things like automatically parsing JSON-line formats, automatically decompressing gzip-compressed files in S3, and automatically parsing string-based embedded data types like timestamps.</p><p>How about that COUNT DISTINCT aggregate we discussed before? Oh yea, Redshift handles that, too. Their <a href="http://docs.aws.amazon.com/redshift/latest/dg/r_COUNT.html">COUNT</a> function adds an extension called COUNT APPROXIMATE DISTINCT, which “uses a HyperLogLog algorithm to approximate the number of distinct non-NULL values in a column or expression; queries that use the APPROXIMATE keyword execute much faster, with a low relative error of around 2%.” Pretty cool.</p><p>Hopefully, with these explanations, you can see that Redshift appears as a kind of analytics chimera. Yes, it has a SQL interface, which can plug into existing code and tools that need to run analytical queries. But it’s not like your typical SQL engine. It is restrictive on the write path, and extends SQL in certain ways, while attacking the core performance problems that made old SQL engines a poor fit for large-scale analytics. And all while offering the convenience of Amazon’s public cloud and relatively ops-free control panels.</p><h3>Google BigQuery</h3><p>“But why bother worrying about machines and clusters at all?”</p><p>This is probably the question the Google team posed when thinking through their own take on SQL-style analytics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*9g_RfyABhKLrbR9f" /></figure><p>BigQuery tables may look like traditional SQL tables, but they are very, very different.</p><p>BigQuery is Google’s answer to Redshift, although its architecture is <strong>dramatically</strong> different. Some parts are the same: for example, to attack the core performance problems, BigQuery also uses columnar storage, compression, fast internal network, and multi-node data sharding.</p><p>But unlike Redshift, you don’t run “a BigQuery cluster”. Instead, you just get a BigQuery account, and with that account, you are given API access to a single, massive BigQuery cluster that is run by Google. It’s truly “SQL analytics as a service”, and it’s truly “zero ops”.</p><p>Similar to the Redshift COPY command, BigQuery provides a tool called bq that assists with bulk loading of JSON or CSV data. It can even sync that data from Amazon S3 buckets.</p><p>Intriguingly, BigQuery doesn’t shy away from the real-time streaming write problem. For a price, you can send BigQuery streaming writes via a publicly-documented HTTP API, where bulk inserts can happen in a streaming fashion. This API is wrapped up in official clients for Python, JavaScript, and other languages. You never send BigQuery an INSERT or UPDATE statement; you either send it streaming writes, or you bulk load data using the bq tool.</p><p>Up until a few months ago, the big difference between Redshift and BigQuery from a usability standpoint was that Redshift supported a SQL dialect that was <strong>very</strong> close to Postgres, and indeed was mostly compatible with standard Postgres clients. But BigQuery had its own quirky not-quite-SQL-but-sorta-SQL dialect. Most tools couldn’t work with it out of the box, so you had to use special client libraries or buy special connectors for your client tools.</p><p>But a couple months ago, their <a href="https://cloud.google.com/blog/big-data/2016/06/bigquery-111-now-with-standard-sql-iam-and-partitioned-tables">Standard SQL dialect went into beta</a>. This means that BigQuery is much more directly comparable to Redshift on the client side. This also means that BigQuery will magically start working with BI tools that use standard connectors like JDBC and ODBC and expect to use “standard” SQL SELECT statements.</p><p>The truly amazing thing about BigQuery is just how fast it is on big data sets. Because every query can run on hundreds or thousands of partially-idle nodes in Google’s data center, pretty much every BigQuery analytics request will return in seconds, even when it’s doing a full scan of terabytes upon terabytes of data. To illustrate this power, Google has even published a number of public data sets, including the <a href="https://cloud.google.com/bigquery/sample-tables">full set of all Wikipedia edits and the full set of Github commits</a>, each of which is beyond terabyte scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aME2LV1iJDrVPzi1" /><figcaption>BigQuery’s included console allows one to execute SQL queries directly in the browser, design schemas in the browser, do query/job management, get results in CSV/JSON, and also create derived tables from result sets that can be saved to BigQuery itself in just a few seconds. Here, some data from the Github public code dataset is shown. Overall, it’s a very slick end-to-end offering that has become my go-to tool for ad-hoc data tasks.</figcaption></figure><p>Making BigQuery fast is not some grand data modeling or performance tuning exercise. It doesn’t require lots of expertise in setting up schemas or thinking through data distribution, sort keys, and the like. Instead, you just dump your data into BigQuery. If you can query it, then you can also query it quickly. It’s hard to come up with queries that “break” the system. Yes, some queries are faster than others, but no query is a showstopper for your database. Even if you manage to send it a really terrible query — for example, by abusing sub-selects and joins to create a cardinality explosion — your only punishment will be that the query aborts after a timeout period. You didn’t just “hose your database” — since Google runs a global BigQuery cluster for everyone, they’ve already got safeguards in place to make sure no one ruins it for everyone.</p><p>That peace of mind is certainly worth something.</p><h3>SQL is back!</h3><p>I’m a big fan of the NoSQL movement. It got the open source community thinking through different ways to solve the challenges of data distribution and parallel queries, in an era where data volumes grew at an alarming rate and vectors for database performance changed dramatically.</p><p>However, I’m sure the data analysts and data scientists who thought to themselves — “I just want to be able to query my data!” — felt quite hamstrung by having to learn the query languages of MongoDB, Elasticsearch, Cassandra, and other similar tools. These tools are good for developers to build amazing web products, but not so good for analysts to do analytical queries. SQL, the language, is really the perfect fit for that sort of thing.</p><p>I would know: my team at Parse.ly runs <a href="https://www.elastic.co/elasticon/conf/2016/sf/web-content-analytics-at-scale-with-parse-ly">a massive analytics cluster atop Elasticsearch</a> for our real-time analytics dashboard &amp; API for publishers. But it was the recent excitement around cloud SQL engines that led us to also offer our backend data collection infrastructure as a service via <a href="http://parse.ly/data-pipeline">Parse.ly Data Pipeline</a>. What are the two most popular use cases for our Data Pipeline?</p><ol><li>to bulk load data into a Redshift cluster for full SQL over our analytics events</li><li>to stream real-time data to BigQuery for a fully-managed real-time SQL layer</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/0*cl_zQjXrKuWUl3Je" /><figcaption>Parse.ly’s <a href="http://parse.ly/help/rawdata/pipeline">technical documentation</a> shows some example SQL queries that can be used to reproduce specialized media metrics the system measures, like unique sessions, engaged time, and video starts. This requires the raw data is bulk loaded into an engine like Redshift or BigQuery, using the streaming data endpoints Parse.ly provides to customers.</figcaption></figure><p>The other thing driving interest in cloud SQL engines is the rise of SaaS BI tools, such as Looker, Periscope, and Mode. These allow teams to “roll their own dashboard” atop these options, and this is especially attractive to data analyst teams who might have felt that they could do complex analysis, but without visualizations of those analyses, they couldn’t be acted upon by the business- and customer-facing teams.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*B7E3QsNoHmxNOUNf" /></figure><p>So, this is happening: and we know, because we’re increasingly becoming a data source for SQL-fluent teams that are hosting their own warehouses.</p><h3>Recap</h3><p>Let’s recap quickly. Amazon RDS and Google Cloud SQL can let any analyst spin up a small Postgres or MySQL database for running analytics queries, and then scale it up when they need more CPU, disk, or memory. This can be done for low cost and with full compatibility with the “SQL of old”.</p><p>Amazon Redshift and Google BigQuery provide particularly compelling answers for running analytics queries on event data. Redshift lets you spin up a parallel cluster that will let you run unlimited queries at a fixed monthly or annual cost. BigQuery lets you get out of the cluster-running business altogether, and run any number of queries at a variable cost per query. And both offer ways to bulk load and stream in your raw data.</p><p>BigQuery is perhaps the most fascinating development in this space, because of the “no ops” and “no servers” approach. It’s a magic Google black box where you can dump terabytes of data, run queries that scan those terabytes of data, and get back answers within seconds.</p><p>As Felipe Hoffa, a BigQuery Developer Advocate, describes <a href="https://www.reddit.com/r/bigdata/comments/3jnam1/whats_your_preference_for_running_jobs_in_the_aws/cur518e">on this Reddit thread</a>, BigQuery takes a lot of the deep thought and up-front architectural design you’d have to put into designing a SQL analytics warehouse, and boils it down to, “who cares — just dump your data and BigQuery will figure it out.”</p><p>That’s pretty much the definition of “commodification of big data”, and I suppose it’s no surprise that Google is the one to figure it out. With BigQuery’s new “standard SQL” beta, I suspect competition in this space won’t slow down, and we’ll continue to see some amazing innovation over the next few years.</p><h3>Conclusion</h3><p>As for me, I’m betting that with 50 billion web analytics events per month and counting, <a href="http://parse.ly/data-pipeline">Parse.ly’s data set</a> will be one of the most fascinating ones that people analyze using these new tools.</p><p>In fact, we’ve designed a reference architecture around Parse.ly’s Data Pipeline that allows us to use all sorts of analytical databases with our raw data. You can see a diagram of that architecture here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*owpCoROkchBCuWeP" /></figure><p>More details can be found in our <a href="http://parse.ly/help/rawdata/pipeline">Data Pipeline technical documentation</a>. If you have any questions — reach out to me via <a href="http://twitter.com/amontalenti">@amontalenti</a> on Twitter.</p><p>—</p><p><em>Andrew is the co-founder and CTO of Parse.ly, a leading web/mobile analytics provider whose mission is to democratize data across organizations. His team’s work with the media industry includes powering the real-time dashboards used by staff at The Huffington Post, Slate, Mashable, and many other top sites. The </em><a href="http://parse.ly/data-pipeline"><em>Data Pipeline</em></a><em> powering Parse.ly’s suite of products operates at massive scale — and is now available as a </em><a href="http://parse.ly/data-pipeline"><em>fully managed service</em></a><em> that anyone can license for their company or team. Andrew is also a dedicated Pythonista, JavaScript hacker, and open source advocate in the areas of Kafka- and Storm-based stream processing technologies. You can find Parse.ly on Twitter at </em><a href="http://twitter.com/parsely"><em>@Parsely</em></a><em>, and Andrew over at </em><a href="http://twitter.com/amontalenti"><em>@amontalenti</em></a><em>.</em></p><p>—</p><h3>Appendix: Comparison Tables</h3><p>I’ve put together a couple of tables comparing the various services on both features/approaches and on price. I’ve included them below.</p><h3>Feature Comparison</h3><p>Service Storage Limits Sharding Analytics Speedups “Serverless” Amazon S3 None N/A No1 Yes Amazon RDS 6 TB No No No Google Cloud SQL 10 TB No No No Amazon Redshift Petabytes+ Yes Sketches, Compression No Google BigQuery Petabytes+ Yes Sketches, Compression Yes</p><ol><li>One of these is not like the other; S3 is obviously not a SQL engine. But it’s shown here to indicate why it tends to be involved in analytics discussions. S3 is a serverless way to just “dump your raw data”, and guarantee it’s durable and accessible.</li></ol><h3>Price Comparison</h3><p>This table is not really a fair “apples and apples” price comparison, but more to show you the menu of options from a pricing standpoint, and to showcase the different pricing models. Note also that these prices do not include any discounts provided by up-front payment or commitment.</p><p>RDS and CloudSQL have low entry points: you can spend as little as ~$20-$100/mo to get started with single-node setups, and you’ll still have unlimited querying capability for playing around with small and large data sets. The costs of these, even for single-node setups, can go up to a few thousand dollars per month; the case of RDS, a massive node with 244 GiB of RAM will cost you around $2.8k/month for compute.</p><p>Redshift has a steeper starting price: the smallest one-node cluster will cost you $180/month, and typical clusters will probably be in the $500-$1,000/month range. But if you use reserved instances judiciously, you can achieve price points near a couple thousand dollars per year to have a TB or more of fast-queryable data.</p><p>BigQuery’s pricing model is just totally different than the others. It’s $20/mo per TB of data stored, and then $5 per TB of data queried. That means if you have a query that scans a full terabyte of data, that single query will cost you $5. But, you don’t have to pay a dime for unused compute capacity.</p><p>So, with all that said, here’s the summary:</p><p>Service Storage Cost Compute Cost RAM per Node Amazon S3 $30 per TB / mo N/A1 N/A1 Amazon RDS $115 per TB of SSD / mo $13 — $2,865 per node / mo 1 GiB — 244 GiB Google Cloud SQL $170 per TB of SSD / mo $8 — $2,016 per node / mo 0.6 GiB — 104 GiB Amazon Redshift N/A2 $180 — $3,456 per node / mo 14 GiB — 244 GiB Google BigQuery $20 per TB / mo $5 per TB query3 N/A3</p><ol><li>S3 has no notion of “node”, therefore no compute or RAM; S3 cost is provided as a baseline of “cheap cloud storage”.</li><li>Redshift storage cost is tied to compute cost; there are options for regular disks and SSDs into terabyte ranges.</li><li>BigQuery has no variable per-node compute costs or per-node RAM limits because its pricing model is based on the amount of data scanned per query in the BigQuery cluster.</li></ol><p><em>Originally published at </em><a href="https://blog.parse.ly/post/4516/cloud-sql-bigquery-redshift/"><em>blog.parse.ly</em></a><em> on October 14, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5993af20e083" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parse-ly-engineering/picking-a-cloud-database-for-analytics-the-sql-options-5993af20e083">Picking a cloud database for analytics: the SQL options</a> was originally published in <a href="https://medium.com/parse-ly-engineering">Parse.ly Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PyKafka: Fast, Pythonic Kafka, at Last!]]></title>
            <link>https://medium.com/parse-ly-engineering/pykafka-fast-pythonic-kafka-at-last-c4c635b8eea?source=rss----3cf5297cc33---4</link>
            <guid isPermaLink="false">https://medium.com/p/c4c635b8eea</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Parse.ly Engineering]]></dc:creator>
            <pubDate>Tue, 24 Jul 2018 14:53:22 GMT</pubDate>
            <atom:updated>2018-07-24T15:19:27.131Z</atom:updated>
            <content:encoded><![CDATA[<p>For the last three years, Parse.ly has been one of the biggest production users of Apache Kafka as a core piece of infrastructure in our <a href="https://blog.parse.ly/post/1550/kreps-logs/">log-oriented architecture</a>. We currently process over 90 billion events per month in Kafka, which streams the data with sub-second latency in a large Apache Storm cluster. Data that originates in Kafka eventually finds its way into <a href="http://blog.parse.ly/post/1633/mage/">Mage</a>, our time series analytics engine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*UiBvl_TYkL6hxZdn" /><figcaption><em>Apache Kafka is an open source distributed pub/sub messaging system originally released by the engineering team at LinkedIn.</em></figcaption></figure><p>Though using some variant of a message queue is common when building event/log analytics pipelines, Kafka is uniquely suited to Parse.ly’s needs for a number of reasons. Specifically:</p><ul><li><strong>Ridiculous write performance</strong>: Most people adopt Kafka because of this killer feature — you can send it gigabytes of data per second and you will always saturate your Kafka broker’s network card before saturating disk or CPU.</li><li><strong>Multiple consumers per topic</strong>: Traditional pub-sub systems make “fan-out” delivery of messages expensive; in Kafka, it’s nearly free. This means we can have multiple production, staging, and beta environments all reading production data without duplicating our raw data storage.</li><li><strong>Cluster-level fault tolerance</strong>: Kafka has a distributed design that replicates data per-topic and allows for seamless handling of individual node failure.</li><li><strong>Data retention for message replay</strong>: Kafka has a unique “distributed commit log” design to its topics, which makes it possible to replay old messages even if they have already been delivered to downstream consumers. This allows for various data recovery techniques that are typically unavailable in pub-sub systems.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/726/0*VBNpaFQnJkh3i1_Q" /><figcaption><em>Kafka is built around the notion of producers and consumers. Producers write messages to topics, and consumers read messages from those topics. This many-to-many message delivery architecture leads to a high level of production flexibility in moving data from point-to-point.</em></figcaption></figure><p>To leverage these features well, you need a good driver for your programming language of choice. Kafka is written in Scala and is thus a JVM-based technology, and includes high-quality Java-based drivers. However, Parse.ly is firmly a Python shop. We were already maintaining <a href="https://github.com/Parsely/streamparse">streamparse</a>, a Python and Apache Storm integration library, so we figured it might be good to contribute our work on Kafka to the community, as well.</p><h3>Releasing PyKafka 1.0 in 2015</h3><p>Good Python drivers for Kafka really did not exist, even as late as June 2015. Though there was some code in the community, there was a huge lack of support for a specific Kafka usage pattern called “balanced consuming”. So, we took our internal code for this that we were already using in production, and we <a href="http://blog.parse.ly/post/2006/announcing-pykafka-python-support-for-kafka-0-8-x/">released it as PyKafka 1.0</a>.</p><p>That open source release was successful beyond our wildest imagination. We received many community reports of production usage, including at organizations like the Wikimedia Foundation and Activision. Meanwhile, Parse.ly’s production usage of PyKafka continued to grow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vseVkl9kqSAkCeDS" /><figcaption><em>Click above to view how we scaled Kafka usage over time. Parse.ly started using Kafka in mid-2013, switching from a ZeroMQ-based architecture. This was right as our data volumes started to grow rapidly. By January 2014, we were processing 5 billion events per month in Kafka. One year later, we grew 300% to 15 billion events per month. The next year, we grew 600% to 90 billion events per month. Meanwhile, in the last 2.5 years, we have developed </em><a href="https://github.com/Parsely/pykafka"><em>PyKafka</em></a><em>, our production-strength Python driver for Kafka consumers and producers, in the open on Github. It now has 2,000+ commits and 320+ stars, and we’ve closed 300+ issues for the community.</em></figcaption></figure><p>In 2015, we also enlisted the help of Yung-Chin Oei, to join the existing PyKafka committers of Emmett Butler and Keith Bourgoin, in improving the project. Yung-Chin developed some initial support for bridging Python to librdkafka, a C-based driver for Kafka that boasted better performance, and his main project was to bring this support to PyKafka.</p><p>In the rest of this post, Yung-Chin will introduce PyKafka’s new APIs, explain his work on integrating librdkafka, and showcase some performance numbers he recorded on using Python and Kafka together with PyKafka.</p><h3>Yung-Chin’s discovery of Kafka</h3><p>It was sometime in 2014 that I first stumbled onto Kafka, and found Jay Kreps’ really rather <a href="https://engineering.linkedin.com/distributed-systems/log-what-every-software-engineer-should-know-about-real-time-datas-unifying">lucid essay</a> “The Log: What every software engineer should know about real-time data’s unifying abstraction”.</p><p>To my (admittedly historical-perspective-challenged) mind, it read as a founding text for a new paradigm in messaging systems. And if that was the first thought, of course the next one was “How do I talk to this from Python?”</p><p>At the time, the options were limited. There was kafka-python, which wasn’t very mature yet, and there was another project called samsa, which was however stuck on an old Kafka protocol version. A bit of a barren landscape.</p><p>But a lot can happen in a few months: Parse.ly released PyKafka, and started what was essentially a rewrite that brought it up to date supporting the Kafka 0.8.2 protocol. Best of all: they got me to contribute, too.</p><h3>Basic pykafka usage</h3><p>PyKafka basically aims to deal with all the particulars of talking to a Kafka cluster. Abstractly, all you need to do is tell it which “topic” your messages need to be sent to or retrieved from, and it will figure out which brokers to talk to, and will also handle any reconnections, cluster reconfigurations and retrying requests. But let’s see all that in code.</p><p>PyKafka’s API is organized so that most everything elegantly flows from a single entrypoint, a KafkaClient instance:</p><pre>from pykafka import KafkaClient client = KafkaClient(&quot;localhost:9092&quot;)</pre><p>From there, you can discover available Kafka topics (try print client.topics) and then obtain a producer or consumer instance:</p><pre>topic = client.topics[&quot;topicname&quot;] producer = topic.get_producer() consumer = topic.get_simple_consumer()</pre><p>(More on why it’s called a “simple” consumer later on.) Should you wish to explore low-level cluster details, you can dive into client.cluster or client.brokers, but for today we’ll stick to the higher-level subjects of producing and consuming messages.</p><h3>Producing to Kafka</h3><p>“Producing” is Kafka’s term for writing or sending a message to a topic. At its simplest, all it takes is this:</p><pre>producer = topic.get_producer() producer.produce(b&quot;your message&quot;)</pre><p>For the finer points, there are two things worth touching upon: message partitioning, and asynchronous usage patterns. Or wait — maybe three things.</p><p>If your application is suited for it, the producer can be used as a Python context manager, like so:</p><pre>with topic.get_producer() as producer: while not your_app.needs_stopping: producer.produce(your_app.generate_interesting_message())</pre><p>This will ensure that, upon exiting the context, the program waits for the producer to flush its message queues.</p><p>“Wait, what message queues?” you ask. “You didn’t mention queues before!” Right, that gets me to the second thing. What’s important to know here, is that by default produce() ships your message asynchronously. This is important for performance — specifically, for throughput. PyKafka groups messages into batches in the background, which helps to reduce overhead and load on the Kafka cluster, and allows your application to charge ahead rather than block on network I/O. However, it also means that when produce() returns, you’ve no idea whether your message made it to disk on the cluster yet.</p><p>You have two options here. If you can afford produce() blocking until message delivery, the simplest thing is to start your producer in synchronous mode:</p><pre>producer = topic.get_producer(sync=True)</pre><p>In sync mode, either produce() returns and you know all is fine, or it raises an error. But, this is slow.</p><p>Even in sync-mode, if you produce() from multiple threads concurrently, those messages may still be batched together. It’s just that each of the producing threads will block waiting for delivery of the batch. This is a nice feature on, say, a multi-threaded webserver.</p><p>The other option is to enable delivery reports:</p><pre>producer = topic.get_producer(delivery_reports=True)</pre><p>In this mode, the producer instance exposes a queue interface on which it posts “delivery reports” for every message produced. You’re then expected to regularly pull the reports from the queue:</p><pre>msg, exc = producer.get_delivery_report(block=False, timeout=.1)</pre><p>If exc is not None, delivery failed and you can inspect the msg object which carries the message and its partitioning key. The idea here is that you can produce your messages fast (perhaps at rates of thousands per second), and then periodically check the delivery reports to make sure all the messages made it “to the other side” without errors.</p><p>That brings me to the last bit I want to highlight here: message partitioning. By default, messages are randomly allocated to topic partitions, but if you add a message key to your messages, and define a custom partitioner, you can achieve any allocation you like.</p><p>As an example, pykafka.partitioners.hashing_partitioner ensures that messages with a particular key consistently end up on the same partition:</p><pre>producer = topic.get_producer(partitioner=hashing_partitioner) producer.produce(b&quot;your message&quot;, partition_key=b&quot;bravo&quot;) producer.produce(b&quot;another message&quot;, partition_key=b&quot;bravo&quot;)</pre><p>will send both to the same topic partition.</p><p>So that’s producing in a nutshell. How do we get these messages back out?</p><h3>Consuming messages with PyKafka</h3><p>This can be as simple as</p><pre>consumer = topic.get_simple_consumer() msg = consumer.consume() print(”%s [key=%s, id=%s, offset=%s]” % (msg.value, msg.partition_key, msg.partition_id, msg.offset))</pre><p>That’s it. You pulled a message from the topic, and can now unwrap the payload and message key, and find out what partition it came from (because we didn’t specify otherwise, the consumer will read from all partitions that exist in this topic), and at what offset within the partition it sits.</p><p>Instead, you can also iterate over the consumer:</p><pre>consumer = topic.get_simple_consumer(consumer_timeout_ms=5000) for msg in consumer: print( ”%s [key=%s, id=%s, offset=%s]” % (msg.value, msg.partition_key, msg.partition_id, msg.offset))</pre><p>Iteration stops if no new messages have become available for consumer_timeout_ms — or, if you don’t specify this, iteration won’t stop, and we block, awaiting new messages forever.</p><p>If you want the consumer to regularly store its offsets (i.e. how far into each topic partition you’ve read), and — upon starting — to resume at the last stored offsets, you need to pass it a group name under which to store these:</p><pre>consumer = topic.get_simple_consumer(consumer_group=b&quot;charlie&quot;, auto_commit_enable=True)</pre><p>Alternatively, don’t set auto_commit_enable and call<br> consumer.commit_offsets() at your discretion.</p><p>There’s more: a headline feature of PyKafka is that, like the Java client, it offers a “balanced consumer”. What’s that do, you ask?</p><p>Well, the “simple” consumer is called that because it is not aware of other consumer instances that are reading the same topic. You can assign it a subset of all the available topic partitions</p><pre>parts = topic.partitions consumer_a = topic.get_simple_consumer( partitions=(parts[0], parts[2])) consumer_b = topic.get_simple_consumer( partitions=(parts[1], parts[3]))</pre><p>but adding a third consumer, or removing one, will not reshuffle partitions between them. The balanced consumer is capable of just that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/0*VDXEfqEjhpfhClLb" /><figcaption>Balanced consumers (aka “high-level consumers”) are a critical and uniquely differentiating feature of the Kafka system. It allows for horizontal scalability in reading high-throughput message streams. For example, if a single node can only process 1,000 messages per second, but your topic receives 10,000 messages per second, then you could use 10 balanced consumers to “shard” message consumption, with each consumer reading 1 or more partitions of data at a time. In addition to horizontal scalability, this adds high availability to your distributed consumer setups.</figcaption></figure><p>Balanced consumers connect to Zookeeper (which the Kafka cluster already depends upon to coordinate between brokers), enabling coordination of partition assignments between all consumers in a named consumer group. The beauty is that in PyKafka, all it takes is:</p><pre>consumer_a = topic.get_balanced_consumer( consumer_group=b&quot;charlie&quot;, zookeeper_connect=&quot;localhost:2181&quot;)</pre><p>This gives you a consumer instance with practically the same interface as the simple consumer — except that, if you’d instantiate a consumer_b in the same group “charlie”, consumer_a would be automatically notified of this, and would surrender half of its partitions to consumer_b, and so on. And, if consumer_b disappears for some unfortunate reason, consumer_a would be assigned its orphaned partitions automatically.</p><h3>Making PyKafka super fast in 2016</h3><p>We were looking to make usage of Kafka and Python together just as fast as using Kafka from a JVM language. That’s what led us to develop the pykafka.rdkafka module. This is a Python C extension module that wraps the highly performant <a href="https://github.com/edenhill/librdkafka/">librdkafka</a> client library written by Magnus Edenhill.</p><p>To get going with librdkafka, make sure the library and development headers are <a href="https://github.com/edenhill/librdkafka/#building">correctly installed</a> in some conventional location (e.g. under /usr/local/). If you then rebuild (or reinstall) pykafka, setup.py will automatically detect the presence of librdkafka and build the extension module. Alternatively, you need to export some search paths to help the compiler find the librdkafka headers and lib, <a href="https://github.com/Parsely/pykafka/blob/cec20cb79e9a899b67353c1b9da782526144af49/.travis.yml#L38-L40">like so</a>.</p><p>Now, all it takes is an extra switch when instantiating a producer or consumer:</p><pre>producer = topic.get_producer(use_rdkafka=True) consumer = topic.get_simple_consumer(use_rdkafka=True) consumer = topic.get_balanced_consumer(use_rdkafka=True)</pre><p>If the extension isn’t loadable, any of these calls will throw errors. Otherwise, that’s it, you’re good to go! You’re now using a performant C implementation of the Kafka protocol, but with the same Pythonic API!</p><p>As a side note, the librdkafka C client is actually a fully fledged client in itself, handling connections and reconnections upon cluster reconfigurations, and retrying failed requests, all automatically. In that sense, our wrapper code could have avoided communication with Kafka for itself at all. But we wanted to make the librdkafka-backed classes capable of serving as drop-in replacements for their pure-python equivalents. Thus, the librdkafka-backed consumer has been written to reuse our Python code for offset handling and consumer rebalancing, building on the C client only to handle consume() calls.</p><p>This, of course, is just a lot of talk. Let’s see about performance: what does the extra effort of hooking up librdkafka buy you?</p><h3>Performance assessment</h3><p>Let’s go straight for the numbers. These performance benchmarks were run against PyKafka 2.1, but should hold up for the latest PyKafka 2.4.0, as well, since no (known) performance-impacting changes happened in the meanwhile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/943/0*8BhdWVoKocXxRtmx" /></figure><p>All these tests were run against an 8-broker Kafka cluster, running locally on a 32-core system with ample RAM (60G) and after “pre-warming” the disk cache — that is to say, we read the entire test topic into RAM before benchmarking. What you’re seeing here is a somewhat condensed summary — for more details see <a href="https://github.com/Parsely/pykafka/issues/378">this topic on the issue tracker</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/0*ez9iztodS9aNLJv5" /></figure><p>The consumer benefits most from the librdkafka backing, as is clear in the raw throughput numbers, and more so in the cpu load numbers. It’s worth noting also, that the gains here are conservative estimates: the throughput numbers include instance-initialization time, and the load numbers include everything from the start of the process, including interpreter and module loading.</p><p>“Why?!” you ask? I guess benchmarking is hard to do fairly, and these choices simply gave the least jittery numbers. Benchmarking already initialized consumers suggested gains for the pykafka.rdkafka flavor of anywhere between 10x and over a 40x.</p><p>It turns out, we got really nice speed-ups on producing, as well:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/0*6HMsay5kmyfBtL9v" /></figure><p>Not only do we get a performance boost, but we also use less CPU:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/0*5KJZE00Npz7hacZb" /></figure><p>What I learned in benchmarking PyKafka is that the librdkafka speedups are certainly significant. And I had these findings confirmed by the Parse.ly team, who reported significant cluster-wide CPU savings and better throughput after putting the rdkafka-based consumers and producers into production.</p><p><em>— Yung-Chin Oei</em>, contributor to PyKafka</p><h3>A closing note on the Kafka community</h3><p>PyKafka’s impact at Parse.ly cannot be overstated. It is core to our real-time event analytics infrastructure — which is now even available to customers as a <a href="http://parse.ly/data-pipeline">hosted data pipeline</a> — and it is something we will continue to invest time, code, and effort improving.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*EHPXumEar0KtJV4B" /><figcaption>Kafka is the central “data hub” inside Parse.ly’s data center. Our real-time analytics dashboard gets its fresh data from Kafka. Kafka brokers — and PyKafka consumers — are also the source of raw data that streams to Amazon Kinesis and Amazon S3 for our hosted data pipeline product. Rather than Hadoop, we use Spark to re-process data that has been archived to S3.</figcaption></figure><p>With <a href="https://github.com/Parsely/pykafka/releases/tag/2.4.0">PyKafka’s recent 2.4.0 release</a>, we feel that it is production-ready for widespread use with Kafka 0.8 and 0.9. A highlight of this release was support for Kafka 0.9’s security features via SSL — one of our top community feature requests.</p><p>We hope you enjoyed this technical deep dive on the work we’ve done to make the experience of using Kafka better for the Python community. It’s a point of pride for our backend/data engineering team that we can share our expertise — and code — to promote the adoption of this excellent technology.</p><p>As this post illustrated, PyKafka is not only a full-featured driver, but it’s also blazing fast. So, where do we go from here? Well, at Parse.ly, we’re eager to kick the tires on the recently-released Kafka 0.10, and to ensure PyKafka continues to work well with its newer features.</p><p>However, in the last couple of years working on PyKafka, we can’t help but notice that there has been quite a lot of fragmentation in the Python community around Kafka. As far as we can tell, there are three major projects as of this writing:</p><ul><li><a href="https://github.com/Parsely/pykafka">pykafka</a>, our project, maintained by Emmett Butler and Keith Bourgoin from Parse.ly, with contributions by Yung-Chin Oei (pure Python + C extension wrapper, 0.8+ support)</li><li><a href="https://pypi.python.org/pypi/kafka-python">kafka-python</a>, maintained by Dana Powers, currently at Pandora (pure Python, mostly 0.9+ focused)</li><li><a href="https://github.com/confluentinc/confluent-kafka-python">confluent-kafka-python</a>, recently released by Magnus Edenhill, who is now on the Confluent team; this was a part of the broader Kafka 0.10 release (it’s a C extension, mostly 0.9+ focused)</li></ul><p>Each project has a different history, level of current support for Kafka, and set of features — and, of course, different APIs. This is obviously not an ideal state for the Python user community around Kafka, both those that currently have Kafka clusters in production and for those looking to adopt Kafka for new projects.</p><p>Therefore, we close this post with a call to action. If you are part of one of these communities and you have an interest in this, please chime in on our <a href="https://github.com/Parsely/pykafka/issues/559">Kafka + Python community discussion issue on Github</a>.</p><p>As for the wider Kafka community, we want to make sure Python support for this awesome stream processing technology is first-class in the years ahead. Onward to 100 billion messages per month and beyond!</p><p><em>— Andrew Montalenti, Emmett Butler &amp; Keith Bourgoin</em>, from the Parse.ly/PyKafka team</p><p><strong>Want to work with us at Parse.ly?</strong> Check out our <a href="https://www.parse.ly/jobs/#software_engineer">job postings</a>.</p><p><strong>Want to help out in open source?</strong> You can find us <a href="https://github.com/Parsely/pykafka">on Github</a>.</p><p><strong>Image credits:</strong> Watercolor style Kafka diagrams come from Neha Narkhede’s talk, <a href="https://speakerdeck.com/nehanarkhede/demystifying-stream-processing-with-apache-kafka"><em>Demystifying Stream Processing with Kafka</em></a>. Other diagrams are original to this post.</p><h3>Related</h3><p><em>Originally published at </em><a href="https://blog.parse.ly/post/3886/pykafka-now/"><em>blog.parse.ly</em></a><em> on June 9, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c4c635b8eea" width="1" height="1" alt=""><hr><p><a href="https://medium.com/parse-ly-engineering/pykafka-fast-pythonic-kafka-at-last-c4c635b8eea">PyKafka: Fast, Pythonic Kafka, at Last!</a> was originally published in <a href="https://medium.com/parse-ly-engineering">Parse.ly Engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>