<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sasha Bagan on Medium]]></title>
        <description><![CDATA[Stories by Sasha Bagan on Medium]]></description>
        <link>https://medium.com/@pnlbagan?source=rss-22096e9829c1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*zPnEQvY8fQMdvJCoCOJZCg.jpeg</url>
            <title>Stories by Sasha Bagan on Medium</title>
            <link>https://medium.com/@pnlbagan?source=rss-22096e9829c1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 06:25:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pnlbagan/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[What it takes to deploy a model]]></title>
            <link>https://medium.com/data-science/what-it-takes-to-deploy-a-model-30864cd9477f?source=rss-22096e9829c1------2</link>
            <guid isPermaLink="false">https://medium.com/p/30864cd9477f</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Sasha Bagan]]></dc:creator>
            <pubDate>Tue, 31 Mar 2020 16:32:25 GMT</pubDate>
            <atom:updated>2020-04-01T13:43:10.183Z</atom:updated>
            <content:encoded><![CDATA[<h4>Basic steps and best practices when placing a machine learning model into production</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*JPEKhzGF7yk57gKO" /><figcaption>Image by <a href="https://pixabay.com/users/kreatikar-8562930/">Mudassar Iqbal</a> from <a href="https://pixabay.com/">Pixabay</a></figcaption></figure><p>So you (or your team) have spent several months juggling around notebooks with code. You’ve had sleepless nights wondering whether Word2Vec or BERT should be used for vectorizing your text inputs. You’ve trained your model on dozens (no, hundreds? Really, thousands?) of GPUs for days on end and you have finally achieved that sweet accuracy you were aiming for. This satisfaction is why you work in data science. You have your precious model.pickle file in hand. You know your company will gain tons of money by using it, but you may not realize that this moment is maybe the most failure-prone. Unfortunately, many models don’t make it to production. For example, in April 2009 Netflix organized a Kaggle competition with a prize of $1 million and the winning model never made it to production! [1]. All that work and accuracy only pays off if someone actually can use the model at the end of the day — stably, reliably, quickly and at scale to generate value.</p><p>So what does it take to actually deploy a model? Here are some basic steps and considerations for one deployment path, for you to keep in mind as your model is translated from research and development to production.</p><h3>1. Wrap Your Model in a Web Server</h3><p>Of course, many people use the manual deployment option. Your teammates can run the model manually whenever a new prediction needs to be made. But most likely this approach will not be scalable enough for your business needs. For a first step of automation, you could create a short script that will load your model and score new data, but then every time you need a prediction, you will waste time loading, and reloading, your model, which may not be an insignificant loss.</p><p>One solution to this challenge is to wrap your model with a simple web server. The web server will keep your model loaded in memory and be able to serve predictions immediately, with low latency. For most of the languages there are plenty of tutorials on how to write a web server.</p><p>To think further down the line, you should then also ask yourself: Will this server always be hosting only one model? Or later on, will you need to host multiple models together?</p><h3>2. Improving Your Web Server</h3><p>Now that you have a web server, you have to ask yourself what will happen if it crashes? Your model is hopefully powering a high-impact business process, and it’s vital to build in contingency plans for different events. A runtime exception could occur. You may have a memory leak somewhere, which causes your prediction scoring process to eventually get killed when it runs out of memory. You don’t want to have to wake up at night in an emergency to restart it, so it’s a best practice to think ahead and develop process management around your deployed model that is running separately. It will handle automatic restarts, and provide reporting mechanisms that communicate the real-time status of your service.</p><h3>3. Hosting Your Web Server</h3><p>Now that you have your model running locally, in a stable way, you need to expose it to the world. Does your company host its software on bare metal machines, or do you rely on one of the cloud providers? In any case you need to host your server somewhere. Your decisions about hosting should depend on public availability of the model. Will your model be available publicly for clients to call or will it be available in your internal network only? If the model is available publicly, you’ll need to set up an authorization mechanism for the web server in order to restrict access for malicious users.</p><p>Any software needs to be updated, so once your web server is hosted somewhere you need some process for updating it. And when changes are done, you then need to test that the service continues to work. To achieve that and ensure your team’s productivity, you should set up some form of Continuous Integration / Continuous Delivery pipeline.</p><h3>4. Highly Available Service</h3><p><strong>High availability</strong> (<strong>HA</strong>) is a characteristic of a system measuring level of operational performance. It is typically measured in percentage of the uptime time. “Two nines” or 99% uptime means that your service is unavailable for 88 hours over a year. Ask yourself: how much would it affect your business if your model went down for 88 hours?</p><p>Most web services provide Service Level Agreement on HA. But achieving even three nines (99.9%) uptime could be very hard. The host of your web server may go down. There could be a blackout in the datacenter where it is hosted. One of the foundations of high availability is eliminating single points of failure [2]. To do that, you would need to host multiple replicas of your model and balance between them. Keep in mind that spreading them geographically will reduce the amount of failures. To be able to adapt to changing load and optimize the costs of hosting, it is important to be able to scale up and down the number of replicas.</p><h3>5. Monitoring</h3><p>Even with all previous steps taken, something can still go wrong. Maybe all nodes of your server go down, or a bug was not caught by your testing pipeline. To be able to react to such emergencies, you need monitoring and alerts for your service. Collecting service logs will help uncover the root cause of such issues after they happen.</p><p>For your service updates to be based in scientific decision-making, you need to collect data on how your service currently operates. You should not say that your model is “slow”; instead you should be precise, and operate in terms of the median or other significant percentiles of response timings. You should not say that your service is failing “too much”; instead you should have exact percentages of failed requests to benchmark against.</p><h3>6. More monitoring?!</h3><p>But just monitoring the service is not enough for our use case. The moment you put a model in production, it starts degrading [3]. Most often this is related to the drift in the data your model predicts on. In order to provide accurate predictions over time, you need to monitor a model’s performance. Most popular techniques include monitoring a model’s input variables, predictions, and accuracy. Imagine a model that is using price in US dollars as an input, and let’s suppose that because of a mistake, the price in Ukrainian Hryvnia was sent instead. The model will process the request as usual, as it’s still a numeric feature, but your prediction will be very different, as that number is 30x larger now.</p><p>You would need to set up clear thresholds for when your model is considered to have drifted and get alerts for when the model is predicting with poor accuracy. Those notifications are as important as notifications about service health.</p><h3>7. Retraining</h3><p>Once you can tell clearly that your model is predicting poorly, you need to update your model with more recent data. The CI/CD pipeline we mentioned before comes in handy to continuously update your model. For retraining the model, you will need to have the updated, more recent <strong>labeled</strong> data, so you also need a process to collect new labeled data. Be careful with injecting too much historical data, as the model might work worse on recent data if it is too different from historical one. You could prioritize the most recent data over historical data.</p><p>Another interesting aspect is that for completely new data, a different ML algorithm might perform better. From time to time you should consider not just retraining the same algorithm, but to experiment with others. Or you can go above and beyond, and for every update, try automatically fitting different models and selecting the best one.</p><p>Now we’ve gone from a model to a sustainable service. While this does not cover everything, I hope it provides you a comprehensive outline of the basic needs and best practices.</p><p>References:</p><p>[1] Mike Masnick, Why Netflix Never Implemented The Algorithm That Won The Netflix $1 Million Challenge (2012), TechDirt: <a href="https://www.techdirt.com/articles/20120409/03412518422/why-netflix-never-implemented-algorithm-that-won-netflix-1-million-challenge.shtml">https://www.techdirt.com/articles/20120409/03412518422/why-netflix-never-implemented-algorithm-that-won-netflix-1-million-challenge.shtml</a></p><p>[2] Blake Thorne, Four nines and beyond: A guide to high availability infrastructure (2018), Atlassian Blog: <a href="https://www.atlassian.com/blog/statuspage/high-availability">https://www.atlassian.com/blog/statuspage/high-availability</a></p><p>[3] Alexandre Gonfalonieri, Why Machine Learning Models Degrade In Production (2019), Towards Data Science:</p><p><a href="https://towardsdatascience.com/why-machine-learning-models-degrade-in-production-d0f2108e9214">https://towardsdatascience.com/why-machine-learning-models-degrade-in-production-d0f2108e9214</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30864cd9477f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/what-it-takes-to-deploy-a-model-30864cd9477f">What it takes to deploy a model</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>