<?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[Xeneta - Medium]]></title>
        <description><![CDATA[Xeneta is the leading ocean and air freight rate benchmarking and market analytics platform. - Medium]]></description>
        <link>https://medium.com/xeneta?source=rss----71f4429a370c---4</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Xeneta - Medium</title>
            <link>https://medium.com/xeneta?source=rss----71f4429a370c---4</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 12:28:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/feed/xeneta" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How we gave everyone at Xeneta a safe place to build apps with AI]]></title>
            <link>https://medium.com/xeneta/how-we-gave-everyone-at-xeneta-a-safe-place-to-build-apps-wtih-ai-2a824ca957bc?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/2a824ca957bc</guid>
            <category><![CDATA[internal-developer-portal]]></category>
            <category><![CDATA[zero-trust]]></category>
            <category><![CDATA[self-service-bi]]></category>
            <category><![CDATA[ai-assisted-coding]]></category>
            <category><![CDATA[kubernetes]]></category>
            <dc:creator><![CDATA[Ushan Kavinda]]></dc:creator>
            <pubDate>Wed, 28 Oct 2026 10:15:00 GMT</pubDate>
            <atom:updated>2026-10-28T12:53:47.779Z</atom:updated>
            <content:encoded><![CDATA[<p>With AI, building a real app stopped being an engineers-only thing. People across Xeneta started doing it, and the obvious next step was tools like Lovable or Replit. Fun, but insecure, expensive, and we’d have had no idea what was running where or what data it touched. We also tried a vendor solution for building internal tools. Too manual, no AI integration at the time, and its own AI builder wasn’t good. BI tools didn’t cover it either. Building a dashboard there is just as manual, and the moment you want something off the beaten path, a custom calculation, a different data shape, an action on the result, you are stuck or queuing for an engineer. So the question became: how do we give people somewhere to put these apps that’s safer and cheaper, without turning every internal dashboard into a full engineering project.</p><p>The answer is an internal developer platform we built ourselves. The portal is Backstage, the open-source developer portal from Spotify. Behind it sits a set of scaffolding templates, a Kubernetes cluster on AWS, and a plugin of Claude Code skills that encode how we build things. The platform itself was built with Claude by a two-person infra team, and the apps running on it get built the same way.</p><p>You open Backstage and fill in a short form. Seconds later you have a GitHub repository, a CI/CD pipeline, cloud infrastructure, login and a live URL. You open Claude Code in that repo and describe what you want. Our skills plugin tells Claude the house rules, so it already knows our conventions and you never have to learn them. Push your changes and the app is online a minute later.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vrlbryl0dkVN5_FfRoIL3g.png" /></figure><p>97 apps exist today, built by 50 different people, most of whom are not engineers. Our value consulting lead built a tool where you type in a prospect’s freight spend and volumes and see how they compare to peers in their industry, which used to be a request to data science. A lead data analyst replaced a monthly ritual of Power BI, Excel and PowerPoint with an app that scores every customer’s data health overnight. A product manager built a small portal where marketing manages the reports and webinars shown on the product homepage, instead of asking an engineer every time something changes. None of these needed a ticket to the tech team. Most of the people who built them couldn’t tell you what Kubernetes is, and they don’t need to.</p><p>The first version ran every app as its own container on AWS ECS with its own load balancer and its own stack of Terraform. It worked, but every new app meant minutes of infra provisioning and about $20 a month in load balancer cost before it served a single request. With 97 apps that adds up, and most of them are tiny. So we are moving to a single EKS cluster, Kubernetes managed by AWS. Apps are small containers packed densely onto a handful of machines, nodes are provisioned on demand with Karpenter and scale back down when idle, and all apps share one load balancer and one certificate. Deploys went from minutes to seconds, and the hosting bill went from roughly $1,300 a month to about $45. Roughly half the fleet has migrated so far.</p><p>An app doesn’t ship infrastructure code. It ships a short declaration of what it needs: a web address, a few secrets, some storage. A controller in the cluster turns that into real cloud resources, a container registry, an identity client, encrypted parameters, buckets and a permission role scoped to exactly those things. Secrets are set once by a human and never appear in code or logs. The pipeline refuses to deploy to production while any secret is still a placeholder.</p><p>Security is the part people ask about most, and fairly: 97 apps written largely by AI, by people who are not engineers, touching real company data. The answer is that the platform does the security, not the app. An app cannot be reached from the public internet, cannot see secrets it wasn’t given, cannot access cloud resources outside its own, and cannot skip login, because none of those are decisions the app gets to make. The most visible piece of that is login. You need to be on the company VPN, and traffic lands on the shared load balancer that sits in front of every app. That load balancer is where authentication happens, not in the app.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FVAKRC4FkNXjmdSFMuDekw.png" /></figure><p>When you hit an app URL, the load balancer checks for a valid session cookie. If there isn’t one, it redirects you to our AWS identity service (Cognito), which hands you on to our company identity provider (JumpCloud) via SAML, the same login you use for everything else. JumpCloud confirms who you are and which groups you belong to, that answer flows back through the chain, and the load balancer sets a cookie and lets you through.</p><p>The app only ever receives a request that already carries your verified identity in the headers. It trusts the load balancer and nothing else, and network rules make sure the load balancer is the only thing that can reach it, so there is no way around the front door. Each app gets its own registration in the identity service, created automatically from its declaration, and who can open which app is just a JumpCloud group. The app contains zero login code. For the person building it, single sign-on is not a task. It was always there.</p><p>The same approach covers the apps themselves. Every app runs under its own workload identity, not a shared service account. When it talks to our cloud or our data warehouse, it proves who it is with a short-lived token the cluster issues for that app alone, and the other side grants exactly what that app’s declaration asked for: these buckets, these tables, nothing else. There is no stored password anywhere, so nothing to leak and nothing to rotate. And we can answer, from configuration rather than archaeology, which app can reach which data.</p><p>It’s not finished. Cleaning up an app when it’s retired is still manual, and the ECS to EKS migration is mid-flight. But the core bet has held: make the safe path also the fast and easy one, and most people will happily never leave it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a824ca957bc" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/how-we-gave-everyone-at-xeneta-a-safe-place-to-build-apps-wtih-ai-2a824ca957bc">How we gave everyone at Xeneta a safe place to build apps with AI</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How much data is enough data — Part 1: Beyond numbers]]></title>
            <link>https://medium.com/xeneta/how-much-data-is-enough-data-part-1-beyond-numbers-29cab96d1148?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/29cab96d1148</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[statistics]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[analytics]]></category>
            <dc:creator><![CDATA[Ilko Masaldzhiyski]]></dc:creator>
            <pubDate>Tue, 31 Oct 2023 15:03:57 GMT</pubDate>
            <atom:updated>2023-10-31T15:03:57.709Z</atom:updated>
            <content:encoded><![CDATA[<h3>How much data is enough data — Part 1: Beyond numbers</h3><p>Navigating the fine line between too little and too much in the quest for actionable insights ⚖️</p><p>TL;DR</p><ul><li>📊 Explore the data and its characteristics</li><li>🧑‍🏫 Understand if the distribution is normal</li><li>💪 Use bootstrapping if the data is not normally distributed</li><li>👥 Choose a sample size to represent the population accurately</li><li>🌎 Consider the systemic biases in the data</li><li>🔜 Ensure observations are independent</li></ul><h3>Background</h3><p>At <a href="https://www.xeneta.com/"><strong>Xeneta</strong></a><strong>,</strong> we reveal the true picture of the ocean &amp; air freight markets through crowdsourced, real-time data. This transforms how freight is bought and sold by increasing the efficiency and alignment of logistics teams and their ability to uncover revenue opportunities in all market conditions.</p><p>Hence, data collection is a core part of <a href="https://www.xeneta.com/"><strong>Xeneta</strong></a>’s business model. By becoming the leading ocean benchmarking provider, with over 700 data providers and <strong>billions</strong> of prices, <strong>we faced a luxury problem — having too much data.</strong></p><blockquote>We faced a prioritization challenge aiming at expanding real-time coverage while maintaining accuracy. It was essential to determine when to delay importing more data for one trade lane and shift focus to another</blockquote><p>Instead of oversaturating a few thousand lanes with a lot of data, we balance the efforts on data collection across more lanes with the <strong>optimal amount</strong> of data.</p><p>This is where, in 2020, the question “<strong>How much data is enough data?</strong>” came to be. I and my partner in crime, Ahmet Vural, took a shot at answering this for <a href="https://www.xeneta.com/"><strong>Xeneta</strong></a>.</p><p>This question has a different degree of importance depending on the context. For your case, consider the following:</p><ul><li>How expensive is data collection?</li><li>How much time does data collection take?</li><li>How much data do you need before it’s too much data?</li></ul><p>If data is cheap and easy to collect, there’s no reason not to take it. However, your business must consider where is the point of diminishing returns.</p><p>Clearly, expensive or slow data collection will make the question of how much data you need more contentious. For us, there were scenarios where we would want to improve benchmarks on exotic trade lanes. In those cases, we might have to go after all customers and check if they have pricing information on those trade lanes.</p><blockquote>No matter what your business is, if you can’t get all the data, you have to make sure you collect <strong>enough</strong> of the right kind to give a representative picture</blockquote><p>In our case, this translated to <strong>finding the right amount of data that will represent real-world market pricing for shipping containers from port A to port B</strong>.</p><p>This is the first part in a series of posts describing how we solved this challenge.</p><h3>Understanding your data and the assumptions surrounding it</h3><p>Customers provide us with the cost of shipping a container from port A to port B. Once this data is cleaned, anonymized, normalized, validated, and aggregated, we can give our customers <a href="https://help.xeneta.com/en/articles/20-market-benchmarks">the price range</a> they will receive when negotiating with their suppliers. Information asymmetry is no longer hindering performance.</p><p>An essential factor in our case is understanding that the data we collect, regardless of the amount, should be considered a sample from a larger population of an unknown size. It is unrealistic that we collect all the pricing information for every single container out there.</p><p>Depending on the characteristics of our samples, we had to decide which type of statistical methods we should use — parametric or non-parametric.</p><p>Nonparametric methods are the kind we use when our data doesn’t fit neatly into common patterns or distributions. In contrast, parametric methods assume our data follows a specific distribution like the Normal or Gaussian distribution.</p><blockquote>If a data sample is not normally distributed, then the assumptions of parametric statistical tests are violated, and nonparametric statistical methods must be used.</blockquote><p>You can use various techniques to check if your data deviates from a Normal distribution called <strong>normality tests</strong>. Outside histograms, box plots, and QQ plots, the Kolmogorov-Smirnov and Shapiro-Wilk tests are worth using.</p><p>Our data goes through <a href="https://www.xeneta.com/blog/data-qualification-processes-for-customers">multiple cleaning stages</a> and is finally stored within a regional grouping called <a href="https://help.xeneta.com/en/articles/88-geo-hierarchy-methodology">Geo Hierarchy</a>. The assumption is that after all these steps, we reduce noise, remove outliers, and improve variance in our data.</p><h4>Check if the distribution of your data is Normal</h4><p>It’s always a good practice to visually inspect your data first.</p><p>Before jumping into analyzing all of our pricing data (more than <strong>4.3 billion prices</strong> as of June 30th, 2020), we visually explored some of the most densely saturated trade lanes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NiBcT0McnI9cuipNQsQyXw.png" /><figcaption><em>Annual development of distributions on five trade lanes with a lot of data</em></figcaption></figure><p>None of these five distributions are easily classified. It is easy to visually confirm that there are no Normal distributions, and after running the Shapiro — Wilk test, we comfortably rejected the hypothesis that these are Normal.</p><p>That’s too small of a sample to make conclusions, though. You should always ensure that your findings are based on enough good data. Hence, we further proceeded with exploring all of the available pricing data.</p><p>When looking at our data, we found that 24% of all analyzed trade lanes had a Normal distribution. However, those accounted for only 2.6% of all prices. No trade lane exceeding 500 contracts on a given day had a Normal distribution.</p><p>Thus, even though there were some indications that the data could follow a Normal distribution, it was concluded that this is highly unlikely.</p><h4>What were the most common types of distributions we saw in our data?</h4><p>We plotted the goodness of fit and estimated the best candidate using the least square error (LSE) method, whether a chosen distribution from the most common distributions summarizes our observed values.</p><blockquote>We wanted to understand if a given statistical model is more frequently seen across our data.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e3NnrLydBMZBq99C9Wd4GA.png" /><figcaption>Estimating goodness of fit using LSE</figcaption></figure><p>We tested for the following 32 distributions across hundreds of densely saturated trade lanes:</p><p>lognorm, exponnorm, gamma, alpha, beta, weibull_max, weibull_min, loggamma, rice, rayleigh, powerlognorm, powernorm, pareto, maxwell, loglaplace, logistic, laplace, invweibull, invgauss, invgamma, genlogistic, gengamma, gausshyper, fisk, exponweib, exponpow, expon, cosine, chi2, burr, cauchy, norm</p><p>The heatmap below visualizes the number of corridors that minimize the LSE function on a given day. There are a few contenders, but it’s apparent that the <strong>exponnorm </strong>distribution is ahead of the rest regarding the number of trade lanes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rHtTn6ry8j5fNeUTGEfSrw.png" /><figcaption>Heatmap illustrating how many trade lanes were described by a given distribution</figcaption></figure><p>The <strong>exponnorm</strong> distribution, or exponential normal distribution, is unique in its flexibility and capacity to fit many data types. In our case, this distribution consistently proved to be the most commonly observed in our data for 2019, reflecting a large number of trade lanes.</p><blockquote>This suggests that our data, and possibly the ocean freight market behaviors it represents, share similar patterns of variance and skewness that align with the characteristics of an exponentially modified Gaussian distribution</blockquote><p>The same observations were also valid when we looked at how many contracts were described by a given distribution type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b_HiKXe18fyzWr_p16JUgg.png" /><figcaption>Heatmap illustrating how many contracts on a given day were described by a distribution type</figcaption></figure><p>So far, we have seen that <strong>our data could not be modeled as Normal, but it conforms with Normal-Like models such as</strong> <strong><em>exponnorm</em></strong>.</p><h4>What if the distribution was Normal?</h4><p>We would be able to <a href="https://en.wikipedia.org/wiki/Margin_of_error">calculate the minimum sample size</a> based on the following criteria:</p><ul><li>Confidence level</li><li>Error margin</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/158/1*VBsRr8Ns1m75rHfPOg5krg.png" /></figure><p>Where <strong>n</strong> is the sample size, <strong>z</strong> is the value based on the confidence level, and <strong>MOE </strong>is the margin of error.</p><p>The <strong>z</strong> value can be chosen from the following table. You can find this table at the back of any book about statistics:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b96f7c0989943589653b2b35188af34d/href">https://medium.com/media/b96f7c0989943589653b2b35188af34d/href</a></iframe><p>If we further expand the above formula, we get the following number of observations needed in our sample sizes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c741c088db4822878bfd304a6d8f81cb/href">https://medium.com/media/c741c088db4822878bfd304a6d8f81cb/href</a></iframe><p>You can choose a sample size that works for your case based on the confidence interval and margin of error. For example:</p><blockquote>If we want to be 90% confident, with an error margin of 10%, that our prices represent the market on a given day, we would need at least 68 contracts on a given trade lane.</blockquote><h3>Use Bootstrap estimation if your data is not Normal</h3><p>In the “What if?” scenario, we assumed that our distributions were Normal and used a simple formula to obtain the required sample size based on a standard error.</p><p>However, as we saw in our data, sometimes it’s hard to meet assumptions like the one above.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LiSORjV3pwDijpsWA1KArA.png" /><figcaption>Normal distribution vs. one seen in our data</figcaption></figure><p>This is why and where the <strong>bootstrap method</strong> addresses these kinds of problems. Bootstrap estimation is a sampling with replacement method that allows you to understand your data better without making too many assumptions.</p><p>It works a bit like a lottery draw. Imagine you have a bag full of all possible prices we’ve seen on a trade lane. Now, you draw a handful of prices, write them down, and then put them back in the bag. You repeat this a certain number of times, each time writing down the average price of your handful. The result is a whole range of averages, which gives you a good idea of what to expect from the prices in the market.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*E8M7ha8LdBEbvmul9JUs7g.png" /><figcaption>Estimating population statistics using multiple samples. Image by Trist’n Joseph</figcaption></figure><p>We could write down the algorithm as follows:</p><ol><li>Draw a random sample with sizes n from a given trade lane</li><li>Compute summary statistics for the sample</li><li>Replicate X times for steps 1 and 2, and get X summary statistics</li><li>Get the <strong>mean </strong>and <strong>variance </strong>for these X statistics, resulting in an approximate of the market</li></ol><p>The number of repetitions must be large enough to ensure meaningful statistics, such as the mean, standard deviation, and standard error, can be calculated on the sample. At least try and have a minimum of 30 repetitions — the more, the better.</p><h4>Why would this work?</h4><p>The classic theorem <strong>Law of Large Numbers:</strong></p><blockquote>The average of the results obtained from a large number of trials should be close to the expected value and will tend to become closer to the expected value as more trials are performed.</blockquote><p>The Law of Large Numbers is like tossing a coin. While in a few throws, you might get heads 80% of the time, which doesn’t reflect the actual probability of 50%, if you toss the coin hundreds or thousands of times, the percentage of heads will get closer and closer to 50%. This is the essence of the law: the more trials you perform, the closer you get to the actual probability or expected value.</p><h3>Results</h3><p>Due to the amount of data and how computationally expensive this was, we randomly chose 400 trade lanes for every 1st and 15th day of 2019 and ran 100 trial samplings with 5, 10, 30, 45, 68, 100, 130, 200, and 350 prices on any given day. We simulated whether we could approximate the market metrics of our trade lanes using different sample sizes.</p><p>The difference between the estimated and actual values with a confidence level of 90% is visualized below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vtfc2cAU_PkSCHkT8SiE1Q.png" /></figure><p>It was interesting that the parametric and non-parametric methods produced almost identical results.</p><p>Hence, almost identical phrasing:</p><blockquote>If we want to be 90% confident, with a margin of error at 10%, that our prices represent the market on a given day, we would need at least 71 contracts on a given trade lane for that day.</blockquote><p>The results guided our decisions on the optimal number of prices to import immediately. This strategy expanded our coverage across trade lanes while maintaining accuracy.</p><blockquote>We could now offer accurate real-world benchmarks for an even larger number of trade lanes than before</blockquote><h3>Consider the systemic biases in the data</h3><p>The underlying assumption when simulating these results is that the pricing information we receive is composed of independent observations. However, this needs further investigation.</p><p>You should challenge such assumptions for your business case. The premise of independence in our pricing information is crucial because if observations are dependent, it may bias our results.</p><p>In our case, data from different customers might be dependent because of shared suppliers or alliances, creating correlations within the data. These correlations can distort our analysis if not accounted for, making it look like we have more information than we do. (This will be covered in pt.2)</p><p>Furthermore, the data itself comprises pricing provided by Freight Forwarders and Shippers. Ensuring that the composition is representative depends on the use case<strong>.</strong></p><p>In addition to testing for statistical significance, we considered <strong>factors such as Outlier Detection, the GINI coefficient, the number of containers shipped, and our customers&#39; industries</strong>.</p><h4>Outlier Detection</h4><p>Our process for outlier detection involves both statistical and domain-specific methods. Statistically, we employ techniques such as the IQR method and clustering. But beyond the numbers, understanding the maritime industry’s intricacies and temporal components was essential.</p><h4>GINI coefficient</h4><p>The GINI coefficient is a measure of inequality — in our case, we used it to assess the distribution of our data points within the different trade lanes in the context of data providers. A low GINI coefficient would indicate that our data points are evenly spread across data providers. In contrast, a high GINI would suggest an unequal distribution, with one customer responsible for most of the pricing data we get.</p><h4>Number of containers being shipped</h4><p>When considering representativeness, the volume of a given customer being moved should also be accounted for. We should have a representative spread across this dimension as well.</p><h4>Different industries</h4><p>We also factored in the variety of industries represented in our data. The pricing data could vary significantly across industries due to the differing requirements and market conditions. Hence, ensuring diverse industry representation would make our benchmarks more robust and applicable.</p><p>As mentioned before, there is a delicate balance in ensuring that our data is representative, which requires optimizing many parameters.</p><h3>Stay tuned for the next part, which further explores the independence of data</h3><p>As we’ve journeyed through the intriguing landscape of data collection, we’ve discovered the balance between too little and too much data, the importance of understanding the characteristics of data, and the novel ways in which we can make sense of it all.</p><p>However, our expedition into the world of data doesn’t end here. The independence of our pricing data is a bold assumption. In the upcoming second part of this series, we will dive into this critical aspect of data analysis, exploring how we navigated across this potential pitfall.</p><p><a href="https://www.xeneta.com/"><strong>Xeneta</strong></a> is always on the lookout for great talent. If you want to join us on our journey to revolutionize how freight is bought and sold, submit your application <a href="https://xeneta.pinpointhq.com/">here</a>.</p><p><em>Ilko Masaldzhiyski is a Data Science Director at Xeneta by day and an avid chess player by night. He’s also a dad who enjoys going to the cinema, playing video games, and reading.</em></p><p><em>Ahmet Vural is a Data Infrastructure Tech Lead at Xeneta — a real “human Swiss knife” when it comes to data. He’s a dad-to-be who enjoys wine, tinkering with all kinds of code, and can’t operate without music.</em></p><p><em>If you have passion and curiosity for data or want to discuss and exchange ideas, please don’t hesitate to reach out.</em></p><p><em>Thanks to Rajesh Bhol, </em><a href="https://medium.com/@migueljativa"><em>Miguel Jimenéz</em></a><em>, </em><a href="https://medium.com/@abdalla.elbedwihi_83530"><em>Abdalla Elbedwihi</em></a><em>, </em><a href="https://medium.com/@emil.korzen"><em>Emil Korzeń</em></a>, and <em>Dayna Goldman</em> <em>for reviewing and helping finalize this article.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29cab96d1148" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/how-much-data-is-enough-data-part-1-beyond-numbers-29cab96d1148">How much data is enough data — Part 1: Beyond numbers</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How We Moved From Traditional Login to Awesome Login]]></title>
            <link>https://medium.com/xeneta/how-we-moved-from-traditional-login-to-awesome-login-b89f75563c2a?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/b89f75563c2a</guid>
            <category><![CDATA[sso]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[xeneta]]></category>
            <category><![CDATA[mfa]]></category>
            <category><![CDATA[auth0]]></category>
            <dc:creator><![CDATA[Vignesh Jeyaraman]]></dc:creator>
            <pubDate>Wed, 02 Nov 2022 14:13:49 GMT</pubDate>
            <atom:updated>2022-11-24T21:21:13.184Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*2SIyCOZq-TOLpoojeWp8FQ.jpeg" /></figure><p>Like many other SaaS platforms, Xeneta had its own proprietary login system, which was secure and powered by the excellent code written by our awesome developers.</p><p>However, more and more of our enterprise customers have been requesting single sign-on (SSO), and since we’ve been looking to implement additional multi-factor authentication options anyway, we decided that the time was right for an upgrade.</p><p>Now, we had two options to choose from — to design, build and maintain a new system ourselves, or to find a third-party solution. Naturally, we went with the latter, and what follows below is a brief story of the problems we faced along the way and how we managed to solve them.</p><h3>What Is SSO</h3><p>Put simply, SSO is when you log in to one platform and automatically log in to multiple other platforms or services without having to re-enter your login information.</p><p>A perfect example of this is Google’s services — when you sign in to Gmail, you can also access other Google apps like YouTube or Drive. Single sign-on is something we all use in our daily life without even thinking about it.</p><h3>How SSO Works</h3><p>To get a better idea of how SSO actually works, let’s take a look at the diagram below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_2Oz2I-NTDX153oYZVGA2g.png" /><figcaption>Flow with SSO</figcaption></figure><p>There’s a lot going on in that diagram, so let’s break it down into individual steps:</p><ol><li>The user is browsing two websites (<strong>Step 1</strong> and <strong>Step 8</strong>).</li><li>Both websites have their domain and a way to log in to it.</li><li>When the user tries to log in, both of them redirect the user to a third domain, a central Auth Server verifying the user’s identity (<strong>Step 2</strong> and <strong>Step 11</strong>)<strong>. </strong><em>Auth Server here is any identity provider like Azure AD or Google, where organizations securely store their users’ identities</em>.</li><li>The user gets verified (<strong>Step 3</strong> and <strong>Step 10</strong>).</li><li>Auth Server redirects the user to the respective website request along with the token containing basic details about the user in action.</li></ol><h3>Why SSO Is a Big Deal</h3><p>Now that we know what SSO is and understand how it works, let’s ask an important question — why would anyone want to replace regular login with SSO?</p><p>To answer that question, let’s take a look at another example. Whenever you log in to a website using your Google credentials, you allow that website to only have some of your information to be able to sign in — there’s no need to create another login and password and store it on that website.</p><p>That’s the main advantage behind SSO and the main reason why so many companies are replacing the regular email and password login with it. Every enterprise has its identity provider, so it’s only natural for Xeneta customers to expect to be able to access our platform using their existing credentials as well.</p><h3>Going Third Party</h3><p>When evaluating if we should develop a custom system or go with an out-of-the-box solution, we concluded that moving forward with a third party would be a better choice since writing code from scratch would require too much effort and resources.</p><p>While looking for a system that fits our requirements, the team went through quite a few SSO solutions available on the market:</p><ol><li>OneLogin</li><li>PingIdentity</li><li>Microsoft Azure</li><li>Auth0</li><li>Okta</li></ol><p>Most of these platforms offer great functionality, but Auth0 was the one that matched our needs the best, so we decided to go with that. It not only offered us SSO but allowed us to basically replace our entire login system with a much more secure and easily customizable solution.</p><blockquote><strong>Can you trust your SSO provider?<br></strong>Check that your provider of choice is fully compliant with the latest data protection standards like <strong>SOC2</strong> and <strong>ISO27018</strong>.</blockquote><h3>From Plans to Reality</h3><p>What if we told you that with a few clicks and a couple of redirects added to your code base, you could have a fully functional and secure login system?</p><p>This might sound like an exaggeration, but with top SSO providers, this is the reality — it took our team just a couple of months to fully master Auth0 and take advantage of its capabilities.</p><p>Auth0 provides a lot of customization options in the form of custom rules, actions, and hooks. With these options, we could change the flow to fit our specific needs and perform the required operations.</p><blockquote>Rules, actions, and hooks are <strong>JavaScript</strong> code that you can use to customize the MFA flow, email verification, password expiration, etc.</blockquote><h3>Thought Process</h3><p>Not everyone was fully on board with the idea of replacing our login system with an external tool at first. Naturally, there were quite a few questions, such as:</p><ul><li>“Why are we moving all of our login stuff to a third party?”</li><li>“Isn’t our current login system secure enough?”</li><li>Other similar (but equally valid) concerns</li></ul><p>And to be fair, our old system was quite solid and secure, but doing authentication securely and correctly is no easy task. Not to mention the cost of maintaining it.</p><p>Since we were going to implement SSO via Auth0 either way, it made sense to us to take advantage of its authentication capabilities to improve our login experience as well. Combined with not having to worry about maintenance, security, and library updates, it was well worth the asking price.</p><p>Auth0 already supported most identity providers and SAML, so we didn’t expect any difficulties with implementing SSO.</p><blockquote><strong>SAML</strong> is a single point of entry that allows you to use any identity provider to set up SSO.</blockquote><h3>What We Got Out of the Box</h3><p>SSO services typically offer an entire suite of features that handle everything related to login and authentication.</p><p>Here’s what we got with Auth0:</p><ol><li><strong>Multi-factor authentication</strong>. With just a click of a button, you can require all users to set up MFA. You can also customize it by adding your own rules.</li><li><strong>Password security</strong>.<strong> </strong>Configurable security rules for password complexity, which we used to help our users choose more secure passwords.</li><li><strong>Attack protection</strong>. Protection against brute force and bot attacks, password breaches, and more.</li><li><strong>Branding</strong>. Branded design, with additional customization options via HTML and CSS — all within a convenient UI. We used this recently to promote our Xeneta Summit customer event directly on our login page.</li><li><strong>Organizations</strong>. If you have enterprise customers with special login requirements, you can use the <strong>Organizations feature</strong> to set up custom authentication rules for each individual company.</li><li><strong>User import</strong>. We didn’t need to worry about keeping user credentials locally and providing Auth0 with access to our DB.</li></ol><p>These are the features we were primarily interested in, and once we understood all the rules, hooks, and actions, we could finally start doing some magic.</p><h3>Start of the Journey</h3><p>Since we already had a vast user database at Xeneta, we needed a solution where we could use our existing user table without having to run any migrations.</p><p>When we dug a bit deeper, we discovered that Auth0 could connect to our current DB and query directly from there.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*OrwAlN9jyHhP15k_e35Slw.png" /><figcaption>Database engines supported by Auth0</figcaption></figure><p>So, we started with the infra changes. First, we created a read-only user for Auth0 with access only to selected tables. Next, we customized Auth0 to use our existing database to let the user log in and do all the necessary operations without making many changes.</p><p>Within a few months, we had a new login page that provided more secure access to our application and allowed our users to access it with their existing credentials.</p><h3>Technical Challenges</h3><p>It wouldn’t be a proper development journey without some challenges and roadblocks, and of course, we ran into our fair share of them while working on our cool new login experience.</p><p>Here are just a few examples:</p><h4>How to release this big change safely?</h4><p>It wouldn’t be very wise to release the new login page in its entirety to all customers right away without some proper testing first (in production, of course).</p><p>At Xeneta, we are already using a feature management solution<strong> </strong>to control our feature rollout. It allows us to release new features only to specific users<strong> </strong>or user groups, and that’s exactly what we did with Auth0.</p><p>At first, we released the new login to a couple of internal users, which helped us fix early bugs. The next step was releasing the new login to all of our employees, and as soon as we were sure that everything was going smoothly after a few weeks of internal testing, we replaced the old login page with the new solution for all of our customers.</p><p>After the full rollout, we closely monitored the authentication logs and support tickets, and once the majority of our users had successfully logged in with the new solution, we could finally breathe out.</p><h4>What to expect from SSO?</h4><p>Since this was our first experience implementing enterprise SSO, we didn’t know what to expect, so we started small.</p><p>We began by testing things out with our internal Azure AD — we failed a couple of times, but with the help of our fantastic colleagues and support from the provider, we made SSO work. To make sure that it was working well, we enabled it for a few internal users and started monitoring it.</p><p>Thanks to the feedback from our early adopters, we discovered that we had to find a workaround for our end-to-end test suite users — apparently, MFA doesn’t play very well with test automation.</p><h4>How to migrate users with multi-factor authentication?</h4><p>We already had MFA in our old login code, but unfortunately transferring or reusing it turned out to be practically impossible.</p><p>We really wanted to keep the new flow as similar to the old one as possible to minimize any user frustration, so we dug into the Auth0 docs and found out that there were<strong> </strong>rules that allowed us to customize the flow.</p><p>After some trial and error, we managed to develop a handful of custom rules that helped us recreate the flow that was close enough to what our customers were already familiar with.</p><p>Those of our users who had MFA enabled had to re-enable it once the new login was released, and thanks to an email with detailed instructions we had sent out to all customers well in advance, the whole thing went very smoothly.</p><h4>Rules and Customization</h4><p>Let’s say that after login you want to check the last time the user reset their password. If the date is more than 30 days ago — stop the user from logging in and show them an error asking them to update their password.</p><p>Here’s what the rule for this scenario would look like in Auth0:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5edf4d1adf8bc91c95dc8b39223ab0a8/href">https://medium.com/media/5edf4d1adf8bc91c95dc8b39223ab0a8/href</a></iframe><blockquote>The function name should be the same — that’s how Auth0 knows when to call this. It’s called after login and receives the authenticated user object as one of the parameters.</blockquote><p>And just like that, with only 16 lines of code, we can change the flow the way we want.</p><h4>Code Base Changes</h4><p>With this integration now in place, we can safely remove a bunch of redundant logic from our code base and not worry about maintaining it.</p><p>All in all, we are looking at removing at least 3,000 lines of code that involved:</p><ol><li>Login</li><li>Logout</li><li>Multi-factor authentication (MFA)</li><li>Password update</li><li>Email verification</li><li>Email update</li><li>Single sign-on (SSO)</li></ol><h3>Downsides of Third-Party SSO</h3><p>Of course, no blog post would be complete without a list of downsides, so here are the ones that we discovered on our journey to implement a third-party SSO solution:</p><ul><li><strong>Single point of failure</strong>. Moving the login functionality to a third-party system comes with a risk that — if the SSO service goes down, it could be a problem for us as well.</li><li><strong>Customization with rules</strong>.<strong> </strong>With a lot of different rules and directions that handle various scenarios, you have to always know which rules control which operation. Otherwise, the whole thing could turn into a bit of a mess.</li><li><strong>Limited customization</strong>.<strong> </strong>Since it’s a third-party tool, there are bound to be some things that you just can’t customize and have to settle for whatever the tool provides.</li></ul><p>Xeneta is the leading ocean and air freight rate benchmarking and market analytics platform transforming the shipping and logistics industry. To learn more, visit <a href="http://www.xeneta.com/">www.xeneta.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b89f75563c2a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/how-we-moved-from-traditional-login-to-awesome-login-b89f75563c2a">How We Moved From Traditional Login to Awesome Login</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How the pandemic made supply chain management stronger]]></title>
            <link>https://medium.com/xeneta/how-the-pandemic-made-supply-chain-management-stronger-38ed9a5242bd?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/38ed9a5242bd</guid>
            <category><![CDATA[coronavirus]]></category>
            <category><![CDATA[shipping]]></category>
            <category><![CDATA[digitization]]></category>
            <category><![CDATA[remote]]></category>
            <category><![CDATA[supply-chain]]></category>
            <dc:creator><![CDATA[Katherine Barrios]]></dc:creator>
            <pubDate>Fri, 04 Sep 2020 09:21:10 GMT</pubDate>
            <atom:updated>2020-09-07T07:42:32.433Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QNZfxgZiFmrKx21Q9niVog.jpeg" /><figcaption>Photo by engin akyurt on Unsplash</figcaption></figure><p>Half a year into the global Covid-19 pandemic, many countries who sort of sailed through the “first wave” of the pandemic, are dialing things back a notch. Light lockdowns are being put back in place, and in little Norway (where I live), masks that were once not at all used, are now recommended on public transportation in Oslo.</p><p>Concerns about a “second wave” of the virus are spreading throughout the world. For some countries, they are saying, “Eh, did we every get over the first wave of the pandemic?”</p><p>As case numbers rise in the United States, Germany, and France, the shipping and supply chain industries will need to prepare for a possible new round of restrictions and lockdowns.</p><p>But the industry has the benefit of experience dealing with the initial coronavirus outbreak. Lessons learned from the early months of the global pandemic have shifted the way the global supply chain works for the short — and possibly — long term. Here are two key ways the supply chain is preparing for a possible Covid-19 resurgence.</p><h3>A focus on building agile remote workforces</h3><p>As the coronavirus spread throughout the world in the early part of 2020, global organizations — including supply chain management companies — allowed their employees to work from home to try and stop the spread of the virus and keep employees safe. After overcoming some technological growing pains of moving work from in the corporate office to the “home office,” remote work is the new normal.</p><p>This practice has forced organizations to shift their thinking around how to build an agile and productive remote workforce for the future. Companies are now much more prepared for “second wave” because their teams are better prepared for remote work.</p><p>Not only that, but the word “trust” is even more engrained in the relationship between employer and employee, and suppliers and buyers. Words mean a lot more. In many cases, we feel more committed, more motivated to make things work. I see great possibilities to how this new-found passion for “making things work” at work( because we don’t see each other face-to-face) will positively affect bottom lines and mental health, in general.</p><h3>Transitioning to digital supply chain data</h3><p>Supply chain data has never been more in the spotlight. In our <a href="https://www.xeneta.com/blog/ups-the-changing-face-of-global-supply-chain-post-covid-19">June 15 Transportation Insights webinar</a>, we spoke with Philippe Gilbert, President of Supply Chain Solutions at UPS about the changing face of supply chain in a post-covid-19 world. According to Philippe, the COVID-19 crisis has only increased the need for digital supply chain data. “The COVID pandemic has accelerated the usage and visibility of data, both to anticipate and avoid blockages.”</p><p>Algorithmic digital data give companies both predictive and descriptive views on the supply chain, so they can uncover and avoid risk. These insights are critical as supply chains deal with challenges brought on by Covid-19 restrictions as we enter the second half of 2020. Data from the early days of the pandemic can also be used to run predictive scenarios, so contingency plans can be developed for all the possible outcomes.</p><p>History is truly our greatest teacher. Lessons learned from H1 2020 will carry over into a possible Covid-19 second wave and the supply chain will be stronger for it — even well beyond this moment of crisis.</p><p>If you are looking to modernize your freight procurement and make your supply chain management even stronger, Xeneta can help. Check out <a href="http://www.xeneta.com./">www.xeneta.com.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38ed9a5242bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/how-the-pandemic-made-supply-chain-management-stronger-38ed9a5242bd">How the pandemic made supply chain management stronger</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why The Sea Freight Industry Is So Broken]]></title>
            <link>https://medium.com/xeneta/why-the-sea-freight-industry-is-so-broken-151d95875140?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/151d95875140</guid>
            <category><![CDATA[shipping]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[logistics]]></category>
            <dc:creator><![CDATA[Per Harald Borgen]]></dc:creator>
            <pubDate>Thu, 17 Nov 2016 15:14:07 GMT</pubDate>
            <atom:updated>2016-11-17T15:17:20.420Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lSpKx6lTPSuxYjttlOCpwg.jpeg" /></figure><p>At Xeneta we’re trying to make the sea freight industry more transparent, as we believe lack of transparency creates a dysfunctional market.</p><p>Let’s have a look at why this industry is so broken.</p><h3>1. No standard</h3><p>If you’re a company that needs to ship stuff in containers over sea, you’ll get price quotes (from shipping lines or freight forwarders) delivered in excel sheets.</p><p>Every supplier has <strong>its</strong> <strong>own standard</strong>, meaning there actually is <strong>no standard.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qdFWRHhzLFPKr6fiiv4VhA.png" /></figure><p>They tend to use different layouts, different names (on ports, regions, container sizes etc) and different ways of displaying other relevant data. As a final touch they often contain mistakes, because they’re created by humans.</p><blockquote>This means that programatically comparing prices is a huge pain.</blockquote><p>At Xeneta, we use a mix of machine power and human power to churn through sheets, so that we can turn the chaos into <strong>actionable</strong> data, like the graph below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OlaJBgVFqMO6dFEVuGn8WA.png" /><figcaption>Short term contracts (spot market) for 20 feet containers from Shanghai to Rotterdam.</figcaption></figure><p>So a simple graph like this, which we take for granted in other markets (stocks, currencies, commodities) is actually really hard to create for the sea freight industry.</p><blockquote>Plus, there’s the effort of convincing shippers to share their data, but that’s a completely different story.</blockquote><h3>2. General Rate Increase</h3><p>If you look closely at the graph above, you’ll see multiple spikes throughout it. This is because shipping lines regularly decide to increase their prices simultaneously, so called General Rate Increases<em> </em>(GRI)<em>.</em></p><p>In the days following a GRI, the suppliers experience spare capacity and start lowering their prices in order to attract volume and fill up their order books again.</p><p>Below you’ll see how the GRI’s plays out on the <strong>Market Average</strong> price on the Shanghai to Rotterdam lane throughout a year:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JCGF5iXfZrBnorOOAb63EA.png" /><figcaption>The market average price for short term contracts for 20 foot containers between Shanghai and Rotterdam.</figcaption></figure><p>Imagine if all the big airlines once a while simultaneously increased their prices with 30–100%. That’s exactly what’s happening here.</p><blockquote>In other words, a perfect sign of a dysfunctional market.</blockquote><h3>3. Market High vs. Market Low</h3><p>The graph above only shows the<strong> Market Averag</strong>e price for short term contracts.</p><p>Let’s zoom in on one of the GRI spikes and look at how it affects the the overall spread of the market by looking at the <strong>Market High </strong>and<strong> Market Low </strong>instead:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ACdRq7RF2a5RAXAZ4iYGqQ.png" /></figure><p>The Market High price is <strong>1 536 USD, </strong>while the Market Low is <strong>387</strong> <strong>USD.</strong></p><blockquote>So if you’re bad at negotiating sea freight prices you risk paying 4 times as much as the ones who’re good at it.</blockquote><p>This week is an extreme example, but throughout the following months, the Market High vs. Market Low <strong>price difference</strong> on this lane stabilised itself at around 300 percent.</p><h3>4. Huge supplier spread</h3><p>This price differences isn’t just because various shipping lines price themselves differently. The spread is just as big internally as well. Let’s zoom into<strong> one shipping line </strong>and see the range of prices it offers to its customers on a specific corridor:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVNTVLI2FD4MXKSlLsKPfQ.png" /></figure><blockquote>At worst, this shipping line‘s highest prices are 4 times as high as the low ones.</blockquote><p>So even if two customers have the same suppliers on the same lane they are likely to pay two completely different prices.</p><p>There are many other broken things about this industry, this was just four of the most apparent examples, to give you an impression.</p><p>If you’re interested in getting insight into this market, don’t hesitate to <a href="http://xeneta.com/">c0ntact us.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=151d95875140" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/why-the-sea-freight-industry-is-so-broken-151d95875140">Why The Sea Freight Industry Is So Broken</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing Ansible playbooks on localhost]]></title>
            <link>https://medium.com/xeneta/testing-ansible-playbooks-on-localhost-58f9fddc4f8b?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/58f9fddc4f8b</guid>
            <category><![CDATA[ansible]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[infrastructure]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Zakhar Shapurau]]></dc:creator>
            <pubDate>Wed, 02 Nov 2016 09:07:36 GMT</pubDate>
            <atom:updated>2016-11-02T11:13:39.441Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*i4U-QxICZB2ri8_l_UM7iA.png" /></figure><h4>How to develop and test Ansible playbooks on your local machine with Docker and some shell scripting.</h4><p><a href="http://docs.ansible.com/ansible/playbooks.html">Ansible playbooks</a> are an extremely powerful tool for managing complex multi-server setups. But when you are developing playbooks, you can not just run them towards your production environment to test them.</p><p>In this article we present a method for testing playbooks locally with Docker containers as targets.</p><h3>Overview</h3><p>We are going to create several Docker containers and use them as Ansible targets.</p><p>We will also alias IP addresses to the loopback interface and expose container SSH ports on those. This is mostly a workaround for macOS because it does not have Docker network interface.</p><h3>Structure</h3><p>The setup fits into one folder with a few files, and Docker is the only requirement apart from Ansible.</p><pre>$ tree ./dev<br>./dev<br>├── Dockerfile  # Docker image for test containers<br>├── id_rsa      # Private key for ansible to ssh into test targets<br>├── id_rsa.pub  # Public key for test targets<br>├── inventory   # Ansible inventory file with test targets<br>├── test.sh     # Script to run ansible towards test targets<br>└── vars.yml    # Ansible playbook variable overrides</pre><h3>Test inventory</h3><p>In the dev/inventory file we put the Ansible hosts config with *.ans.local hostnames. This is how it looks in our setup:</p><pre>$ cat dev/inventory<br>[all]<br>s1.ans.local<br>s2.ans.local</pre><p>When dev/test.sh is run, we first parse the test inventory file to get hostnames of test targets.</p><pre>DIR=&quot;$( cd &quot;$( dirname &quot;${BASH_SOURCE[0]}&quot; )&quot; &amp;&amp; pwd )&quot;<br>INVENTORY_FILE=&quot;$DIR/inventory&quot;<br>TARGETS=$(grep &#39;\.ans\.local&#39; $INVENTORY_FILE | grep -v &#39;;&#39; | sort | uniq)</pre><h3>Docker interface workaround for macOS</h3><p>Docker on macOS does not have docker0 interface, so you can not access containers via the network from the host without exposing their ports on host IP.</p><p>We could expose SSH on 127.0.0.1 with different port for each container, but Ansible does not see the difference between 127.0.0.1:1234 and 127.0.0.1:5555, so we still need unique hostnames. Another problem with using different ports is that it complicates the Ansible run configuration - we would have to set ansible_port for each target.</p><p>To circumvent these limitations, we alias IP addresses to the loopback interface for each hostname from dev/inventory and put the hostname for the alias in /etc/hosts. This way we get unique IP addresses, unique hostnames for Ansible, and the same exposed SSH port on each container.</p><pre>IP_PREFIX=&quot;192.168.200&quot;<br>setup_test_ips() {<br>    counter=1<br>    for host in $TARGETS<br>    do<br>        ip=&quot;$IP_PREFIX.$((counter++))&quot;<br>        sudo ifconfig lo0 alias &quot;$ip&quot;<br>        echo &quot;    $ip $host&quot; | sudo tee -a /etc/hosts<br>    done<br>}</pre><h3>Test containers</h3><p>We build the Docker image with SSH server and our public test key in it.</p><pre>DOCKER_IMAGE_NAME=&quot;ansible_local_test&quot;<br>cd $DIR &amp;&amp; docker build -t &quot;$DOCKER_IMAGE_NAME:latest&quot; .</pre><p>Now we can start the Docker containers for each test target. We are going to assign hostname as a name of container to reference them easily when needed. We are exposing port 22 on the corresponding aliased IP in each container.</p><pre>start_containers() {<br>    counter=1</pre><pre>    for host in $TARGETS<br>    do<br>        ip=&quot;$IP_PREFIX.$((counter++))&quot;<br>        docker run \<br>            -d \<br>            -p &quot;$ip&quot;:22:22 \<br>            --name &quot;$host&quot; \<br>            &quot;$DOCKER_IMAGE_NAME:latest&quot;<br>    done<br>}</pre><h3>Running Ansible</h3><p>Now we are all set to run our Ansible playbook towards the test targets.</p><pre>ID_RSA_FILE=&quot;$DIR/id_rsa&quot;<br>OVERRIDE_VARS_FILE=&quot;$DIR/vars.yml&quot;<br>PLAYBOOK_FILE=&quot;$DIR/../playbook.yml&quot;<br>ANSIBLE_HOST_KEY_CHECKING=False \<br>    ansible-playbook \<br>    --inventory-file=&quot;$INVENTORY_FILE&quot; \<br>    --user=root \<br>    --private-key=&quot;$ID_RSA_FILE&quot; \<br>    --inventory-file=&quot;$INVENTORY_FILE&quot; \<br>    --extra-vars=&quot;@$OVERRIDE_VARS_FILE&quot; \<br>    &quot;$PLAYBOOK_FILE&quot;</pre><h3>Cleaning up</h3><p>After Ansible is done, we remove the IP aliases from the loopback interface and test target hostnames from /etc/hosts.</p><pre>cleanup_test_ips() {<br>    grep -v &quot;$IP_PREFIX&quot; /etc/hosts | sudo tee /etc/hosts</pre><pre>    counter=1<br>    for host in $TARGETS<br>    do<br>        ip=&quot;$IP_PREFIX.$((counter++))&quot;<br>        sudo ifconfig lo0 -alias &quot;$ip&quot;<br>    done<br>}</pre><h3>Demo project</h3><p>I made a demo project that illustrates the approach described in this article. It contains a simple Ansible playbook and setup for testing it locally. You can clone it and follow instructions in README to try it out.</p><p>The demo project can be found here: <a href="https://github.com/xeneta/ansible-local-dev">https://github.com/xeneta/ansible-local-dev</a></p><h3>Using Linux?</h3><p>Everything is much easier. You can skip IP setup and cleanup steps, and instead map hostnames to Docker container IP addresses on docker0 interface - you can find them with docker inspect.</p><p>ifconfig is deprecated on Linux now: you can use ip link to add and remove alias IP addresses instead.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58f9fddc4f8b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/testing-ansible-playbooks-on-localhost-58f9fddc4f8b">Testing Ansible playbooks on localhost</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fuzzy search with MongoDB and Python]]></title>
            <link>https://medium.com/xeneta/fuzzy-search-with-mongodb-and-python-57103928ee5d?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/57103928ee5d</guid>
            <category><![CDATA[search]]></category>
            <category><![CDATA[realtime]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[geolocation]]></category>
            <category><![CDATA[mongodb]]></category>
            <dc:creator><![CDATA[Zakhar Shapurau]]></dc:creator>
            <pubDate>Wed, 19 Oct 2016 13:47:32 GMT</pubDate>
            <atom:updated>2016-10-19T13:47:32.052Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lRaZ5K4u_EbbxzZ4_CvWVw.gif" /><figcaption>Port search in action</figcaption></figure><h4>A typo-robust and flexible search of names and short phrases.</h4><p>At <a href="https://xeneta.com/">Xeneta</a> we operate the world’s largest container freight rate database and provide powerful analytics on top of that.</p><p>One of the most basic use cases is finding out the average price to ship a container of a certain type from one port to another. To enable that we have to give users the ability to search for ports. As with all geographical objects, port names may not necessarily be easy to remember or spell correctly, so the search tool has to be robust against typos.</p><p>This article presents a reasonably simple and flexible solution to this problem which will be especially useful if you are running MongoDB, as it does not require external search tools.</p><h3>Ports and their names</h3><p>The collection that keeps ports in MongoDB looks somewhat like this:</p><pre><strong>&gt;</strong> MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>find()<br><br>[<br>    {<br>        &quot;name&quot; : &quot;St. Petersburg (ex Leningrad)&quot;,<br>        &quot;code&quot; : &quot;RULED&quot;<br>    },    <br>    {<br>        &quot;name&quot; : &quot;El Iskandariya (Alexandria)&quot;,<br>        &quot;code&quot; : &quot;EGALY&quot;<br>    },<br>    {<br>        &quot;name&quot; : &quot;Ålesund&quot;,<br>        &quot;code&quot; : &quot;NOAES&quot;<br>    }<br>]</pre><p><strong>Ålesund</strong> contains an accented latin character, which is not even present on an ISO keyboard. We want to be able to search for it as <strong>aalesund</strong>, <strong>alesund</strong> or <strong>ålesund</strong>.</p><p><strong>St. Petersburg (ex Leningrad) </strong>has to be searchable with both <strong>lenin</strong> and <strong>peter</strong>.</p><p>Search query <strong>alex</strong> has to be able to find <strong>El Iskandariya (Alexandria)</strong>.</p><p>Even though MongoDB supports text search functionality in more recent versions, it is not a particularly good fit for this task, mostly because it works by matching whole words. Stemming could be the answer, but it is hard to find stemming dictionaries for geographical names.</p><p>In order to solve our problem, additionally we use an n-gram technique.</p><h3>Introducing n-grams</h3><p>In our case, an <strong>n-gram</strong> is a sequence of characters taken from a string. n-grams are commonly used in statistical text analysis problems: like measuring text similarity (think plagiarism check) or even speech recognition.</p><p>It is pretty clear that <strong>unigram</strong> (single character) is not going to be of much use, because there are a few letters are very common among different words and therefore search would give way too many false positives to be useful.</p><p>Here is a Python function that we use to extract n-grams out of a port name:</p><pre><strong>def</strong> <strong>make_ngrams</strong>(word, min_size<strong>=</strong>2):<br>    &quot;&quot;&quot;<br>    basestring       word: word to split into ngrams<br>           int   min_size: minimum size of ngrams<br>    &quot;&quot;&quot;<br>    length <strong>=</strong> len(word)<br>    size_range <strong>=</strong> xrange(min_size, max(length, min_size) <strong>+</strong> 1)<br>    <strong>return</strong> list(set(<br>        word[i:i <strong>+</strong> size]<br>        <strong>for</strong> size <strong>in</strong> size_range<br>        <strong>for</strong> i <strong>in</strong> xrange(0, max(0, length <strong>-</strong> size) <strong>+</strong> 1)<br>    ))</pre><p>This is how <strong>ålesund</strong> would look like after we split it into n-grams:</p><pre><strong>&gt;</strong> make_ngrams(u&quot;ålesund&quot;)</pre><pre>[<br>    u&#39;ål&#39;, u&#39;le&#39;, u&#39;es&#39;, u&#39;su&#39;, u&#39;un&#39;, u&#39;nd&#39;,<br>    u&quot;åle&quot;, u&quot;les&quot;, u&quot;esu&quot;, u&quot;sun&quot;, u&quot;und&quot;,<br>    u&quot;åles&quot;, u&quot;lesu&quot;, u&quot;esun&quot;, u&quot;sund&quot;,<br>    u&quot;ålesu&quot;, u&quot;lesun&quot;, u&quot;esund&quot;,<br>    u&quot;ålesun&quot;, u&quot;lesund&quot;,<br>    u&quot;ålesund&quot;<br>]</pre><p>Now, if we take an input search term, coming from the user, something like <strong>alesu</strong>, and split it into n-grams:</p><pre><strong>&gt;</strong> make_ngrams(u&quot;alesu&quot;)</pre><pre>[<br>    u&#39;al&#39;, u&#39;le&#39;, u&#39;es&#39;, u&#39;su&#39;,<br>    u&quot;ale&quot;, u&quot;les&quot;, u&quot;esu&quot;,<br>    u&quot;ales&quot;, u&quot;lesu&quot;,<br>    u&quot;alesu&quot;,<br>]</pre><p>We can compare these two lists, and consider overlap to be a search hit — and this is something that MongoDB text search can do really well.</p><h3>Indexing n-grams in MongoDB</h3><p>We are introducing additional collection in MongoDB for storing space-separated n-grams of port names as text.</p><p>This is a function that we have to run every time someone modifies or adds a new port:</p><pre><strong>def</strong> <strong>index_for_search</strong>(port):<br>    MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>search<strong>.</strong>update(<br>        {<br>            &quot;code&quot;: port[&quot;code&quot;],<br>        },<br>        {<br>            &quot;$set&quot;: {<br>                &quot;code&quot;: unicode(port[&quot;code&quot;]),<br>                &quot;name&quot;: unicode(port[&quot;name&quot;]),<br>                &quot;ngrams&quot;: u&#39; &#39;<strong>.</strong>join(<br>                    make_ngrams(unicode(port[&quot;name&quot;]))<br>                ),<br>            },<br>        },<br>        upsert<strong>=</strong>True,<br>    )</pre><p>It extracts n-grams from port name, puts them into a text field, and stores it alongside with code and name in sub-collection.</p><p>Collection would look something like this in MongoDB:</p><pre><strong>&gt;</strong> MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>search<strong>.</strong>find()</pre><pre>[<br>    {<br>        &quot;code&quot; : &quot;NOAES&quot;,<br>        &quot;ngrams&quot; : &quot;lesu esu åles lesun esund lesund sun åle les und ålesu esun ålesun ålesund sund&quot;,<br>        &quot;name&quot; : &quot;Ålesund&quot;<br>    }<br>]</pre><p>In this particular case we are not using n-grams that are shorter than 3 characters. We found this lower limit empirically: <strong>bigrams</strong> gave too many false hits to be useful.</p><p>Now we need to tell MongoDB to build text search index on this collection:</p><pre><strong>&gt;</strong> MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>search<strong>.</strong>create_index(<br>    [<br>        (&quot;ngrams&quot;, &quot;text&quot;),<br>    ],<br>    name<strong>=</strong>&quot;search_port_ngrams&quot;,<br>    weights<strong>=</strong>{<br>        &quot;ngrams&quot;: 100,<br>    }<br>)</pre><h3>Using search</h3><p>We turn the incoming search query into space-separated list of n-grams so that MongoDB could do whole-word match in documents we indexed for text search:</p><pre><strong>&gt;</strong> query <strong>=</strong> make_ngrams(u&quot;alesu&quot;)<br><strong>&gt;</strong> MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>search<strong>.</strong>find(<br>        {<br>            &quot;$text&quot;: {<br>                &quot;$search&quot;: query<br>            }<br>        },<br>        {<br>            &quot;code&quot;: True,<br>            &quot;name&quot;: True,<br>            &quot;score&quot;: {<br>                &quot;$meta&quot;: &quot;textScore&quot;<br>            }<br>        }<br>    )<strong>.</strong>sort([(&quot;score&quot;, {&quot;$meta&quot;: &quot;textScore&quot;})])</pre><pre>[<br>    {<br>        &quot;code&quot; : &quot;NOAES&quot;,<br>        &quot;name&quot; : &quot;Ålesund&quot;,<br>        &quot;score&quot;: 100<br>    }<br>]</pre><p>We tell MongoDB to use text search on our collection using n-grams from search query and sort results by text match score.</p><p>This is already a functional solution, but there is one obvious edge case we want to look at.</p><h3>Improving edge case behavior</h3><p>Many port names have common n-grams in different positions, for example <strong><em>Gua</em></strong><em>m</em> and <em>La </em><strong><em>Gua</em></strong><em>ira</em>. If the user is searching for <strong>gua</strong>, both port names will get the same search score, but we want to show port that matches at the beginning higher up in search results — people rarely type search query from the end.</p><p>This is where we exploit MongoDB index weights to our benefit.</p><p>This version of our n-gram extraction function can optionally return n-grams only from the beginning of the word:</p><pre><strong>def</strong> <strong>make_ngrams</strong>(word, min_size<strong>=</strong>2, prefix_only<strong>=</strong>False):<br>    &quot;&quot;&quot;<br>    basestring          word: word to split into ngrams<br>           int      min_size: minimum size of ngrams<br>          bool   prefix_only: Only return ngrams from start of word<br>    &quot;&quot;&quot;    length <strong>=</strong> len(word)<br>    size_range <strong>=</strong> xrange(min_size, max(length, min_size) <strong>+</strong> 1)<br>    <strong>if</strong> prefix_only:<br>        <strong>return</strong> [<br>            word[0:size]<br>            <strong>for</strong> size <strong>in</strong> size_range<br>        ]<br>    <strong>return</strong> list(set(<br>        word[i:i <strong>+</strong> size]<br>        <strong>for</strong> size <strong>in</strong> size_range<br>        <strong>for</strong> i <strong>in</strong> xrange(0, max(0, length <strong>-</strong> size) <strong>+</strong> 1)<br>    ))</pre><p>And now we have to add one more field to the documents in search sub-collection:</p><pre><strong>def</strong> <strong>index_for_search</strong>(port):<br>    MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>search<strong>.</strong>update(<br>        {<br>            &quot;code&quot;: port[&quot;code&quot;],<br>        },<br>        {<br>            &quot;$set&quot;: {<br>                &quot;code&quot;: unicode(port[&quot;code&quot;]),<br>                &quot;name&quot;: unicode(port[&quot;name&quot;]),<br>                &quot;ngrams&quot;: u&#39; &#39;<strong>.</strong>join(<br>                    make_ngrams(unicode(port[&quot;name&quot;]))<br>                ),<br>                &quot;prefix_ngrams&quot;: u&#39; &#39;<strong>.</strong>join(<br>                    make_ngrams(unicode(port[&quot;name&quot;]), prefix_only<strong>=</strong>True)<br>                ),<br>            },<br>        },<br>        upsert<strong>=</strong>True,<br>    )</pre><p>And here we change the index to incorporate this new field:</p><pre><strong>&gt;</strong> MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>search<strong>.</strong>drop_index(&quot;search_port_ngrams&quot;)<br><strong>&gt;</strong> MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>search<strong>.</strong>create_index(<br>    [<br>        (&quot;ngrams&quot;, &quot;text&quot;),<br>        (&quot;prefix_ngrams&quot;, &quot;text&quot;),<br>    ],<br>    name<strong>=</strong>&quot;search_port_ngrams&quot;,<br>    weights<strong>=</strong>{<br>        &quot;ngrams&quot;: 100,<br>        &quot;prefix_ngrams&quot;: 200,<br>    }<br>)</pre><p>Note that we give a higher weight to the field containing prefix n-grams. The ability to adjust field weight in the index gives us a way to adjust which kind of results search prefers.</p><p>Usage would be the same:</p><pre><strong>&gt;</strong> MongoClient(&quot;localhost&quot;, 27017)<strong>.</strong>xeneta<strong>.</strong>ports<strong>.</strong>search<strong>.</strong>find(<br>        {<br>            &quot;$text&quot;: {<br>                &quot;$search&quot;: make_ngrams(unicode(search_input))<br>            }<br>        },<br>        {<br>            &quot;code&quot;: True,<br>            &quot;name&quot;: True,<br>            &quot;score&quot;: {<br>                &quot;$meta&quot;: &quot;textScore&quot;<br>            }<br>        }<br>    )<strong>.</strong>sort([(&quot;score&quot;, {&quot;$meta&quot;: &quot;textScore&quot;})])</pre><p>Now we can play a bit with field weights in index and make search behave as we want it to.</p><h3>Missing parts</h3><p>The solution we employ in production is a bit more complicated than what was presented:</p><ul><li>Both port names and input search terms have to be cleaned up before indexing.</li><li>Whitespace, punctuation and prefixes like <em>St.</em> or <em>Pt. </em>have to be handled.</li><li>In addition to ports, we provide search for geographic regions.</li><li>We provide exact-match search by port code.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57103928ee5d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/fuzzy-search-with-mongodb-and-python-57103928ee5d">Fuzzy search with MongoDB and Python</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Setup A Learning Routine At Work]]></title>
            <link>https://medium.com/xeneta/how-to-gain-new-skills-at-work-923bb088a352?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/923bb088a352</guid>
            <category><![CDATA[business]]></category>
            <category><![CDATA[employee-engagement]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <dc:creator><![CDATA[Per Harald Borgen]]></dc:creator>
            <pubDate>Mon, 29 Aug 2016 08:39:24 GMT</pubDate>
            <atom:updated>2016-09-01T13:42:05.298Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LMf1rMRjGHZ4ezelWrzAeQ.jpeg" /><figcaption>Credit: Pete Souza</figcaption></figure><h4>4 tips to grow your skills while being hired</h4><p>I’m convinced that your ability to continuously learn new things at your work place is more important for your day-to-day performance and career than everything you learned at university.</p><p>If you’re a developer, you’re also more likely to be pleased with your job if it enables you to learn new stuff (according to the <a href="http://stackoverflow.com/research/developer-survey-2016#work-devs-love-to-learn">Stack Overflow 2016 survey</a>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2epo721wHnLHdNTBwgIhKA.png" /></figure><p>So I think all companies should embrace self development. Not only through making sure their employees work on tasks which turn them into better developers, designers, managers etc etc. But also by letting them devote time<strong> solely </strong>to sharpen their skills.</p><blockquote>At Xeneta, all employees are encouraged to spend work hours to learn new stuff, as we believe employee skill growth directly impacts our success.</blockquote><p>Throughout this year, I’ve tried to follow a consistent learning routine every week, and I’ve experienced how effective this can be. Likewise, I’ve also realized how easy it is to get off track, which is why I decided to write this article.</p><p>Below are the tips I’ve gathered along the way. They should make it easier for you to set up a successful learning routine for yourself at work.</p><h3>1. Ask for it</h3><p>Your first challenge might be that your company doesn’t have a training program. And it might not be a culture for it either.</p><p>When I started at <a href="http://xeneta.com/">Xeneta</a>, we didn’t have an official employee training program (which we do now). But there was certainly a culture for learning new stuff. However, I didn’t know if it was ok that I spent a specific number of work hours each week to train myself. So I had to ask, of course.</p><p>The answer was yes. Not only that: I was encouraged to do it.</p><p>So if you don’t know if you’ll be allowed, the first step is naturally to <strong>ask for it. </strong>If you get a no, I think you should consider quitting your job.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*e5VFRiNYevSAmIUIh7BwIg.jpeg" /></figure><h3>2. Set off specific hours</h3><p>In the beginning, I squeezed in a little bit of learning here and there, whenever I didn’t have other tasks hanging over me. This is a bad idea.</p><p>First and foremost because the<strong> mental cost of shifting</strong> between learning and working is big, and both activities are hurt by the switch.</p><blockquote>Three straight hours of learning is better than an hour a day for three days.</blockquote><p>Secondly, it’s easy to skip your learning sprints it if you don’t schedule time for it, as there are always tasks to be done. So save yourself the mental cost of having to choose between working or learning multiple times throughout the week, and simply add it to your calendar instead.</p><p>I prefer <strong>before lunch on Wednesdays</strong>.</p><p>The exact day doesn’t matter much, but scheduling it in the morning is critical, as it prevents me from being deep into another task when I start. This limits the chance of skipping it and also dodges the switching cost mentioned above.</p><h3>3. Plan your training ahead of time</h3><p>This point is important. The difference between a fruitful learning session and three wasted hours is often whether or not I planned what I was going to learn.</p><p>So I always try to mentally decide this beforehand. It doesn’t have to be detailed, but something like:</p><ul><li>Code task A</li><li>Do next lecture in course B</li><li>Try to understand concept C.</li></ul><p>If you’re really serious, even write it down!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FT8tQZChniMk%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DT8tQZChniMk&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FT8tQZChniMk%2Fhqdefault.jpg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d8d6f0df8a29c865123847bfd43f8e4/href">https://medium.com/media/3d8d6f0df8a29c865123847bfd43f8e4/href</a></iframe><h3>4. Put your skills to the test</h3><p>This one is not critical, but it’s both fun and makes your knowledge stick. By finding a way to use your newly acquired skills at work, you’ll feel a sense of accomplishment and likely get motivated to learn even more.</p><p>Secondly, this also helps your co-workers see the benefit of self development hours. This will create more acceptance in your company for these kinds of activities.</p><p>After spending a lot of time (both at work and home) going through the <a href="http://cs224d.stanford.edu/syllabus.html">Stanford CS224D course</a>, I did a project at Xeneta where we trained an algorithm to recognize potential customers by reading their company descriptions.</p><p><a href="https://medium.com/xeneta/boosting-sales-with-machine-learning-fbcf2e618be3">Boosting Sales With Machine Learning</a></p><p>Even though I didn’t directly use the neural networks structures from the Stanford course in the <a href="https://github.com/xeneta/LeadQualifier">Xeneta lead qualifier</a>, it did make me more comfortable using natural language processing techniques in general, and opened my eyes for all the possibilities in the field, which again gave me the confidence to tackle the project.</p><p>Hope these tips helped, and feel free to add your comments below if you have anything to add:)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=923bb088a352" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/how-to-gain-new-skills-at-work-923bb088a352">How To Setup A Learning Routine At Work</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Boosting Sales With Machine Learning]]></title>
            <link>https://medium.com/xeneta/boosting-sales-with-machine-learning-fbcf2e618be3?source=rss----71f4429a370c---4</link>
            <guid isPermaLink="false">https://medium.com/p/fbcf2e618be3</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Per Harald Borgen]]></dc:creator>
            <pubDate>Tue, 07 Jun 2016 13:11:55 GMT</pubDate>
            <atom:updated>2016-06-08T13:03:12.259Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6IxbN8PDGYbc1nb4HLLP9Q.jpeg" /></figure><h4>How we use natural language processing to qualify leads</h4><p>In this blog post I’ll explain how we’re making our sales process at <a href="http://www.xeneta.com/">Xeneta </a>more effective by training a machine learning algorithm to predict the quality of our leads based upon their company descriptions.</p><p>Head over to <a href="https://github.com/xeneta/LeadQualifier">GitHub</a> if you want to check out the script immediately, and feel free to suggest improvements as it’s under continuous development.</p><h3>The problem</h3><p>It started with a request from business development representative <a href="https://twitter.com/EdvardNore">Edvard</a>, who was tired of performing the tedious task of going through big excel sheets filled with company names, trying to identify which ones we ought to contact.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iDt2eG7NYSx6NCTB-1oYLw.png" /><figcaption>An example of a list of potential companies to contact, pulled from sec.gov</figcaption></figure><p>This kind of<em> </em><strong>pre-qualification of sales leads<em> </em></strong>can take hours, as it forces the sales representative to figure out what every single company does (e.g. through read about them on LinkedIn) so that he/she can do a qualified guess at whether or not the company is a good fit for our SaaS app.</p><p>And how do you make a <strong>qualified guess?</strong> To understand that, you’ll first need to know what we do:</p><blockquote>In essence, Xeneta help companies that ship containers discover saving potential by providing <strong>sea freight market intelligence.</strong></blockquote><figure><a href="http://www.xeneta.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tKeie4sCeX95DXfJH0qJ8w.png" /></a><figcaption>This customer had a 748K USD saving potential down to market average on its sea freight spend.</figcaption></figure><p>More specifically, if your company ships above 500 containers per year, you’re likely to discover significant saving potential by using Xeneta, as we’re able to tell you exactly where you’re <strong>paying above the market average price.</strong></p><figure><a href="http://www.xeneta.com/"><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*87paooEILGwnTz_W13yghg.png" /></a><figcaption>This widget compares a customers’ contracted rate (purple line) to the market average (green graph) for 20 foot containers from China to Northern Europe.</figcaption></figure><p>This means that our target customers are vastly different from each other, as their only common denominator is that they’re somewhat involved in sea freight. Here are some examples of company categories we target:</p><ul><li>Automotive</li><li>Freight forwarding</li><li>Chemicals</li><li>Consumer &amp; Retail</li><li>Low paying commodities</li></ul><h3>The hypothesis</h3><p>Though the broad range of customers represents a challenge when finding leads, we’re normally able to tell if a company is of interest for Xeneta <strong>by reading their company description,</strong> as it often contains hints of whether or not they’re involved in sending stuff around the world.</p><p>This made us think:</p><blockquote>Given a company description, can we train an algorithm to predict whether or not it’s a potential Xeneta customer?</blockquote><p>If so, this algorithm could prove as a huge time saver for the sales team, as it could roughly sort the excel sheets before they start qualifying the leads manually.</p><h3>The development</h3><p>As I started working on this, I quickly realised that the machine learning part wasn’t be the only problem. We also needed a way to get hold of the company descriptions.</p><p>We considered crawling the companies’ websites and fetch the <strong><em>About us</em></strong> section. But this smelled like a messy, unpredictable and time consuming activity, so we started looking for API’s to use instead. After some searching we discovered <a href="http://www.fullcontact.com/">FullContact</a>, which have a Company API that provides you with descriptions of millions of companies.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*StYX-B0ln68C3SvzU89tvw.png" /></figure><p>However, their API only accept company URL’s as inputs, which rarely are present in our excel sheets.</p><p>So we had to find a way to obtain the URL’s as well, which made us land on the following workflow:</p><ul><li>Using the Google API to google the company name (hacky, I know…)</li><li>Loop through the search result and find the most likely correct URL</li><li>Use this URL to query the FullContact API</li></ul><p>There’s of course a loss at each step here, so we’re going to find a better way of doing this. However, this worked well enough to test the idea out.</p><h3>The dataset</h3><p>Having these scripts in place, the next step was to create our training dataset. It needed to contain at least 1000 <strong>qualified</strong> companies and 1000 <strong>disqualified</strong> companies.</p><p>The first category was easy, as we could simply export a list of 1000 Xeneta users from SalesForce.</p><p>Finding 1000 <strong>disqualified </strong>was a bit tougher though, as we don’t keep track of the companies we’ve avoided contacting. So Edvard manually <strong>disqualified</strong> 1000 companies.</p><h3>Cleaning the data</h3><p>With that done, it was time to start writing the natural language processing script, with step one being to clean up the descriptions, as they are quite dirty and contain a lot of irrelevant information.</p><p>In the examples below, I’ll go though each of the cleaning techniques we’re currently applying, and show you how a <strong>raw description</strong> ends up as an <strong>array of numbers.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pquscuuu64HSZ3sS8I-qlA.png" /><figcaption>An example of a raw description.</figcaption></figure><h4>RegExp</h4><p>The first thing we do is to use regular expressions to get rid non-alphabetical characters, as our model will only be able to learn words.</p><pre>description = re.sub(“[^a-zA-Z]”, “ “, description)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tST2pvlZSKH5kr5-J4jBeA.png" /><figcaption>After removing non-alphabetical characters.</figcaption></figure><h4>Stemmer</h4><p>We also stem the words. This means reducing multiple variations of the same word to its stem. So instead of accepting words like <strong>manufacturer, manufaction, manufactured &amp; manufactoring, </strong>we rather simplify them to <strong>manufact.</strong></p><pre>from nltk.stem.snowball import SnowballStemmer<br>stemmer = SnowballStemmer(‘english’)<br>description = getDescription()</pre><pre>description = [stemmer.stem(word) for word in description]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qFNZ2qDLYhCKyeqo6LkE0A.png" /><figcaption>After stemming the words.</figcaption></figure><h4>Stop words</h4><p>We then remove stop words, using <a href="http://www.nltk.org/">Natural Language Toolkit</a>. Stop words are words that have little relevance for the conceptual understanding the text, such as <strong><em>is, to, for, at, I, it etc.</em></strong></p><pre>from nltk.corpus import stopwords<br>stopWords = set(stopwords.words(&#39;english&#39;))<br>description = getDescription()</pre><pre>description = [word for word in description if not word in stopWords]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LUfcLzzmjaaHoOegdo3kJg.png" /><figcaption>After removing stop words.</figcaption></figure><h3>Transforming the data</h3><p>But cleaning and stemming the data won’t actually help us do any machine learning, as we also need to transform the descriptions into something the machine understands, which is numbers.</p><h4>Bag of Words</h4><p>For this, we’re using the Bag of Words (BoW) approach. If you’re not familiar with BoW, I’d recommend you to read <a href="https://www.kaggle.com/c/word2vec-nlp-tutorial/details/part-1-for-beginners-bag-of-words">this Kaggle tutorial</a>.</p><p>BoW is a simple technique to turn <strong>text phrases into vectors, </strong>where each item in the vectors represents a specific word. <a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html">Scikit learn’s CountVectorizer</a> gives you super simple way to do this:</p><pre>from sklearn.feature_extraction.text import CountVectorizer</pre><pre>vectorizer = CountVectorizer(analyzer = ‘word’, max_features=5000)<br>vectorizer.fit(training_data)<br>vectorized_training_data = vectorizer.<a href="http://scikit-learn.org/stable/modules/generated/sklearn.feature_extraction.text.CountVectorizer.html#sklearn.feature_extraction.text.CountVectorizer.fit_transform">transform</a>(training_data)</pre><p>The <strong>max_features </strong>parameter tells the vectorizer how many words you want to have in our vocabulary. In this example, the vectorizer will include the 5000 words that occur most frequently in our dataset and reject the rest of them.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dLQR2Av4OBu2nbC-ZrDnoQ.png" /><figcaption>An example of a very small (35 items) Bag of Words vector. (Ours is 5K items long).</figcaption></figure><h4>Tf-idf Transformation</h4><p>Finally, we also apply a <strong>tf-idf</strong> transformation, which is a short for <strong>term frequency inverse document frequency. </strong>It’s a technique that adjusts the importance of the different words in your documents.</p><p>More specifically, tf-idf will emphasise words that occur frequently in a description (<strong>term frequency</strong>), while de-emphasise words that occur frequently in the entire dataset (<strong>inverse document frequency</strong>).</p><pre>from sklearn.feature_extraction.text import TfidfTransformer<br>tfidf = TfidfTransformer(norm=’l1&#39;)</pre><pre>tfidf.fit(vectorized_training_data)<br>tfidf_vectorized_data = tfidf.transform(vectorized_training_data)</pre><p>Again, <a href="http://scikit-learn.org/stable/">scikit learn</a> saves the day by providing tf-idf out of the box. Simply <strong>fit</strong> the model to your vectorized training data, and then use the <strong>transform </strong>method to transform it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2h_4HxOrGAG5tEgtpciDwg.png" /><figcaption>The vector after applying tf-idf. (Sorry about the bad formatting)</figcaption></figure><h3>The algorithm</h3><p>After all the data has been <strong>cleaned</strong>, <strong>vectorised</strong> and <strong>transformed</strong>, we can finally start doing some machine learning, which is one of the simplest parts of this task.</p><p>I first sliced the data into 70% training data and 30% testing data, and then started off with two <a href="http://scikit-learn.org/stable/">scikit learn</a> algorithms: <a href="http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html">Random Forest</a> (RF) and <a href="http://scikit-learn.org/stable/auto_examples/neighbors/plot_classification.html">K Nearest Neighbors</a> (KNN). It quickly became clear that RF outperformed KNN, as the former quickly reached more than 80% accuracy while the latter stayed at 60%.</p><p>Fitting a scikit learn model is super simple:</p><pre>def runForest(X_train, X_test, Y_train, Y_test):<br> forest = RandomForestClassifier(n_estimators=100)<br> forest = forest.fit(X_train, Y_train)<br> score = forest.score(X_test, Y_test)<br> return score</pre><pre>forest_score = runForest(X_train, X_test, Y_train, Y_test)</pre><p>So I continued with RF to see how much I could increase the accuracy by tuning the following parameters:</p><ul><li><strong>Vocabulary:</strong> how many words the CountVectorizer includes in the vocabulary (currently 5K)</li><li><strong>Gram Range:</strong> size of phrases to include in Bag Of Words (currently 1–3, meaning up until ‘3 word’-phrases)</li><li><strong>Estimators:</strong> amount of estimators to include in Random Forest (currently 90)</li></ul><p>With these parameters tuned, the algorithm reaches an accuracy of 86,4% on the testing dataset, and is actually starting to become useful for our sales team.</p><h3>The road ahead</h3><p>However, the script is by no means finished. There are <strong>tons</strong> of way to improve it. For example, the algorithm is likely to be biased towards the kind of descriptions we currently have in our training data. This might become a performance bottle neck when testing it on more real world data.</p><p>Here are a few activities we’re considering to do in the road ahead:</p><ul><li>Get more data (scraping, other API’s, improve data cleaning)</li><li>Test other types of data transformation(e.g. word2vec)</li><li>Test other ml algorithms (e.g. neural nets)</li></ul><p>We’ll be pushing to <a href="https://github.com/Xeneta/leadQualifier">GitHub</a> regularly if you want to follow the progress. And feel free to leave a comment below if you have anything you’d like to add.</p><p>Cheers,</p><p><a href="http://www.twitter.com/perborgen">Per Harald Borgen</a></p><p>Thanks for reading! We are <a href="http://www.xeneta.com/">Xeneta</a> — the world’s leading sea freight intelligence platform. We’re always looking for bright minds to <a href="http://www.xeneta.com/our-company/careers">join us</a>, so head over to our <a href="http://www.xeneta.com/">website</a> if you’re interested!</p><p>You can follow us at both <a href="https://twitter.com/xeneta_as">Twitter</a> and <a href="https://medium.com/xeneta">Medium</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbcf2e618be3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/xeneta/boosting-sales-with-machine-learning-fbcf2e618be3">Boosting Sales With Machine Learning</a> was originally published in <a href="https://medium.com/xeneta">Xeneta</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>