<?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[jampp-engineering - Medium]]></title>
        <description><![CDATA[Creating technology that helps mobile companies grow - Medium]]></description>
        <link>https://medium.com/jampp-engineering?source=rss----e7378711074e---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>jampp-engineering - Medium</title>
            <link>https://medium.com/jampp-engineering?source=rss----e7378711074e---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 20:37:48 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/jampp-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[Spread the code: How Jampp’s tech team tackles knowledge-sharing]]></title>
            <link>https://medium.com/jampp-engineering/spread-the-code-how-jampps-tech-team-tackles-knowledge-sharing-96f46c4e3747?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/96f46c4e3747</guid>
            <category><![CDATA[company-culture]]></category>
            <category><![CDATA[engineering]]></category>
            <category><![CDATA[recruiting]]></category>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[hiring]]></category>
            <dc:creator><![CDATA[Dardo Marasca]]></dc:creator>
            <pubDate>Tue, 07 Sep 2021 20:42:29 GMT</pubDate>
            <atom:updated>2021-09-07T20:42:29.036Z</atom:updated>
            <content:encoded><![CDATA[<p>Knowledge is power. But knowledge itself doesn’t guarantee top-notch tech. It’s only when we share what we know among fellow engineers that we can reach our full potential as a team.</p><p>Being open and transparent about knowledge (whether it’s a piece of software, the features of our products, or the way in which we write code) is what enables every Jampper to become a true owner of their work. The more we know, the faster we can develop, iterate, and deliver outstanding tech. At the end of the day, this drives us to be more competitive as a company.</p><p>That’s why at Jampp we consider that building an agile knowledge-sharing culture is a key pillar of our technology team. And we’ve got numerous ways to do it, both internally and externally.</p><p>Want to find out how we share knowledge as a team? Read on 🤓</p><h3>Insider info: how we share knowledge within our team</h3><p><strong>print(“Hello, World!: Tech Onboarding at Jampp”)</strong></p><p>This vital knowledge-sharing practice starts on day one, as we give our best to ensure the onboarding process is a true learning experience.</p><p>During the first two or three weeks at Jampp, new engineers take part in thoroughly planned 101 meetings with every Team Lead. The goal is not only for them to dive into our fascinating industry, but also to understand how the team contributes to achieving our goals as a company.</p><p>Complementing these sessions, engineers are brought up to speed with tailored training based on their background, the role they will be developing, and the tech team they are joining, all of which is supported with documentation about our tools and technologies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*87PSNYeway4n-vYG" /></figure><p><strong>from “Jampp’s Best Practices” import “Documentation: keeping track of our progress”</strong></p><p><strong>Building our internal records:</strong> The most important best practice that we implement is documenting everything we develop. We don’t consider a project finished unless it comes with complete technical documents that allow any Jampper that was not part of the development to understand the solution and the decisions that were made around it. This also helps a lot when it comes to onboarding new team members! 😉</p><p><strong>Giving constant feedback — </strong>Another key practice is providing constructive and meaningful feedback on ongoing projects, whether it’s through RFC (request for comments) documents, or through our code review practice.</p><ul><li>RFC documents are built during the solution’s design stages and when these solutions reach a minimum level of maturity, the documents are presented to all the teams involved. At that point, every team member is able (and encouraged) to ask questions, debate, and suggest changes to the original idea. Senior engineers can easily detect potential issues or areas of improvement and transfer this feedback and knowledge to others.</li><li>Code review, on the other hand, takes place after implementing a solution and is organized through Github. In this case, the feedback is directly about written code, so it’s a perfect opportunity for junior developers to get specific pointers to improve their work and make sure they are aligned with our best practices.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZMCM2pF2eKZBOMZw" /></figure><p><strong>def “Tech Discussions”:</strong></p><p><strong>On a day-to-day basis: </strong>One way to keep connected as a remote team is through our Slack channels. They are the go-to tool for new engineers to ask for help and take part (even if they are only spectators) in technical discussions between other team members. To keep our conversations organized, we divide our channels by teams and goals: we have a channel for tech questions, another one for reporting bugs, and one for announcing changes.</p><p><strong>Monthly initiatives: </strong>We also have a set of team initiatives that foster our knowledge-sharing culture by generating an environment for laid-back and enlightening interactions.</p><p>The first one is a company-wide session where one or two Jamppers share a specific topic related to our business. The second one is specifically for the tech team, where we deep dive into technical solutions implemented in the latest projects.</p><p>Every couple of weeks we also have technical challenges, where all engineers (and Jamppers from other teams as well) can compete to solve a specific problem (not necessarily related to Jampp). Winners always present their solutions to the rest of the team and, to make it a little more special, they get a treat delivered to their home.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KQ_70j3zTskP_g5v" /></figure><h3>And we don’t stop there! How we connect with the outside world</h3><p>We also have several ways to share knowledge externally, which helps us create a connection between the technology community and Jampp.</p><p>One of the most important ways of sharing knowledge with others is our interview process. Our purpose is to ensure that all candidates can learn while they go through the process and are evaluated, not only about Jampp and our business, but also about the technologies we use and the solutions we develop.</p><p>We design the hiring process taking into consideration who the candidate is and what position they are applying for. With that in mind, we develop a custom hiring path, selecting the interviewers that will best assess the required skills and ensure a meaningful learning experience for the candidate. In some cases, we also include an exercise or challenge which our engineers are in charge of reviewing. They do this with the same diligence with which we carry out our daily work, providing constructive feedback to all candidates in all cases.</p><p>Apart from our hiring process, we also share our expertise by participating in different conferences, both local and international, as well as hosting different meetups at the office (before COVID-19, when we could get together). We’ve been part of specific events over the past few years, like PyCon, PyData, Nerdear.la, and <a href="https://www.youtube.com/results?search_query=jampp">ECI</a>. Our goal is to always give tech talks or share knowledge so participants can truly find learning experiences during those interactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*tyMi4gKAfjgMZxO4" /></figure><h3>Wrapping up</h3><p>Knowledge-sharing is part of our culture as a company and as a tech team.</p><p>One of the most meaningful moments at my job is when I learn something new. This knowledge helps me take a leap, challenge myself and grow as a developer. In order to do that, I need to fully understand the tools and software we work with, and there’s no better way to gain those insights than by learning from my fellow teammates.</p><p>There are many ways in which we do this. As we’ve mentioned, internally, we develop regular training sessions, a thorough onboarding process, and mindful documentation practices; externally, we look for ways of contributing to the tech community by participating in conferences, meetups, or publishing posts (whether it’s an academic paper or a blog post, just like this one 😉).</p><p>Overall, all of these methods help us build a stronger team, as well as communicating and sharing knowledge to develop better code and build seamless tech that helps our customers grow their business.</p><p><strong>Want to join the team? </strong><a href="https://www.jampp.com/careers?utm_source=tech_blog&amp;utm_medium=post&amp;utm_campaign=spread-the-code-how-jampp-s-tech-team-tackles-knowledge-sharing">Visit our careers page</a> to learn more about open roles and opportunities at Jampp.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wWSiZeef5A5Dyv-c" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96f46c4e3747" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/spread-the-code-how-jampps-tech-team-tackles-knowledge-sharing-96f46c4e3747">Spread the code: How Jampp’s tech team tackles knowledge-sharing</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Leveraging Docker Override and MinIO for local data development]]></title>
            <link>https://medium.com/jampp-engineering/leveraging-docker-override-and-minio-for-local-data-development-7052344d2449?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/7052344d2449</guid>
            <category><![CDATA[data]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[minio]]></category>
            <category><![CDATA[data-infrastructure]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Dante Pawlow]]></dc:creator>
            <pubDate>Thu, 07 Jan 2021 17:53:21 GMT</pubDate>
            <atom:updated>2021-01-15T13:51:37.339Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VSQIDVqICWBfnsLB" /></figure><p>One of the biggest problems when developing Big Data applications is figuring out whether or not your components will interact nicely with each other.</p><p>Integration testing usually requires setting up a staging environment in the cloud, possibly duplicating the production environment. This is not only expensive, but also cumbersome for developing: I’d much rather have everything set up locally, use my favorite editor and not bother my DevOps team with setting stuff up, granting access, and all that jazz.</p><p>The solution seems obvious at first: build a docker environment that you can use to run tests locally!</p><p>This, however, presents several difficulties:</p><ul><li>The complexity of the setup grows non-linearly with each component that you add, given that you usually have to integrate them into many of the components already present in the environment (and in data environments, there are normally <em>a lot</em>).</li><li>It requires extensive automation to be useful, otherwise it would be really slow to set up each time you need it, increasing friction and frustration.</li><li>Not every component that you have in the cloud is open sourced or easily replicated locally (think AWS’ services). This sometimes can be mitigated, albeit in detriment of the previous points.</li></ul><p>It was difficult, but once we overcame these hurdles, <a href="https://github.com/jampp/data-docker-images">we ended up with a development environment that is fast to set up, easy to use, and boasts the usual benefits of using Docker.</a></p><p>Now we can test to our heart’s content!</p><h3><strong>The environment</strong></h3><p>As it is a reflection of our production environment, it’s likely that your setup will look very different from ours. However, it shouldn’t be too difficult to modify, and we encourage you to adapt it to your needs.</p><h4><strong>Storage layer</strong></h4><p>At Jampp, we use AWS S3 as our main storage system. It’s the glue that holds many parts of our infrastructure together, so any developing environment that we use can’t exist without it.</p><p>Unfortunately, we had no way of replicating it locally. Our previous development environment used HDFS, which not only meant constantly adjusting the code to make it run locally, but also that we weren’t really performing integration tests.</p><p>The missing piece of the puzzle came when we discovered <a href="https://min.io/">MinIO</a>: an open-source object storage that is compatible with the S3 API. This allowed us to have a plug-and-play component without even having to replace S3’s URLs in the code!</p><p>Besides, MinIO’s lightweight nature and elegant UI make it perfect for developing locally, as a bucket’s structure can be set up with a few clicks or with a <a href="https://github.com/jampp/data-docker-images/tree/develop/minio#bucket-creation">simple script</a>.</p><blockquote><strong>Note</strong>: even though MinIO implements the S3 API, not every version of the AWS SDK works with it. We found that AWS’ 1.11.534 jars work well with Hadoop 2.8.5 and up.</blockquote><h4><strong>Orchestration</strong></h4><p><a href="https://airflow.apache.org/">Apache Airflow</a> is an amazing tool for building, orchestrating, managing and dynamically generating simple or complex workflows.</p><p>Being the centerpiece of our operation, this development environment is built from the ground up to run everything through Airflow.</p><h4><strong>Data processing</strong></h4><p>Historically, all of our data processing was done with <a href="https://hive.apache.org/">Apache Hive</a>. Nowadays, the bulk of the processing is distributed between <a href="https://trino.io/">Trino</a> (ex PrestoSQL) and <a href="https://spark.apache.org/">Apache Spark</a> (run through <a href="https://livy.apache.org/">Apache Livy</a>). However, we maintain the Hive Metastore as the main interface between engines, using it to manage all table metadata in our data warehouse.</p><p>These three services receive jobs from Airflow, fetch and store files in MinIO, and use the Hive Metastore to obtain all the metadata they need.</p><h4><strong>Schema migrations</strong></h4><p>We track Trino’s and Hive’s migrations and table alterations through another one of our open-sourced projects: <a href="https://migratron.readthedocs.io/en/latest/">Migratron</a>.</p><h3><strong>The docker-compose</strong></h3><h4><strong>Reusability with Docker Override</strong></h4><p>We have many projects that use Airflow, spanning many repositories. Because of this, a key feature of this environment had to be reusability without code duplication, made possible by <a href="https://docs.docker.com/compose/extends/">docker-compose’s override functionality</a>.</p><p>This functionality allows us to only extend or modify very few components of the environment in each repository, while letting them share the same infrastructure (much like when they share production clusters). Here’s an example of the docker-compose.override.yml file in one of our projects:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cf5f933805812ed3eec826505a17efb6/href">https://medium.com/media/cf5f933805812ed3eec826505a17efb6/href</a></iframe><p>As you can see, it only overrides a few files used for customization with the equivalent ones in the project’s repository and the Airflow service’s image, replacing it with one that also packages the project dependencies (you could even add services specific to the project this way).</p><p>All you have to do to run the modified environment is stand in the repository with the docker-compose.override.yml file, and execute this command, which’ll link run using both the base and override docker-compose files:</p><pre>PWD=`echo $PWD` docker-compose -f /path/to/base/docker-compose.yml -f /path/to/project/docker-compose.override.yml up -d</pre><h4><strong>Volume management</strong></h4><p>Docker volumes are what allow us to call this a “development environment”: by using them, we can edit our Airflow DAGs’ code, for example, and the changes will be immediately reflected inside the running containers.</p><p>Another advantage of using volumes is that their data is persisted when we shut the containers down, allowing us to resume the same test later or to share the same MinIO (with all its stored data) between different projects.</p><h4><strong>Alternative running modes</strong></h4><p>I may have exaggerated when I said that you should cram a highly distributed system into a single computer: most of the time you only need to test the integration between some components, not all of them at once.</p><p>This is especially useful if your computer struggles with running the whole environment, which we found to be the case in laptops with 8GB of RAM or less. This is another instance where Docker’s volumes are great: you can perform a sort of incremental testing, turning services on or off when needed, and the data will be persisted between executions.</p><h3><strong>Closing remarks</strong></h3><p>This Docker environment proved to be invaluable to us, but it took quite a while to develop it. This is why we wanted to make it accessible to anyone who may find it useful.</p><p>It currently only represents the batch-processing side of our infrastructure, but we continue to build upon it and add new components.</p><p>We encourage you to use this environment in your projects and add services or any other improvements you’d like!</p><h3><strong>Acknowledgments</strong></h3><p>We want to thank <a href="https://johs.me/posts/big-data-stack-running-sql-queries/">Johannes Tang Kristensen</a> and the <a href="https://github.com/big-data-europe">Big Data Europe team</a> for their excellent <a href="https://hub.docker.com/u/bde2020">Docker images</a>, from which we drew a lot of inspiration.</p><p>Ultimately, we made extensive modifications to those images in order to integrate more services, but please check the originals out, as you will find a wealth of knowledge there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7052344d2449" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/leveraging-docker-override-and-minio-for-local-data-development-7052344d2449">Leveraging Docker Override and MinIO for local data development</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Optimal bidding: a dual approach]]></title>
            <link>https://medium.com/jampp-engineering/optimal-bidding-a-dual-approach-b4ac10626f79?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/b4ac10626f79</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[adtech]]></category>
            <category><![CDATA[rtb]]></category>
            <dc:creator><![CDATA[Carlos Pita]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 20:05:11 GMT</pubDate>
            <atom:updated>2019-07-18T20:07:21.182Z</atom:updated>
            <content:encoded><![CDATA[<h3>Optimal Bidding: A Dual Approach</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8OruWgoFSfa20DmdYFaz5w.png" /></figure><h4>ABSTRACT</h4><p>We propose a practical yet rigorous near-optimal bidding strategy for demand-side platforms (DSPs) that scales to thousands of advertising campaigns programmatically bidding in real-time (RTB) in billions of auctions per day.</p><p>The strategy is logically derived from two different — stylized but realistic — constrained global profit maximization problems, so there are no ad hoc rules for pacing, pricing, etc. The approach relies on a few assumptions that we identify and analyze, providing a basis for further extensions to other kinds of problem/contract. It is expected to find a near-optimal solution by solving a convex relaxation of the original hard combinatorial problem. It is based on Lagrange duality so it has a sound, well-known, theoretical foundation. Optimal bids for first/second-price auctions can be cheaply computed in real-time given the shadow prices of the problem constraints; on the other hand, shadow prices are daily updated by a simple subgradient descent algorithm that converges logarithmically. The algorithm should be robust in the face of noisy real-life environments and of market seasonal oscillations and structural breaks.</p><p>For a special case, we also offer an alternative derivation based on an intuitive continuous relaxation argument that reinforces our confidence in the general solution proposed here.</p><p><a href="https://s3.amazonaws.com/files.jampp.com/Paper-2019-Optimal-Bidding.pdf">Read the full paper here.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4ac10626f79" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/optimal-bidding-a-dual-approach-b4ac10626f79">Optimal bidding: a dual approach</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Surviving software rewrites]]></title>
            <link>https://medium.com/jampp-engineering/surviving-software-rewrites-144b10dfff8b?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/144b10dfff8b</guid>
            <category><![CDATA[adtech]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[engineering]]></category>
            <dc:creator><![CDATA[Claudio Freire]]></dc:creator>
            <pubDate>Thu, 04 Jul 2019 15:00:34 GMT</pubDate>
            <atom:updated>2019-07-04T23:49:16.797Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AA3dlE6_WrgBn-NCvn9HOA.png" /></figure><p>I’ve suffered a few “rewrites” over my career, both in professional projects and in amateur ones. You know how it goes. You start your project coding with a few reasonable assumptions, and you get a nice proof of concept working. Then you realize your proof of concept became the actual thing, so you try (in vain) to “tidy things up”. But it works, and well, so you move on.</p><p>A few thousand kilometres down the road (because metric!), you look back in horror at your code. It’s awful, you’ve got tons of features nobody uses, features that require a lot of code and support.</p><p>You also realize you’ve engineered the whole thing wrong. The assumptions that seemed reasonable at the time turned out to be untrue after some real-world experience. Or maybe they were true, but not anymore. Whatever the case, you realize your whole software architecture no longer fits the problem.</p><p>Finally, you notice the quality of the code has considerably degraded. It’s hard to read. It’s hard to think about it. Patches upon patches, some for optimization, some for new features nobody wants, some to fix some obscure bug or worse, some workaround to deal with someone else’s bug. A million paper cuts made your software hard to read, and hard to maintain.</p><p>And you think to yourself… I could do this much better if I rewrote it today, with the knowledge I accumulated down the road. I know I can.</p><p>And if you’ve been in that situation and decided to go for it, <a href="https://medium.com/@herbcaudill/lessons-from-6-software-rewrite-stories-635e4c8f7c22">you know how it ends as well</a>. Almost always, in flames.</p><h4>Rewrites are very difficult, very risky projects:</h4><ul><li><strong>They’re extremely long projects: </strong>It’s not due to laziness it took years to get the software to that point. It takes time to discover how to do things, and more time to actually do those things. It’s not like you’ll be able to redo all that work in a week. Or a month. Or two.</li><li><strong>They’re risky: </strong>Since you’ve got to develop everything from scratch again, there’s a very high chance you’ll find something unexpected along the way. It’s a statistical certainty. With so much work ahead, you’d have an easier time winning the lottery than finishing the rewrite on time and without a hitch. Add that the long time frames involved naturally imply huge error bars on any time estimation, and you’ve got eternal headaches for management.</li><li><strong>They’re giant scope creep magnets: </strong>Since we’re rewriting it, I’ll take the opportunity to fix this thing I did wrong. And since we’re at it, we can improve on this… and that… famous last words.</li><li><strong>Insanely slow ROI: </strong>You won’t see the fruits of your labor until you’re done rewriting. Unlike with the original development experience, where you could deploy features as you went along, it’s unlikely you can replace your old software before you finish all the features. Feature regressions are hard to accept, so you won’t see it deployed until you’re done. And you don’t get feedback until you’re done.</li><li><strong>They’re demoralizing: </strong>All of the above means the whole endeavor will be fraught with pain and low morale. It’s not fun spending months coding something no user sees. You get no satisfaction from your work until the very end, <strong>if</strong> you get there.</li></ul><p>With that introduction, it might come as a surprise to you when I say the project I’m going to talk about isn’t one of those.</p><p>No way José. I’ve done those, I have developed the knee-jerk self-preservation reflex to say “No” when I hear such proposals. No, we didn’t <strong>intend</strong> to do a rewrite.</p><p>We just ended up doing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-ttMI-rnSk8d7_WqPk7IcA.jpeg" /></figure><h3>Preface</h3><p>Let me tell you the story of how we ended up there in the first place. If you’re feeling like <em>“TL;DR, gimme the punchline”</em>, feel free to skip to the next section. But if you’re in the mood for some storytelling, read on.</p><p>Like I said before, most useful projects start out from a PoC that does well and becomes the actual thing. Ours was no different. And, as such, there was a lot of room for improvement.</p><p>Not only that, but our way of doing business was changing, so many of the assumptions we made while writing the software no longer applied nor were a good fit to our needs.</p><p>The software I’m talking about is our Real-Time Bidder. It has some very strong performance requirements. One is that it has to answer most requests within 100ms. Any later, and the response is ignored. Furthermore, if even one percent of those requests take longer than that, our partners will start complaining.</p><p>But 100ms isn’t even close to our actual CPU budget. In order to stay profitable, we have to take much less than that per request. Our average target is closer to 4ms than 100ms.</p><p>Real-time bidding is a tough thing to get right, even without any machine learning and sophisticated algorithms and features. Just doing a very dumb bidder that can respond usefully within those constraints is a challenge. And we’re not content with a dumb bidder, we do use a lot of machine learning and have sophisticated features that make the endeavor technically challenging.</p><p>So we’ve cut more than a few corners to get that performance we need. And each corner we cut was motivated both by performance, and some business reality we <em>thought</em> would hold for a long time. <em>Except a lot of these didn’t</em>.</p><p>Skip a few years ahead, and we realized a lot had changed in how users (our account managers) were using it.</p><p>Our bidder was like the old OpenGL 1.0 of yore: highly configurable, but fixed-function. It was configurable enough that we could actually do what we needed, no problem there, but it took a lot of effort and human involvement, and we do believe in letting computers do what computers do best.</p><p>Weighing lots of variables to try and find the right users to show an ad to? That’s a task for computers, not humans. Figuring what ad to show to which user? Or the best time to show ads? Again, tasks for computers. Building reports that give an insight into possible performance problems or lost opportunities? You guessed it, the computer should do that, and yet we found, in lots of cases, our users had to “handhold” the system if they wanted to do things right.</p><p>Our bidder design was centered around a workflow that was no longer in use, and the new workflow was more labor-intensive than it should be <em>because</em> of that.</p><p>We knew that, and we wanted to fix it.</p><p>We started looking into the problem as a problem of automation (again, automating repetitive tasks? That’s a computer’s job) — that is, how do we build the current workflow into our UI so that users don’t have to spend more time than necessary navigating and clicking on the UI to do mundane tasks?</p><p>A colleague of mine, let’s call him Benja, because that’s his name, was in charge of that. As he delved into the problem, it became increasingly apparent that just UI changes wouldn’t cut it. Our whole system was built on outdated assumptions, not just the UI.</p><p>So he came to me to talk about that, and said, (I’m paraphrasing more than a bit): “What if we switched to a Rules-based system?”.</p><p>It would work! It was like upgrading from the fixed-function OpenGL pipeline to the fully-programmable GLSL-powered version 4.0 we’re so used to today (if you’re doing GPU programming that is). Having that expressive power would allow our workflow to translate naturally into the UI, and simplify our users’ tasks an order of magnitude.</p><p>At that point two thoughts crossed my mind: First thing I thought was that I was sold on the idea. I wanted to do it. And a second after that I thought <em>“I hate you”</em>.</p><p>Because I knew just how much work achieving that would involve. And if I hadn’t been convinced it was a good idea, I would never have agreed to take on such a huge task. But I was convinced. And I had fallen into the trap. And I knew the next N months of my life would be… well… <em>“fun”</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CTdYun49eOCAxAbTYqWwiA.jpeg" /></figure><h3>The project</h3><p>The project itself wasn’t a rewrite, but the changes involved were huge. As I said, it all started with a new UI. The new UI started adding constraints to the backend, enough that we ended up rewriting most of the existing code base. So it wasn’t a rewrite per se, but we rewrote most of our code anyway.</p><p>I mentioned we switched from a highly configurable fixed function pipeline into a highly flexible rules-based one that had a lot more expressive power. That was the core of the project.</p><p>But that’s easier said than done. The new system used rules instead of configuration. Each campaign would basically have a program that had to run in order to figure out whether to bid on an impression or not.</p><p>Suddenly, all the optimizations we had in place to meet our CPU budget no longer applied, and we had to work out another way to optimize things.</p><p>So… how do we get there?</p><p>We had to solve quite a few nontrivial — nay, complex — problems in the process:</p><ul><li><strong>The Bidder Decision Tree </strong>(BDT): First, we replaced all the straightforward business logic code by a decision-tree-like structure that could quickly cull rules based on auction characteristics.</li><li><strong>Instrumentation: </strong>Since the BDT was so magical that it would be an inscrutable black box, and that wasn’t ok, we designed a whole new instrumentation system to measure all the decisions taken within the BDT with minimal overhead.</li><li><strong>The new UI itself: </strong>The new UI was indeed a complete rewrite from scratch, with microservices, Node.js and React. It was a massive undertaking.</li><li><strong>Data migration: </strong>The new model was radically different from the old model so, at some point, we had to transition databases, applications, everything to it. It was no small feat, especially since it had to be done without impacting day-to-day operations. It’s not like we could start the new system with a blank database and tell everybody to set everything up again, manually, from scratch. We had to come up with an unobtrusive transition plan.</li></ul><p>As you can probably tell from the preface, though, the project was as stressful as it was cool. Each step of the way encountered unexpected roadblocks, and was cause for many a flamewar.</p><p>Where to begin…</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FukMiDlCmdv2og%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2FukMiDlCmdv2og%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2FukMiDlCmdv2og%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/63cf916ca20b67042df29a447770b644/href">https://medium.com/media/63cf916ca20b67042df29a447770b644/href</a></iframe><h3>The Bidder Decision Tree</h3><p>Instead of processing campaigns one by one, caching results as we did before, we precomputed a decision tree optimized for whatever the current campaign setup is at the time. A greedy algorithm would be free to shape that BDT the way it best suited the current setup, making it a very flexible design.</p><p>The decision tree would trade offline CPU time with online CPU time. Building the tree would take a lot of CPU time, but the structure could then be shared by all bidders and that cost gets amortized in time and scale. It was a clear win, but not without its challenges.</p><p>The first version of the BDT had a rather naïve approach. We knew this, but we thought we could get away with it. Instead of building a truly optimal tree, we tried a heuristic that was fast and simple. At least in tests. As soon as we plugged it onto some real configurations, there wasn’t a machine that had enough RAM to finish the job. Those were some nicely wasted months, but it is par for the course for a complex rewrite trying to solve complex problems. Trial and error involves both trial… and error.</p><p>The next version of the BDT was an optimal tree, done in a straightforward, brute-force way. It took 6 hours to build, and weighed approximately 30GB. That was not ok. We had to update the BDT every 5 minutes.</p><p>Eventually, we got there; mostly by cleverly optimizing the tree, both in how it’s represented, with heuristic branch pruning, <strong>and</strong> massive parallelization of the build process.</p><p>There was no book we didn’t throw at it.</p><h3>Instrumentation</h3><p>Before this project, every time we decided not to bid for a campaign, we tracked an “NBR”. Quite descriptively, a non-bidding reason. Problem with that was that it was very hard to interpret. If the NBR for an auction was, say, “blacklisted publisher”, that didn’t mean it would have bid on a different publisher. NBRs weren’t easily interpreted as lost opportunities, and thus actionable recommendations, and we had to solve that.</p><p>We knew that when — not if — something didn’t work as intended, we would have a hard time diagnosing the issue. So we designed a whole new instrumentation system that let us measure all the decisions taken within the BDT with minimal overhead. Not only those that would result in a non-bid, but all of them. And I really mean minimal overhead. On the hottest paths, the instrumentation takes literally a single CPU cycle.</p><p>Getting there took way longer than we had estimated, evidencing the riskiness of such huge project rewrites. We thought we could do the instrumentation rather quickly, sloppily on a first version and then improve on it. However, when we put that sloppy PoC in pre-production, the performance was so abysmal we just couldn’t put that in production.</p><p>We had to spend way longer optimizing the thing down to an acceptable overhead than we thought, squarely putting the project off-schedule.</p><p>Yes, now we have a really nifty instrumentation system that we can use to diagnose and measure anything we need. It even produces easy to understand reports. We were even able to use it to thoroughly test the BDT in our test suite and in pre-production, which was probably a big part of why the whole endeavor succeeded.</p><p>But it came at considerable cost.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*GgqY-lgBfibU-25UgY68kw.gif" /></figure><h3>The new UI</h3><p>I did mention this all started as a purely-UI project. The UI team soon realized the original web app needed sweeping changes, so they set out to rewrite the whole thing “the modern way” from scratch. With new technologies to boot. React, Node.js, microservices, you pick the buzzword and we got it.</p><p>Seriously though, the original UI was a rather standard web 2.0 app, already showing its age, and the rewrite was long overdue. With React, Node.js, and a host of backend microservices to power them, the usability and maintainability improvements weren’t minor.</p><p>That’s not done overnight though.</p><p>But this was also the core of the project. We wanted to redesign the UI because the old one was just not well suited to our current workflow.</p><p>We didn’t just change the UI, however… and here it comes…</p><h3>Scope creep</h3><p>Microservices are great. I’m totally in favor of them, especially for connecting a web UI to its backend. It’s such a great way to work in the frontend…</p><p>But changing the workflow also meant changing that data model behind it. A data model is after all also a conceptual model, so if you’re trying to adapt your software to changing realities, no change is complete without a corresponding model change.</p><p>And a model change, especially if it involves a database with terabytes or even petabytes of historic data that you can’t throw away, is a huge change.</p><p>We had to turn everything upside down to do that model change, so it looked like the best time to also change a few things we always wanted to change, but hadn’t had the opportunity to.</p><h3>Rip that Database</h3><p>I mentioned microservices, I mentioned the bidder, and I mentioned the UI. Until now, the bidder and the UI communicated through a shared database. That was… chaotic, to put it mildly.</p><p>Both applications were hugely different in requirements and workload. The bidder serves half a million requests per second, whereas the UI serves just us, in our internal use of the system. Those workloads are so different that the two apps are always clashing in some way.</p><p>Even the teams maintaining them were different. Maintaining that shared database was not easy, so we decided it would be a great time to force the bidder to start using those new microservices. After all, we had a huge model change coming, and the microservices would be a great way to abstract that change away as much as possible.</p><p><em>And thus it started. Scope crept an inch forward.</em></p><p>It wasn’t really necessary. We just thought it would be the best time to attempt it. In hindsight, maybe we shouldn’t have. The project was big enough without that, and it wouldn’t come cheap in the end.</p><p>We thought it would help shield the bidder from the huge model change that was happening underneath, but in the end it wasn’t very effective in doing that either. It only served to add a dependency between the UI team and bidder team making team dynamic a lot more complex, and basically delaying the project.</p><p>In retrospect, we could have switched to microservices either before or after the redesign. That would have improved team independence, and a whole category of things that could go wrong would have vanished, making the project move that much faster and predictably as a result.</p><p>What’s worse, the database switch forced the project to be an all-or-nothing affair. We couldn’t do baby steps because the new system would work on a different database. It’s hard to be 100% certain, but I’m pretty sure we would have had a much smoother transition if we hadn’t compounded the problem by doing both things at once.</p><p>But, as always, hindsight is 20:20.</p><p>Which brings me back to the preface, and that issue of…</p><h3>Late ROI</h3><p>All of the above made the project unable to hit production before it was fully fleshed out. We <em>tried</em> to chop it into smaller chunks we <em>could</em> deploy, but there was still a huge last jump that was quite problematic.</p><p>As with all very long projects, it was hard to predict when it would be done. We revised our estimates a zillion times, each time delaying it a bit further. We revised the functionality a zillion times as well, trying to move the date back to where we wanted it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*AgggirlmfXmmIb-e.gif" /></figure><p>There’s a very weird dynamic in these huge projects that makes for a very <em>“fun”</em> experience.</p><p>On the one side, you want to fix a delivery date and stick to it. That’s useful, it puts a limit to scope creep, it informs the business side so they can make better decisions, and in general keeps everyone focused on the immediately useful goals.</p><p>On the other side, complex problems can’t be rushed. Sometimes the only resource a project needs to finish, is more time.</p><p>Manpower can’t be added. There’s a very famous saying in this regard, that I expect most already know: <em>“Adding manpower to a late software project, makes it later.”</em></p><p>Functionality can be removed only up to a point. If what delays you is the core of the project, you can only choose whether to invest the required time or not. And then there’s that sunk cost that keeps you from choosing to bail out.</p><p>Suffice it to say, that planning sessions were best watched with popcorn in hand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9MGHqgpM1t04L-tBC0pfgg.jpeg" /><figcaption>“Brace yourselves Silver is coming”</figcaption></figure><h3>How to cope with it</h3><p>During all this time, a sense of urgency starts to build up. At some point, you might be tempted to put all your eggs in the project’s basket, go all in, throw all your resources at it, finish it as quickly as possible and ignore everything else.</p><p>It’s a common reaction to think that, if all your development team is fully dedicated to finishing that rewrite, it will happen sooner. And then, you think, if it happens soon, then we don’t need to maintain the old system. Right?</p><p><strong>Resist the urge to freeze the “old system”.</strong></p><p>That system pays the bills. If you stop maintaining it, at some point, it will stop paying the bills, and you won’t have it either way.</p><p>As the old adage goes, <em>“if you don’t schedule time for maintenance, your equipment will schedule it for you”</em>. The same applies to software.</p><p>It’s best to spend a whole year on the rewrite, while keeping the legacy version relevant and able to sustain the business, than to spend 6 months on the rewrite to reach the end and find you no longer have a business, because your old system just couldn’t keep up with the business without maintenance.</p><h3>In the end</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Wc2zEQNqM7dhzAZm9pt2eA.jpeg" /></figure><p>Here we are. After the better part of a very hard year, working tirelessly to build a super-cool new version of our bidder, we have succeeded.</p><p>The switch to production was quite a rocky road, but that was to be expected. Such a big change is likely to present obstacles. All in all, I know how lucky we were to even finish. But it wasn’t just luck, it was the effort of not one team, but <strong>all of them.</strong></p><p>Probably the most important thing to make sure you succeed, is knowing that you may fail. That most of such endeavors fail. Be ready to make hard decisions, because they’re definitely in your future if you’re considering a rewrite. Set things up so that <strong>if you fail, you won’t go under</strong>, and learn how to recognize defeat early.</p><p>Otherwise, don’t let despair set in, it may be difficult to see the light at the end of the tunnel, but whether you see it or not, it’s there.</p><p><strong>Just keep calm, and keep coding.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=144b10dfff8b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/surviving-software-rewrites-144b10dfff8b">Surviving software rewrites</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Our take on mobile fraud detection]]></title>
            <link>https://medium.com/jampp-engineering/our-take-on-mobile-fraud-detection-bd6d3d045932?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/bd6d3d045932</guid>
            <category><![CDATA[ad-fraud]]></category>
            <category><![CDATA[adtech]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Jampp Geeks]]></dc:creator>
            <pubDate>Thu, 13 Jun 2019 20:55:15 GMT</pubDate>
            <atom:updated>2019-06-13T20:55:15.379Z</atom:updated>
            <content:encoded><![CDATA[<p>Jampp’s mission is to help companies grow their mobile business by engaging users and driving new customers. Combatting mobile fraud is a top priority to ensure this is possible. Other than spamming, phishing and scamming, ad fraud is one of the most profitable scenarios for rogue internet users. Mobile fraud forecasts for 2016 vary along $1.25bn (<a href="https://forensiq.com/mobile-app-fraud-study/">Forensiq</a>) and $7.2bn (<a href="http://www.ana.net/content/show/id/botfraud-2016">ANA</a>). Yes, you’ve read that correctly: impact is on the order of billions of dollars.</p><h3>What is it and how can it be done?</h3><p>The mobile ad business is fairly simple in monetary terms, some people, namely advertisers, pay to place their ads in a site whose owners we will call publishers. There’re a whole lot more players in between and around, but we’ll keep it simple for the moment. Publishers are the ones offering their advertising space for sale and advertisers are essentially bidding for that space. Most pricing models across the industry are proportional to ad impressions, click volumes and, recently, generated installs.</p><p>Technically speaking, clicks or impressions are not exactly what people would commonly think of. Under normal conditions clicks, impressions and events are HTTP requests being made between devices and servers, in response to user actions. To exemplify this, a simple diagram is given below. Here a click request bounces around different servers, one for each actor in the mobile advertisement ecosystem.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rpNBsXCDD1qIA9qH.png" /></figure><p>The user initially clicks on the ad and its user agent, device ID and other metadata are being URL-encoded in the request. Their request is passed along the chain until it is finally redirected to the App/Playstore where, ideally, the user would install<a href="#2e76">¹</a> and open the app. Then, an event-tracking SDK integrated to the advertiser’s application would report this type of in-app events back along the chain of requests. This action is named a <em>postback</em> request, which informs everyone that a user has opened the app, thus prompting an install.</p><p>The difficulty relies on actually verifying that the user’s reported action effectively happened and wasn’t just simulated. In all cases, this means establishing that a real touch on the screen or even an ad view. Faking a request or a real <em>action</em> is essentially not difficult.</p><p>Given the rules, costs and benefits of this game, you can imagine why scammers feel so encouraged to do their job. There you have it, that is mobile fraud.</p><h3>Fraud Categories</h3><p>The <a href="http://mediaratingcouncil.org/101515_IVT%20Addendum%20FINAL%20(Version%201.0).pdf">Invalid Traffic Detection and Filtration Guidelines Addendum</a> made by the MRA and the Mobile Marketing Association (MMA) defines two big categories of fraud according to their technical nature:</p><h3>General</h3><p>A “consistent source of non-human traffic”. This is covered by mobile bots, traffic from data center, virtual machines and traffic from proxies or VPNs. <a href="#2974">²</a></p><h3>Sophisticated</h3><p>Its defined by the property that significant human analysis and intervention are needed in order to detect it. The addendum’s non-exhaustive list includes certain examples like “hijacked devices; hijacked sessions within hijacked devices; hijacked ad tags; hijacked creatives; adware; malware; incentivized manipulation of measurements; content; falsified viewable impression…”. The common denominator being that there is an <em>real</em> user in the scheme, but the ad is not served correctly.</p><p>Simply put, most of the traffic involved in the general fraud category would be originated when a scammer runs programs that imitate mobile devices and human behaviour interaction with advertisements. The programs behind these schemes consist of obvious random-http-request scripts generating requests with tokens tuned for each specific source or ad network. General fraud traffic is represented in the type of invalid traffic from data centers, VPNs, malware and other similar scenarios where programs are impersonating human actions like viewing and clicking ads or even installing and generating in-app events. Typical countermeasures for this type of fraud involve using ip blacklists, user-agent filtering, checking correct device-id formats, and other direct filter measures.</p><p><a href="http://blog.checkpoint.com/2016/07/01/from-hummingbad-to-worse-new-in-depth-details-and-analysis-of-the-hummingbad-andriod-malware-campaign/">Hummingbad</a> malware campaigns are a recent example of sophisticated invalid traffic. Using rootkits, the malware gets to command and coordinate a huge botnet across millions of devices, generating most of its revenue from app installs. Yingmob is the organization responsible for this scheme employing up to 25 people in different project groups. The organization’s professional structure behind the campaigns involved managing interactions between highly complex modules and across different technical teams.</p><h3>Fraud Objects (Sites or IPs)</h3><p>By the arguments we mentioned before, one could assume that a scammer would represent theirself either as an IP or through a publisher/site. In some cases, also looking at device ids as possible fraud objects could be more favorable but even these are easily falsifiable and, in the end, the advertiser’s budget is going to the publishers. And here is where the scammer will be cashing their rewards. For the rest of this post we will be focusing the analysis on these two data points because masking IPs is not a simple task and because the publisher information is reliable (otherwise a scammer would never cash in their rewards).</p><h3>Fraud Types</h3><p>For this post, we will be looking at anti-fraud tools against both forms of invalid traffic, with focus on the following fraud types: Click Spamming, Mobile Hijacking and Action Farming <a href="#79ab">³</a>.</p><p>A brief outline of each type is given below.</p><h3>Click Spamming</h3><p>This type refers to programs that generate fake click requests programmatically. A scammer would first run tests to extract appropriate campaign URL tokens for a specific device type or location. Next, it would execute programs to generate a high volume of click requests, randomizing device-IDs and user agents at each iteration. The idea is to cash in from these requests and, as a surplus, randomly nail a would-be-organic install. The typical consequences of this scenario would be having huge volumes of clicks and impressions, low CVRs and high volume coming through a few network points or sites.</p><h3>Mobile Hijacking</h3><p>This happens when a user’s seemingly genuine app runs hidden ads and clicks in the background. In general, the program would be scripted to imitate human behavior as much as possible. The problem is that all common data points look valid i.e., the IP address and user-agent, as well as the device ID. The idea is that would-be-organic installs from this user will be then incorrectly attributed to this publisher. This scenario would generate high volumes across clicks and impressions. Low CVRs and better-than-average user activity are expected as well. Also, given that a scammer can’t control when the install is organically made by a user, the time delta analysis from click to install would result in very atypical distributions at the fraud object’s level (either publisher or IP).</p><h3>Action Farms</h3><p>The idea behind this scheme is fairly simple. Scammers would reward people all around the world for clicking ads and installing apps manually i.e., actual people are hired to click on ads and install applications. The amount of events to be reached by this scheme will definitely not be as big as in programmatic schemes, but put in monetary terms, where one install might equal one dollar means three hundred fake installs a day is no joke to any campaign’s budget.<br>We have even tracked cases to social network groups where people were openly being hired to “get paid for installing applications!”.</p><h3>Fraud Metrics</h3><p>Most of the obvious countermeasures are already standard across the industry: IP filtering, publisher blocking, foreign click filtering and detection of spikes in click or install requests. To add on these tools and concretely target the types of fraud we mentioned above, we expanded on a new set of detection tools.</p><h3>Population Ratio</h3><p>Given that IPs have the ability to be geolocated up to a certain extent, we can match an action’s IP to a region and compare the region’s population size vs the amount of clicks coming from that IP. This metric is simple but in some cases not reliable. There are times when click IPs are incoming from mobile carrier exit nodes situated in low density regions and where each node concentrates a big big part of the carrier’s traffic. A brief example of this tool is given below, this test was carried out on clicks with no fraud filtering and the top rates are shown:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/759/0*EyMSjM-TmWY5McT0.png" /></figure><p>Similar to the metric explained before, we compare geoIP regional mismatches between different actions, comparing across impressions, clicks, installs and events. This metric is expected to uncover only a few discrepancies because, as we mentioned before, masking an IP in a request is a difficult task and filtering invalid traffic this way is a common industry practice. In our experience, this ratio is rarely “unusual”, having average differences of the order of 0.7%. The following histogram shows geographical average mismatches at the publisher and campaign levels. A sample of 20k click-installs was used for this analysis.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/719/0*4nDCo2WPKF1Fk3Jl.png" /></figure><p>When focusing on the top discrepancy cases in unfiltered traffic, we are encountered with the following results which highlight differences in click and events geolocations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/0*Qp97Z3KZeHyfHxlW.png" /></figure><p>Notice that even though publishers are not the same, some campaigns appear more than once in this head. This type of information would raise suspicions towards click spamming or action farming where scammers would be resetting their IP address to hide high volumes of traffic from a single IP, thus creating a discrepancy with the past IP used for the click.</p><h3>Time Delta</h3><p>This relatively new metric has been in use by the people at <a href="https://www.adjust.com/fraud-prevention/">Adjust</a> and <a href="https://www.kochava.com/kochava-difference/fraud-detection/">Kochava</a>. It is built by measuring the seconds it takes between any two consecutive actions, for example from click to install. Note that this metric has already gone deeper in the funnel, giving specific information on every particular install. The idea behind this metric is that, in general, counting data gives rise to empirical distributions with specific properties. Most of the distribution’s mass would be concentrated in lower values and the decay would be exponential at first and almost constant at higher values. An example of this metric is shown below, where time between a click and an install is measured:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*3v4PJjGT2xq8XKvD.png" /></figure><p>The histogram shows a sharp decay for the lower values of the metric with an almost constant decay value for higher time deltas. These type of distributions also appear when focusing the analysis on specific applications. The following example is taken from the Classifieds vertical where the fraudulent publisher has been excluded:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*BlL9OyFDvP9DcGJt.png" /></figure><p>Notice that the two histograms shown before are essentially very similar in terms of their statistical moments when compared to more fraudulent samples. Once we focus on the fraudulent publisher, we find that the empirical distribution has evidently changed, and this change is reflected in statistical tests.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/454/0*jpiJ78UbwXvXFXoF.png" /></figure><h3>Performance Metrics</h3><p>For this tool, we are assuming that faking a device ID at the tracking platform’s SDK level would be a difficult feat. Thus we will be looking at click and install volume, CVR rates and the number of unique device IDs making installs in a given time interval. The idea is to see if there are significant anomalies when segmenting traffic per publisher or click IP.</p><p>These metrics are simple and based around standard industry metrics. Comparing top and bottom performance notches for each performer would give an insight into the condition of the traffic being acquired. However, it’s important to take special care before tagging an object with unusual behavior because it is common to have notable differences amongst verticals, sources and applications. Let’s see what unfiltered traffic would look like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/0*qKgH3rUdz-7Fwqsn.png" /></figure><p>Here observations are ordered by click volume. Notice the high volume incoming from the same IP range. Unique device ID rates look healthy though for this range, with a handful of cases where one device ID has multiple installs. However, the first row is more suspicious when you consider that, in average, every device ID using this specific IP has generated 1.3 installs.</p><h3>Some Final Comments on the Nature of Fraud Detection</h3><p>By now, it might have become evident to the reader that mobile fraud is, in essence, an <a href="https://en.wikipedia.org/wiki/Unsupervised_learning">unsupervised</a> problem. There is virtually no data, other than the obvious cases, to label any given click, install, view, or in-app event as fraud in an automatic, non-intrusive way. This concept is fundamental to the issue at hand. Looking at the techniques used in other industries, say banking, health or finance, some of them would have access to specific fraud cases (picture a credit-card charge dispute for instance) where fraudulent actions are duly tagged. For the rest of the cases they’d need to rely on unsupervised techniques.</p><p>As an example, imagine we measure some variable that tests out to be normally distributed. Then a toy anti-fraud tool would label all cases outside the 99.7% band. This is called outlier or anomaly detection <a href="#92fb">⁴</a> and the spirit is that, in a normal distribution, this band value equals to three standard-deviations from mean. But why is this band chosen? Should we choose two, three or four standard-deviations? What is standard about a standard-deviation? What if our distributions have fat-tails? (<em>DISCLAIMER: yes, this is our case</em>). The same goes for all statistical tools in Extreme Value Theory or Anomaly Detection: their applications must be handled with care and with attention to context (one measurement might be atypical in one context but not in others ). To sum up, there is no mathematically correct definition to characterize outliers, and by this, human input is inherently needed for the problem.</p><h3>References</h3><ol><li>Here an install is defined as the user’s first in-app event reported by the tracking platform.</li><li>There are legitimate cases of traffic coming from these sources such as from large organizations, universities and such; however this is not the general case.</li><li>We’ve evolved the term click farm into action farm to better suit the mobile world since having people manually click, install and use an app is also carried out as fraud. Remember that payback on installs is significantly higher than on clicks or views.</li><li>For a more accurate and complete overview of anomaly detection, a very useful survey on the topic can be found at <a href="http://cucis.ece.northwestern.edu/projects/DMS/publications/AnomalyDetection.pdf">http://cucis.ece.northwestern.edu/projects/DMS/publications/AnomalyDetection.pdf</a>.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bd6d3d045932" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/our-take-on-mobile-fraud-detection-bd6d3d045932">Our take on mobile fraud detection</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scoring our publishers]]></title>
            <link>https://medium.com/jampp-engineering/scoring-our-publishers-7063d57db375?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/7063d57db375</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[adtech]]></category>
            <dc:creator><![CDATA[Jampp Geeks]]></dc:creator>
            <pubDate>Thu, 13 Jun 2019 20:54:51 GMT</pubDate>
            <atom:updated>2019-06-13T20:54:51.796Z</atom:updated>
            <content:encoded><![CDATA[<p>At Jampp, we use a variety of sources to generate our traffic flow. Generally speaking, the source employed in one campaign is not necessarily the same as the one used in another. However, most platforms do not have a unified measure to compare the quality of the traffic sources. To create such measure, it is not as trivial or simple as comparing CTRs due to the aforementioned usage of different sources in different campaigns and because campaigns do not share the same post-install metrics (and we are precisely interested in post-install quality). In this entry, we briefly discuss how we have built an index that ranks our sources on a bi-monthly data basis.</p><p>When we started this project, despite our clear objective (basically creating a score that should reflect a particular source post-install quality), we were confronted with a wide set of choices. Many of those choices were related to the granularity level of the analysis: should we construct an index on a per app basis, a per vertical one (i.e a group of apps within a same category such as e-commerce or taxi) or use an overall classification. Even though a fine-grained classification can be summarized into a coarser one and vice-versa, the data wrangling requirements hinge critically on this decision. For instance, choosing to produce a vertical quality index implies first classifying apps into each vertical, then normalizing events within a vertical and only then, computing some desired conversion metric (events over clicks, opens, etc). On the other hand, if we resolve for a per-app ordering or a ranking based on a uniform event across apps, clearly most of the steps just mentioned are not required.</p><p>Given the tradeoff between readiness in analysis and wrangling, we decided to classify sources on a per-vertical and country basis. For each source, we then aggregate across verticals and countries to generate an overall ranking. To do so, we employed two types of metrics depending on the campaign type. For user acquisition campaigns, we used a key-event based metric. For retargeting campaigns, we used a retention-centered event (a standard key event is a purchase whereas an open is the prototypical retention event). Essentially, in both cases we first computed conversion ratios: for each vertical within a given source inside a given country, we counted the number of unique key or retention events in two months. We then divided this number by the amount of installs for that vertical and source inside a country.</p><p>It would have been nonsensical to directly compare the ratios produced by the procedure described above. To understand why we considered the following scenario: if in April and May we found out that there were 10 installs from source <strong>x</strong> and 1000 from source <strong>y</strong> and respectively 1 and 100 key events, then the conversion rate would be in both cases 0.1. Should these sources share the same ranking? Clearly source <strong>y</strong> is better at a volume wise level. Therefore in order to make ratios comparable, we need a transformation that ensures that sources with a resembling final index not only have similar conversion rates but also congruent volume.</p><p>What transformation should we use? There are a number of alternatives and the choice is doubtlessly arbitrary. However, since we strive for statistical consistency, we settled for defining a penalty function that corrects the conversion rates according to the sample size required by a specific width of a 95% binomial proportion confidence interval. Let’s break that last sentence down.</p><p>Assume we can model conversion scenarios as a binomial random variable with parameter <strong>p</strong>. A 95% confidence interval for an estimator of <strong>p</strong>, call it <strong>p̂</strong>, is given by</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/474/1*BiSFuRjKR5V8zxkSKpL8Eg.png" /></figure><p>where <strong>n</strong> is the sample size. Subtracting the lower bound from the upper one, it is easy to see that the width of the interval, call it <strong>w</strong>, can be written as</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/254/1*5ZUGvVM9xHYvq0_g725aMQ.png" /></figure><p>Using the previous equation, we allowed <strong><em>w</em></strong> to vary (linearly) stepwise in the range <strong>[0.01,0.1]</strong> and solved for <strong><em>n</em></strong>. We then mapped the resulting sample sizes (which for our goal can be interpreted as number of installs) to a number, say <strong><em>P</em></strong> for penalty, in the interval <strong>[0,1]</strong>. The penalty mapping is constructed in such a way that if the number of installs for a given source in a given vertical is tiny (or equivalently the confidence interval is wide) then <strong>P=0</strong> (full penalty). If the volume is huge, (which translates to a narrow confidence interval) then <strong>P=1 </strong>(i.e no penalty). In other words, there is a direct relationship between the penalty and the interval width. We finally multiply <strong><em>P</em></strong> by the raw conversion rates to get our quality index.</p><p>In the next figure, we limited our attention to apps belonging to the classifieds vertical, and displayed the top ten sources in the United States according to the key-event quality index. We have normalized the index by the organic key-event to installs ratio (for the retention-event index we normalize by the highest value). In the image, we also show the number of installs for each source on the right hand axis. It can be seen, for instance, how applying the penalty implies diverging from a volume-centered measurement by comparing source <strong>a</strong> and source <strong>i</strong>. Despite having similar volume, the former is ranked first and the latter ninth.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/0*E_djWQQbqV3IuMBM.png" /></figure><p>In this post, we have briefly discussed how we have implemented a quality index that ranks our sources for both user acquisition and retargeting campaigns. We are constantly improving this. For instance, to check the robustness of the engagement index we could compare it to some drop-off based measurement such as the number of people engaged at a given day or the first day a drop-off falls below a certain threshold. We will also further automate this. Currently, we use the handy <a href="https://github.com/ZoomerAnalytics/xlwings">xlwings</a> library to port our Pandas dataframes and Matplotlib plots to nicely format Excel spreadsheet reports which can then be easily shared with Google Sheets. Finally, our first empirical tests applying the index show that there is a clear correlation between the quality score and source post-install performance. After some obviously necessary fine-tuning, we might eventually incentivize and reward sources based on this score as <a href="https://developers.facebook.com/docs/audience-network/AOS">Facebook AOS</a> does (probably by paying a premium to the top source).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7063d57db375" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/scoring-our-publishers-7063d57db375">Scoring our publishers</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ITBA’s Big Data Present and Future Conference]]></title>
            <link>https://medium.com/jampp-engineering/itbas-big-data-present-and-future-conference-a61d029a5bee?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/a61d029a5bee</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[rtb]]></category>
            <category><![CDATA[programmatic-advertising]]></category>
            <category><![CDATA[adtech]]></category>
            <dc:creator><![CDATA[Jampp Geeks]]></dc:creator>
            <pubDate>Thu, 13 Jun 2019 20:54:24 GMT</pubDate>
            <atom:updated>2019-06-13T20:54:24.835Z</atom:updated>
            <content:encoded><![CDATA[<p>On May 18th, our data team participated in the “Big Data: Present and Future in Argentina” conference organized by the Buenos Aires Institute of Technology (ITBA).</p><p>Several companies that are currently working with technologies considered as part of the Big Data ecosystem or building their own attended this event.</p><p>Juan Echagüe head of the research team at Pragma Consulting gave the first presentation. He started by giving his perspective on the topic of Big Data and the current state of affairs. After that, he gave an overview of some of the project his team worked on during the last couple of years like analysing trip data for the public transit system.</p><p>Guido de Caso and Santiago Pérez from Medallia came next. They talked about how they scaled their in-memory OLAP engine. They run mostly on bare metal and they take advantage of many of the recent hardware trends like SSDs becoming really cheap and networks reaching 40–100 Gbps to horizontally scale their engine without loosing too much performance when data does not fit in a single machine’s RAM.</p><p>Jorge Brea from Gran Data was the following speaker. His presentation focused on inferring demographics attributes about different populations basing their analysis only on data from mobile phone calls and social media. They are working with Apache Spark to scale their solution.</p><p>Gustavo Arjones, CTO and co-founder at Socialmetrix, talked about how his company evolved their data platform for social media analytics. 7 years ago, they started with a single self-hosted machine that handled crawling, processing, storing and displaying of the data. They have evolved to a point where they are now using over 300 virtual instances in Azure Cloud with technologies like Java, Scala, Spark, Redis, MongoDB and Cassandra mainly.</p><p>Next came Andrés Moratti from Flowics. He focused on how they achieve real-time data processing with Kafka, Storm, RabbitMQ and Hadoop to enable new forms of interactions through Social Media with different live events like TV shows, recitals and big sporting events.</p><p>Sergio Uassouf from SAS presented their offering of SAS Visual Analytics for doing simple and powerful in-memory Big Data analytics alongside Hadoop. He showed a live demo about doing several common data analytics tasks over a data set of 600 million rows with response times of seconds.</p><p>Julián Klas and Adrián Quilis gave the last talk of the day. They have both been working at MercadoLibre for a long time. Julián works building Mercado Libre’s own A/B testing platform using Big Data tools like PrestoDB and Adrián works in the Business Intelligence team with Teradata and other warehouse style systems. They described how each platform was built and the reasons for it. It was specially interesting for us to hear how they moved from a Hadoop cluster in their local cloud to running Presto on the AWS Cloud and using S3 as a Source of Truth, since we are also using the set up in a somewhat smaller scale. One thing emphasized during the whole presentation was that, since MercadoLibre is such a big company, they are focused 100% on building tools that will allow access to the data to be completely self service.</p><h3>Our Session</h3><h4>Programmatic ad buying: How to build an intelligent and scalable, real-time bidding platform</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*DyNoRu67jI_ZgmvZ.jpg" /></figure><p>Martín Bonamico and myself were the ones representing Jampp. At the beginning we gave an overview on how the programmatic ads market for mobile works. Later we took the audience through the evolution of Jampp’s data platform: from the early beginnings when we only used MySQL and PostgreSQL in a very traditional data architecture, to the last iteration that enables near real-time event processing with Amazon Kinesis and Lambda. You can see our presentation below.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.slideshare.net%2Fslideshow%2Fembed_code%2Fkey%2FMSKnvOEoHsUtuz&amp;url=https%3A%2F%2Fwww.slideshare.net%2FJampp%2Fbuilding-a-realtime-scalable-and-intelligent-programmatic-ad-buying-platform-62233250&amp;image=https%3A%2F%2Fcdn.slidesharecdn.com%2Fss_thumbnails%2Fjamppdataarchitecturebigdataitba2-160520160249-thumbnail-4.jpg%3Fcb%3D1463760789&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=slideshare" width="600" height="500" frameborder="0" scrolling="no"><a href="https://medium.com/media/1f2897ec64d71dd1264f437ecd2f2162/href">https://medium.com/media/1f2897ec64d71dd1264f437ecd2f2162/href</a></iframe><p>We had a very positive experience taking part in this event. It showed that the ecosystem of developers dealing with large scale data processing challenges is growing at a steady pace. Although each company uses its own combination of tools and components, we could see some clear patterns emerging:</p><ul><li>The move to Public Cloud providers like AWS to outsource infrastructure maintenance work.</li><li>The trend towards using tools for SQL over Hadoop like Presto.</li><li>The evolution towards a real-time architecture to keep up with the needs of the market.</li></ul><p>Finally, we want to thank ITBA for inviting us to participate, and all the other speakers for contributing to make such a great event.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a61d029a5bee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/itbas-big-data-present-and-future-conference-a61d029a5bee">ITBA’s Big Data Present and Future Conference</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Julia for safe Data Science]]></title>
            <link>https://medium.com/jampp-engineering/using-julia-for-safe-data-science-56357da62352?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/56357da62352</guid>
            <category><![CDATA[julia]]></category>
            <category><![CDATA[data-science]]></category>
            <dc:creator><![CDATA[Jampp Geeks]]></dc:creator>
            <pubDate>Thu, 13 Jun 2019 20:54:08 GMT</pubDate>
            <atom:updated>2019-06-13T20:54:08.707Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently in Jampp, I had the chance to switch some of our data science environment from Python to Julia. For various reasons, its type system is, in my opinion, one of the best language features. The most obvious one is the performance enhancements it allows. I will not, however, address that point here: it has been benchmarked very well in several places. Instead, I will briefly show a safety advantage this type system brings that is really handy for data science.</p><p>To be fair, this feature is handy in a production oriented data science team. Someone more oriented towards analytics, might not find it so helpful. Quoting <a href="https://medium.com/@rchang/my-two-year-journey-as-a-data-scientist-at-twitter-f0c13298aee6">Robert Chang</a>, I perform Type B data science: models I build are meant to get into production. Therefore, safety issues are a big concern when implementing them. If we don’t catch a misbehaviour in our Machine Learning systems, we will be running our business based on mistaken metrics. For example, bidding high prices for bad banners millions times a day…</p><p>So, let’s get to the point. When you deal with hundreds of thousands of messages per second coming from a number of sources, you learn one thing: every field will eventually receive at least one ill-formated message. It is true, and not only for data science, that a smart use of types in a language helps you finding mismatches early in the data handling process. Take this toy example and look when Python realizes there is something wrong with the message and what Julia does:</p><p>Here is Python’s version:</p><pre><strong>import</strong> pandas <strong>as</strong> pd<br><strong>import</strong> numpy <strong>as</strong> np<br><br><em>#I received a few messages</em><br>df = pd.DataFrame(np.round(np.random.rand(<strong>1000</strong>, <strong>200</strong>)),<br>          dtype=float,<br>          columns = [&quot;Attribute{}&quot;.format(d) <strong>for</strong> d in range(<strong>1</strong>,<strong>201</strong>)])<br><br><em># Well, some message didn&#39;t follow the expected pattern...</em><br>df.ix[<strong>1000</strong>,<strong>1</strong>:] = np.round(np.random.rand(<strong>199</strong>))<br>df.ix[<strong>1000</strong>, &quot;Attribute1&quot;] = &quot;1.0&quot;<br><br><em># Python realizes the mismtaching types but it doesn&#39;t complain,</em><br><em># just casts one column to object</em><br><br><em># Several Lines of code either not using Attribute1 ...</em><br><em># ...</em><br><em># ...</em><br><br><em># Or like:</em><br>df.groupby(&quot;Attribute1&quot;).sum()<br><em># The grouping is wrong, though...</em><br><br><em># ...</em><br><em># ...</em><br><br><em># Ok, I need to process 20 given attributes,</em><br><em># one of them is Attribute1</em><br>attributes_needed = [<strong>1</strong>]<br>attributes_needed += np.random.choice(range(<strong>2</strong>,<strong>201</strong>),<strong>19</strong>, replace=False).tolist()<br><br><em>#DISCLAIMER: this is an inneficient loop, it is only for illustrative purposes.</em><br>columns_needed = [&quot;Attribute{}&quot;.format(d) <strong>for</strong> d in attributes_needed]<br><strong>for</strong> r in df.ix[:, columns_needed].iterrows():<br>    r[<strong>1</strong>].prod()<br><em># Now there is no way out, Python complains and this exception is thrown:</em><br>...<br>...<br>...<br>TypeError: Can&#39;t multiply sequence by non-int of type &#39;float&#39;</pre><p>And Julia’s one:</p><pre><strong>using</strong> DataFrames<br><br><strong><em>#I received a few messages<br></em></strong>df = DataFrame(round(rand(<strong>1000</strong>,<strong>200</strong>))) <br>names!(df, [Symbol(&quot;Attribute$i&quot;) <strong>for</strong> i in <strong>1</strong>:<strong>200</strong>])<br><br><strong><em>#Well, again, some message didn&#39;t follow the expected pattern...<br></em></strong>push!(df, [[&quot;1.0&quot;] ; round(rand(<strong>199</strong>))])<br><br><strong><em>#But this time, Julia complains at this point, and throws this:<br></em></strong>ERROR: ArgumentError: Error adding <strong>1.0</strong> to column :x1. Possible type mis-match.<br>in push! at /home/cristian/.julia/v0<strong>.4</strong>/DataFrames/src/dataframe/dataframe.jl:<strong>883</strong></pre><p>In Python, I added the message in my data-frame and even processed the data without noticing the mismatch. Only eventually (and by chance) I got an exception. In contrast, in Julia, the very insertion attempt of this message to the data-frame results in an exception being thrown. Julia’s type system and the promotions implemented for it are flexible enough to allow for easy data handling (I could receive those ones either as Floats or Ints). But at the same time, they are not so liberal as to cast everything to a highly abstract class (as object), enforcing, thus, some checks (I cannot receive a String where a Number is expected). It may be argued that, with proper checking, this safety can be achieved using any language. Fair enough, I’ll concede that. But still, one would have to implement it. In Julia, it comes for free.</p><p>In a pure analytical or exploratory level, handling these issues might be considered, in the best cases, annoying and corrected by hand. But if a model is running in production, anything unexpected in a message should be catched as soon as possible, dealt with and, only then, finally processed. You could be doing a spurious training if ill-formed messages get through your models. As in many other aspects, when dealing with promotions Julia achieves a nice balance between flexibility and safety.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56357da62352" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/using-julia-for-safe-data-science-56357da62352">Using Julia for safe Data Science</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PrestoDB on Amazon EMR at Jampp]]></title>
            <link>https://medium.com/jampp-engineering/prestodb-on-amazon-emr-at-jampp-29c6663b5c?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/29c6663b5c</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[data-infrastructure]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Jampp Geeks]]></dc:creator>
            <pubDate>Thu, 13 Jun 2019 20:53:28 GMT</pubDate>
            <atom:updated>2019-06-13T20:53:27.912Z</atom:updated>
            <content:encoded><![CDATA[<p>At Jampp we are big users of Amazon EMR. Since we handle a lot of data, our volumes keep growing and we have a lot of unstructured log data. Amazon EMR was a great fit for a lot of the use cases we had for analytics and log forensics.</p><p>We really like the versatility EMR provides with the apps available like PrestoDB, Spark and Hive. It doesn’t limit you to one kind of processing since you can do batch, interactive and real-time workloads mixed with some Machine Learning magic. In particular, we found in PrestoDB a great tool that gave us speed and flexibility and was much more robust than Spark SQL as a SQL tool for large scale analytics. As our use of Presto grew, we even got featured in the Amazon <a href="https://aws.amazon.com/elasticmapreduce/details/presto/">PrestoDB product page</a>.</p><p>Our production cluster executes daily ETL tasks and contains a warehouse stored in Parquet backed tables, which is queried by OLAP processes through PrestoDB and Spark. These daily and hourly ETL jobs extract data from different sources like RDS databases and log files and centralize everything in the EMR Cluster. We found <a href="https://github.com/airbnb/airflow">Airflow from AirBnB</a> to be a great tool for orchestrating these workflows and we will talk more in detail on how and why we use it on a later post.</p><p>During this post, we will focus on our experience with Presto and the different customizations we implemented and nuggets of wisdom we learnt along the way.</p><p>Using Presto through Amazon EMR’s apps enabled us to get up and running quickly and scale capacity as needed during peak hours. We were also able to quickly analyze the enormous amount of logs that we have been dumping on S3, using tables defined in Hive with regular expressions. Also, we could combine this information with data from relational databases that we had previously imported to the cluster or that was directly in the databases. Over time we tuned a lot of Presto’s configuration files and add monitoring, using a bootstrap action.</p><p>One problem we had with EMR 4.x is that bootstrap actions are executed before all the EMR apps like Hadoop, Presto, Spark, etc. are installed. In our case we needed to configure Presto and additional programs after Presto was installed. Because of this we developed a way in the bootstrap script to wait for the Presto process to be installed before continuing with the configurations steps. You can get an idea of how to achieve this in the following thread we answered in the AWS forum: <a href="https://forums.aws.amazon.com/thread.jspa?threadID=220183&amp;tstart=25">https://forums.aws.amazon.com/thread.jspa?threadID=220183&amp;tstart=25</a></p><p>Since we moved the cluster to VPC, and one of the databases from which we import data into the cluster is in EC2 classic, we had to add Classic Link between the cluster and the Amazon RDS database. The cluster grows and shrinks during the day, so we created a script that we execute every time a node is bootstrapped. The script adds new nodes to the db’s security group whenever the number of nodes in the cluster is increased. Here is the script in case you need to replicate this behaviour:</p><pre><em>#!/bin/sh</em><br><br>AWS_REGION=&quot;--region us-east-1&quot;<br>AWS_PROFILE=&quot;&quot;<br>AWS_FILTERS=&quot;Name=tag:aws:elasticmapreduce:job-flow-id,Values=<strong>${</strong>EMR_CLUSTER_ID<strong>}</strong> Name=tag:aws:elasticmapreduce:instance-group-role,Values=TASK&quot;<br><br>RDS_SG=&quot;<strong>${</strong>EMR_RDS_SG<strong>}</strong>&quot;<br><br>task_ips=<strong>$(</strong>aws ec2 describe-instances \<br>    <strong>${</strong>AWS_PROFILE<strong>}</strong> \<br>    <strong>${</strong>AWS_REGION<strong>}</strong> \<br>    --filters <strong>${</strong>AWS_FILTERS<strong>}</strong> |\<br>  awk &#39;/PublicIpAddress/ { print $2 }&#39; |\<br>  tr -d &#39;&quot;,&#39;<strong>)</strong><br><br>current_ips=<strong>$(</strong>aws rds describe-db-security-groups \<br>    <strong>${</strong>AWS_PROFILE<strong>}</strong> \<br>    <strong>${</strong>AWS_REGION<strong>}</strong> \<br>    --db-security-group-name <strong>${</strong>RDS_SG<strong>}</strong> |\<br>  awk &#39;/CIDRIP/ { print gensub(&quot;^\&quot;(.*)/32\&quot;,?$&quot;, &quot;\\1&quot;, 1, $2) }&#39;<br><br><strong>)</strong><br><br><strong>for </strong>i <strong>in</strong> <strong>${</strong>task_ips<strong>}</strong>; <strong>do</strong><br><br>  [ -n &quot;<strong>$(</strong>echo <strong>${</strong>current_ips<strong>}</strong> | grep <strong>${</strong>i<strong>})</strong>&quot; ] &amp;&amp; <strong>continue<br><br>  </strong>echo &quot;Add <strong>${</strong>i<strong>}</strong>&quot;<br><br>  aws rds authorize-db-security-group-ingress \<br>    <strong>${</strong>AWS_REGION<strong>}</strong> \<br>    <strong>${</strong>AWS_PROFILE<strong>}</strong> \<br>    --db-security-group-name <strong>${</strong>RDS_SG<strong>}</strong> \<br>    --cidrip <strong>${</strong>i<strong>}</strong>/32<br><br><strong>done<br><br>for </strong>i <strong>in</strong> <strong>${</strong>current_ips<strong>}</strong>; <strong>do</strong><br><br>  [ -n &quot;<strong>$(</strong>echo <strong>${</strong>task_ips<strong>}</strong> | grep <strong>${</strong>i<strong>})</strong>&quot; ] &amp;&amp; <strong>continue<br><br>  </strong>echo &quot;Revoking <strong>${</strong>i<strong>}</strong>&quot;<br><br>  aws rds revoke-db-security-group-ingress \<br>    <strong>${</strong>AWS_REGION<strong>}</strong> \<br>    <strong>${</strong>AWS_PROFILE<strong>}</strong> \<br>    --db-security-group-name <strong>${</strong>RDS_SG<strong>}</strong> \<br>    --cidrip <strong>${</strong>i<strong>}</strong>/32<br><br><strong>done</strong></pre><p>As our usage of Presto grew, we developed many ways of improving its performance and stability.</p><p>One common issue with Presto is that, when handling a join between two large tables, Presto’s process, in the node that is making part of the join, might be killed due to <strong>OoM exception</strong>. Since most of the queries we run in Presto are for analytics, it is not a big issue for us if one of the queries fails. But, as Amazon EMR is configured by default, once a Presto process dies, there is no monitor that restarts it. Therefore, when you run many large queries, the nodes available for Presto to process data were decreasing over time. To fix this issue, we run a bootstrap action for each node in the cluster that installs and configures <a href="https://mmonit.com/monit/">Monit</a> to monitor the Presto service in each node.</p><p>In the <strong>config.properties</strong> file we added:</p><pre>query.max-age=50m #maximum time a query can take<br>query.client.timeout=40m #maximum time a query can run from a client like presto-cli</pre><p>We also found out we needed to do a general increase in the timeouts in the <strong>hive.properties</strong> file:</p><pre>hive.s3.connect-timeout=5m<br>hive.s3.max-backoff-time=10m<br>hive.s3.max-error-retries=50<br>hive.metastore-refresh-interval=1m<br>hive.s3.max-connections=500<br>hive.s3.max-client-retries=50<br>connector.name=hive-hadoop2<br>hive.s3.socket-timeout=5m<br>...<br>hive.dfs-timeout=1m<br>hive.dfs.connect.timeout=2m<br>hive.metastore-timeout=1m</pre><p>One final important alteration to Presto’s config was to change the <strong>jvm.config.</strong> We increased the heap to use at least 60% of the available RAM in the node since Presto would be the most resource-hungry process running on it. Also, we changed the garbage collector to use <strong>G1GC Garbage Collector</strong> rather than the Concurrent Mark Sweep GC which is currently the default. If you want good reference material on why the G1GC is a good option for this kind of applications check <a href="https://databricks.com/blog/2015/05/28/tuning-java-garbage-collection-for-spark-applications.html">this post</a> from the Databricks Blog.</p><p>Other important aspects to consider when tuning Presto to improve its performance are the following useful session properties:</p><ul><li><strong>hive.force_local_scheduling</strong> forces scans to occur locally where the data resides. In the case of EMR it forces scans to happen in the CORE nodes and avoid the increase in network bandwidth usage that would happen if scans were done in a TASK nodes.</li><li><strong>hive.parquet_predicate_pushdown_enabled</strong> pretty self explanatory.</li><li><strong>hive.parquet_optimized_reader_enabled</strong> enable optimized Parquet reader for PrestoDB. This reader is still experimental but we have tried most of the usual queries we use and haven’t found differences with the legacy reader. We still only use it in queries where approximate results are acceptable.</li><li><strong>task_intermediate_aggregation</strong> this option forces intermediate aggregation of results which improves the performance of queries that do aggregations over very large data sets.</li><li><strong>hash_partition_count</strong> the number of partitions for distributed joins and aggregations. The default for Presto in EMR is 8 which is good for only a small cluster. If you have a cluster with more than 8 nodes that do processing and you are running a query that contains a big join, it is a good idea to set this number to a higher value.</li></ul><p>Finally, there were a couple of issues we faced in some of the EMR versions. I will leave the solutions we found here, in case you run into any of them.</p><p>The first issue had to do with some problems with Presto’s connection to the Hive Metastore to retrieve table metadata. After some use, the connections were timing out and we found that this was originated by EMR switching to the MariaDB connector. In the link below, you can find a post from the EMR blog detailing this issue and our answer on how to fix it: <a href="https://forums.aws.amazon.com/thread.jspa?threadID=220302&amp;tstart=25">https://forums.aws.amazon.com/thread.jspa?threadID=220302&amp;tstart=25</a></p><p>The second issue was that in some EMR versions, the file descriptors and processes limits for the <strong>presto</strong> user is set to the default. We fixed it by adding the file <strong>/etc/security/limits.d/presto.conf </strong>during the node bootstrap script execution, with the following content:</p><pre>presto - nofile 32768<br>presto - nproc  65536</pre><p>This brings us to the end of the post. As you might have seen we did a lot of tuning of Presto which was a result of having this tool running in production for almost a year. Although much was done, this is still a work in progress.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29c6663b5c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/prestodb-on-amazon-emr-at-jampp-29c6663b5c">PrestoDB on Amazon EMR at Jampp</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overview of Jampp’s platform]]></title>
            <link>https://medium.com/jampp-engineering/overview-of-jampps-platform-96bccd372a2?source=rss----e7378711074e---4</link>
            <guid isPermaLink="false">https://medium.com/p/96bccd372a2</guid>
            <category><![CDATA[adtech]]></category>
            <category><![CDATA[data-infrastructure]]></category>
            <category><![CDATA[marketing-platform]]></category>
            <dc:creator><![CDATA[Jampp Geeks]]></dc:creator>
            <pubDate>Thu, 13 Jun 2019 20:52:14 GMT</pubDate>
            <atom:updated>2019-06-13T20:52:14.223Z</atom:updated>
            <content:encoded><![CDATA[<p>Jampp is a mobile app marketing company. Our platform helps mobile app advertisers to acquire and re-engage their users globally. This enables brands to go beyond simple installs and re-targeting clicks, as it optimizes for in-app activity and conversions, thus maximizing lifetime value.</p><p>Our intention in this initial post is to give a brief overview of the different systems that power our platform. In future posts we will delve deeper into most of the topics covered here and others.</p><p>Jampp markets apps by effectively buying programmatic ads. Our platform processes more than 200,000 RTB ad bid requests per second which amounts to about 300 MB/s or 25 TB of data per day. Additionally, Jampp tracks more than 6 billion in-app events (app installs, actions taken inside the app and contextual information used for user segmentation) per month. To effectively deal with this volume of information, we combine different technologies like ZMQ, PostgreSQL, SciPy, Cython and Memcache and especially compact data storage formats that eliminate redundancies.</p><h4>Jampp’s architecture is composed of four main subsystems that run in the Amazon Web Services (AWS) cloud:</h4><ul><li>a bidding system that implements the OpenRTB protocol and answers bid requests in less than 100ms;</li><li>a tracking system for clicks, installs and in-app events which lets us attribute an install or in-app event to a click on an ad;</li><li>an online supervised learning system that improves the bidder’s performance by trying to estimate conversion rates and how to explore the market in an efficient way;</li><li>a data processing platform that is constituted by different pub-sub systems with different guarantees that enable consistent sampling of all the data available in real-time and a cluster for scalable data processing.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/475/0*RS9GA44129X0PPk8.png" /></figure><p>The bidder system receives the bid requests for ad slots and decides whether to make an offer for a slot and the amount to offer. The bidder relies on two data sources. The first is a database which contains the ad campaigns’ data configured by the campaign managers through a web application. The second one is a PostgreSQL database which contains aggregated metrics that are used to adjust the pace at which a campaign budget is spent. The bidding system is composed by a variable amount of processes implemented in Tornado (a Python framework). These processes run on Amazon instances inside an Auto Scaling Group which uses Spot Instances to optimize costs. This AS is located behind an Amazon ELB instance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/0*_TgpdICjScyVFQfS.png" /></figure><h3>Caching and pacing</h3><p>Due to the bidding system’s distributed nature and the need to implement a pacing algorithm to regulate expenditure, some communication exists between the different machines that compose the bidding system. The actual money spent bidding can be modeled as a random process, due to multiple external factors like the existence of other RTB systems. This problem can be conceptualized in the following formula:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/438/1*8zhkX4kCibCVwJwDTHQ7zw.png" /></figure><p>Where <strong><em>S</em></strong> represents the estimated money spent every 1000 impression, <strong><em>P</em>ᵥ</strong> the clearing price, <strong><em>P</em>ᵦ<em> </em></strong>the offered price (the bid), <strong><em>W</em></strong> winning the auction and <strong><em>R </em></strong>represents the contextual information provided during the bid request. With this expense estimate, we can update the pacing algorithm’s current state, by adjusting the bidding system’s current behaviour according to the expected outcome of each offer and periodically synchronizing with the database to get the actual cost tracked. This way the system can run a stable operation with a low communication overhead with the database. To implement the pacing algorithm it needs to consult both databases, and compute metrics and plans (expenditure projections according to the configured parameters). These operations are expensive in terms of computational costs and, due to the strict latency requirements, have to be done in an asynchronous manner. To alleviate this problem we implemented a caching architecture with various levels which is shown in the following diagram:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/0*Zd_peObz9fhUQDLF.png" /></figure><p>The first cache level is located in an in-process data structure which guarantees immediate availability of the most important data. Cache misses on the first level can trigger a promotion from the lower levels or an asynchronous calculation, while the bidding system modifies its algorithm to work without the needed value or simply decides not to bid in the auction being processed. Since usually the same user is targeted by more than one ad, we assume that any missed opportunity will probably arise again once the necessary value is loaded in the cache. Coherence between the different caching levels is kept by communicating the different processes through a pub/sub system implemented with ZMQ. This mechanism enables the different processes to coordinate which values are being calculated so as to avoid duplicate calculations. Finally, if, for any reason, a value is invalidated or replaced, the lower and sibling cache levels are notified through this channel so they can also invalidate it and avoid split-brain issues.</p><h3>Bid computation</h3><p>To decide whether to bid and how much, we use similar metrics derived from machine learning algorithms. With metrics like the click through rate and the conversion rate:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/432/1*szPqdtyHL0FCBmnhspQDCQ.png" /></figure><p>We choose a price that, in average, will be profitable:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/472/1*SaroigwA84XO1LTJo3q_WQ.png" /></figure><p>Where <strong><em>P</em>𝘤</strong> is the price by objective that the client accepts, <strong><em>N</em>𝘤</strong> the amount of clicks in the sample, <strong><em>N</em>ᵢ</strong> the amount of impressions, and <strong><em>N</em>ₒ</strong> the amount of opens. After this, an internal auction between all campaigns whose business rules permit an offer for the current bid request is executed. For each campaign one randomly chosen creative is selected with a distribution that fosters the ones with the best performance. The winner of the internal auction is chosen randomly with a distribution based on the probability of winning the external auction and on expected profitability. This way, we can avoid starving the campaigns with worse performance, which is what would happen if we always chose the ones with the highest expected performance.</p><h3>Event tracking and stream</h3><p>The event tracking and attribution system is divided in two parts. The first one is an application written in Node.js which is horizontally scalable through an Auto Scaling Group and writes the data to a database and different Amazon Kinesis streams. In front of the Node.js we have an AWS Elastic Load Balancer to distribute the requests between the different instances that are part of the Auto Scaling Group. The tracking system receives clicks in ads placed by Jampp and registers the data needed to identify this device in the future. Afterwards, if the user continues down the conversion funnel, the system receives an install. Depending on the type of campaign that the ad belongs to, this install might be a conversion. Finally, the system receives in-app events like making a purchase (e-commerce application) or booking a taxi. These events can belong to devices that installed the app through a Jampp ad (attributed events) or through other channels (organic events). Attributed events are stored in a database to power dashboards that show the status of each campaign in real-time. These events are also published in different Kinesis streams to be replicated to other systems. Organic events, due to their volume, are only published in Kinesis streams. The bidding system also generates events like auctions, bids, wins, loses and impressions. Since the volume of these events is orders of magnitude larger than the ones from the tracking platform, we publish them through a PUB/SUB channel using ZMQ. The events are published by a set of processes called Bid Loggers, which are also in charge of filtering, aggregating and sampling the data to persist it in the Postgres database. The stream of events from the bidder is designed as PUB/SUB message stream without persistence so the only messages that are actually published are the ones which belong to topics that have actual consumers subscribed. When events are published, they are partitioned by a transaction id that is maintained throughout the whole chain of events: auction, bid, impression, click, in app event. This permits the consumers to do consistent sampling by subscribing to a particular partition and receiving all the associated events for one transaction. This capability is of vital importance when systems want to analyze the events’ data without being forced to handle 100% of the volume and avoid skewed results.</p><p>This was a very brief summary of some aspects of the systems we have in place at Jampp to effectively market apps.</p><h3>References</h3><p><a href="http://44jaiio.sadio.org.ar/sites/default/files/agranda14-30.pdf">http://44jaiio.sadio.org.ar/sites/default/files/agranda14-30.pdf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96bccd372a2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/jampp-engineering/overview-of-jampps-platform-96bccd372a2">Overview of Jampp’s platform</a> was originally published in <a href="https://medium.com/jampp-engineering">jampp-engineering</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>