In this episode of Data Science at Home, weβre diving deep into the powerful strategies that top AI companies, like OpenAI, use to scale their systems to handle millions of requests every minute! From stateless services and caching to the secrets of async processing, discover 9 essential strategies to make your AI and machine learning systems unstoppable. Whether you're working with traditional ML models or large LLMs, these techniques will transform your infrastructure. Hit play to learn how the pros do it and apply it to your own projects!
Thanks for reading Data Science at Home! This post is public so feel free to share it.
This is a public episode. If you would like to discuss this with other subscribers or get access to bonus episodes, visit datascienceathome.substack.com
Audio and video play straight from the show's own hosting. PodSubs stores and serves no media.
Transcript
From the show. Tap a time to play from there.
SPEAKER_00So I think this is one of the best infographics that I've ever found in the last few years. And to give the credits, of course, to the authors of this, this is awesome. ByteByteGo is the newsletter that you definitely would like to subscribe to. It's not mine and they're not sponsoring this show. So I'm just being absolutely honest with the quality of these infographics, which I really, really like. It's about scalability strategies, and of course the links will be reported in the show notes of this episode on the official website, datasensitome.com,
SPEAKER_00and of course also on the YouTube channel. Now, scalability strategies are of absolute importance, and this really doesn't matter if you're doing traditional machine learning algorithms in production, or a new cutting edge large language model. So it really doesn't matter what type of estimation or prediction you're running in production. These are strategies that you definitely would like to take into account and to
SPEAKER_00consider because they will save you a lot of time and a lot of money probably, or both. So I'm going to start from the first one, which is stateless services. You know, these are a must when you're looking for quite easy scalability. Since these services don't rely on server-specific data, they are easier to replicate or replace. So think about a traditional machine learning example in which, you know, in a system that serves prediction from, let's say, a trained decision tree model,
SPEAKER_00one of these, you know, very first and easy machine learning models, that we were dealing with several years ago. Now, making the service stateless means that any server can handle requests without needing to store session data or, you know, track user states and stuff like that. So every server just takes the inputs, loads the model, makes the prediction and returns, you know, the result. That's all. If you want to think about a large language model example,
SPEAKER_00when you are deploying a massive large language model like GPT family of models, making the inference service stateless, it doesn't make that much sense, in my opinion, because it means that every request is independent, which is rarely the case. So you don't store past conversation context unless explicitly designed, which is usually the case. But it would allow load to be balanced across multiple servers, handling inference without worrying about where each session resides.
SPEAKER_00But I'm pretty sure that large language models do not want to use this kind of strategy when it comes to inference in production. So that's the first. Then we have horizontal scaling. Now, horizontal scaling is a classic way to share workload by adding more servers rather than upgrading a single machine. So whenever you hear horizontal scaling, especially in corporate, what they are actually doing is like adding machines to their data warehouse and increasing the capacity of their information system.
SPEAKER_00That's what it is. Now, with traditional machine learning example, say you have a a model serving thousands of predictions per second okay so by horizontally scaling the prediction service you can actually distribute the requests across multiple servers more or less linearly more or less linearly ensuring that none get overwhelmed so you don't really target one single server because that would create you know a bottleneck in the system um At the same time, you kind of distribute your workload,
SPEAKER_00you know, across multiple servers, and you also maintain low latency for your users. So that's something that has been used extensively with traditional machine learning models. When it comes to large language models, which are, you know, computationally expensive, horizontal scaling, of course, is extremely important, but it's a tiny difference with respect to, you know, the traditional machine learning example, because if the demand for inference increases, you can spin up additional GPUs. And that's usually what people do, or even TPUs, if you have.
SPEAKER_00sometimes even entire nodes dedicated to serving the large language model across different machines to avoid bottlenecks. Now, I don't know exactly how do they do at OpenAI. They didn't disclose, you know, the architecture of their systems. But I... you know, can believe that they use some kind of horizontal scaling in which they probably replicate instances of, you know, large language models in multiple instances. So basically the same model launched a number of times,
SPEAKER_00probably several thousand times in order to perform this strategy. The third is about load balancing, this one. Such a nice infographic, really. Amazing, amazing job guys at ByteBiteGo. Thank you so much for sharing this. Well, load balancing is in fact an art because it's the art of distributing incoming requests evenly across multiple servers. And that's exactly what you see here in this infographics. This ensures that optimal resource use and preventing overload on a single machine.
SPEAKER_00Quite similar to horizontal scaling in terms of the purpose, the goal that you would like to achieve, but the strategy is absolutely different. So let me give an example with traditional machine learning. Whenever, let's say, one of these old web apps that integrates real-time image classification, for example, So you have a load balancer that could help distribute incoming image requests across several model instances to prevent one server from being overwhelmed, okay? In the large language model setting or setup,
SPEAKER_00load balancing becomes even more critical, especially when multiple clients are accessing your models for inference. Now, each model call might take significant compute time because these are, you know, BISCs, billions of parameters. So distributing those requests across a fleet of GPUs or TPUs is absolutely essential to keep response times, you know, reasonable. Autoscaling is the fourth strategy that you might be looking at. Now, auto scanning dynamically adjusts resources based on current demand.
SPEAKER_00And this is absolutely amazing strategy for so-called unpredictable traffic. OK, so in a traditional machine learning example, Think of a sentiment analysis API running on a cloud platform. During peak hours, more users might want to analyze their data. So you set up auto-scaling policies that spin up additional model instances when traffic spikes. And then you scale them down during off-peak hours because you need to save costs. So that's the typical example, very traditional now, the way you scale up and scale down things.
SPEAKER_00And that's exactly what auto-scaling is actually doing. For large language models, auto scanning is also invaluable because serving LLMs in production is, as we all know, resource intensive. It's also very expensive. So when the system detects a surge in usage, it can provision additional GPUs to handle the increased load. And when demand drops, those resources are freed up automatically, balancing cost and performance, right? This usually goes hand in hand with,
SPEAKER_00I think, database replication, but I will explain that a bit more later. Now, the fifth is caching. So caching is about reducing the load, usually on a database by handling repetitive tasks, you know, with quick and stored responses, which are called cached information, cached data. Now, in a traditional machine learning example, imagine the most classic one, movie recommendation engines,
SPEAKER_00right, where users often request similar movie recommendations. Now, you could cache the top, let's say, 10 recommendations for each genre in your database. And instead of quitting the database over and over again, or the model every time, you can, you know, serve cached results almost instantly. That's exactly how caching systems have been used so far. In a large language model example, it's a bit more, you know, tricky because, you know, caching, it's quite dangerous to use caching,
SPEAKER_00especially on the responses of the prompts because, you know, you want to give the feeling that the large language model is thinking and always giving you different answers. So what you can cache probably there is, you know, similar prompts. but not as a prompt. Probably you want to cache the, let's say, the embedded version of the prompts. And then, you know, with the temperature of the model, you can generate different responses
SPEAKER_00semantically similar or semantically very close to each other, but, you know, you want to give the user the feeling that you don't have a broken radio in front of you that repeats over and over the same things because, you know, you're using the cache instead of actually running the model, right? Then we have database replication. Replicating the database, so this thing here, Replicating your database across multiple nodes allows for scalable read operations
SPEAKER_00and also improves redundancy. So the typical machine learning example, let's take an online retail system that is using whatever machine learning model to recommend products to customers, right? So you might replicate your product database across several nodes, so users in different regions of the world can get fast recommendations without overloading a single node with requests. Okay. And I said that this can go hand in hand with the, what was that? The auto scaling.
SPEAKER_00It's exactly because you might be thinking of, let's say, your population of users in the United States, then in Europe, then in Middle East and so on. So according to different time zones, you will see these zones, you know, people will go to sleep at some point and these peak hours will move in the planet, right? According to the time zone. So that's exactly what you would like to do. A strategy that combines auto scaling and database replication in order to, you know,
SPEAKER_00follow your users where they are or, you know, where the peak hour might be very likely. during the day or during the days, because it's going to be across several hours. So, you know, this combination is absolutely, you know, is incredible. It will save you a lot of time. It will save a lot of money, actually, especially maintaining the same quality of service. I guess we are at database sharding. So sharding means splitting your database into smaller and usually more manageable chunks,
SPEAKER_00which helps with both read and write operations. In a traditional machine learning example, think about in FinTech, when I was working for FinTech, a fraud detection system, right? It might use database sharding to split transaction records. You can have like billions of transactions based on whatever criteria, for example, user location or transaction type, okay? Now this reduces the load on individual servers as each shard only handles a specific portion of the data.
SPEAKER_00That's what happened several years ago. It still happens. So these things are not obsolete at all. Actually, they are used and very common today. In a large language model setting, I think that for inference, database sharding might not make a lot of sense, you know, because you cannot really predict what the user is going to ask you. Sharding might make sense during training. So in training phases with massive datasets,
SPEAKER_00sharding the dataset itself can be crucial for a large language model. The training process can load only specific chunks or shards of data, allowing faster training iterations and avoiding memory overload. This, I think, again, I don't know what happens at OpenAI, which is the biggest commercial company that we know, are serving large language models in production. But I believe it would be plausible that these guys are actually doing sharding when they train models overnight or when they fine tune models overnight.
SPEAKER_00And finally, we have a sync processing. This is quite cool one because, you know, it allows you to offload resource heavy tasks to background workers. As you can see here, you have one single server can have multiple servers as well, but you can have multiple workers. And what you have to do with the sync processing is essentially offloading resource heavy tasks to these background workers. And this lets you handle time consuming tasks asynchronously while keeping the main service responsive.
SPEAKER_00So the server can keep taking requests from users, giving the feeling that is always there, not loaded at all. And at the same time, all the workers are actually performing the actual task. and so in a traditional machine learning example think about a system that classifies images you can move some of the logic or so-called heavy pre-processing steps like resizing filtering blurring whatever into an asynchronous task and then of course you might have a task queue eventually and this will let the main
SPEAKER_00application continue serving users while the images get processed in the background For a large language model, you might think of async processing when it comes to batch processing usually. So when using a large language model, for example, content generation, you have these long running tasks like summarization or large text generation that can be handled asynchronously. Users would submit the requests and then once the task completes, the result is sent back without blocking new requests from coming in.
SPEAKER_00So this is usually advised for, you know, when you don't need interactivity between the model and the user, typical example of a chat, but when the user will submit a request or a bunch of requests to the server and then the server can actually offload this to workers, separated workers. So yeah, that's, as I said, an amazing infographics, really, really clear, amazing colors, amazing layout, everything is perfect. ByteByteGo did a really great job here, but I want to say that these strategies aren't just theoretical,
SPEAKER_00they're actually necessary for any modern system trying to scale gracefully. And whether you are scaling a traditional machine learning model, or working on cutting-edge large language models, these massive billion-parameter models, understanding how to apply these strategies effectively can save you and actually will save you a lot of headaches, money, and time. Speak with you next time.
We are excited to be featured in list of the top machine learning and data science podcasts in the world! https://www.millionpodcasts.com/machine-learning-podcasts/ https://www.millionpodcasts.com/data-science-podcasts/...
Everyone's quoting Karpathy's "vibe coding" post. Almost no one quotes the part where he says it's for throwaway weekend projects, not production. Struggling with AI and Software? Here is my new book available for...
What do they mean when they say "AI is the new electricity" exactly. AI is much more than that. It is, in fact, infrastructure and public good. In this episode I expand on that. Struggling with AI and Software? Here is...
What is the state of AI and videogames? Who is considering it? What are the big fails so far? This and much more is covered in this 1st episode of AI and videogames. Buy me a coffee https://ko-fi.com/datascience Discord...
A classifier went from a $200M to a $7.5B valuation in 24 days. We've seen this before: blockchain. Same hype, same irrational money. And no, it's not like the dot-com fiber boom: fiber lasts decades, GPUs go obsolete...