MLGuerrillaStart M1 →
Free · in beta·intermediate·M11-1·31 min read·Prereq: The Model as a Component (M4) and Data & State (M6). The support agent from M6 to M10 is the running example, and Harness & Reliability (M9) covers the same week from inside the code.

Production, Deployment & Scale, Part 1

The capability

What production engineering for a model call is

Production engineering for an AI feature is basically about keeping it fast and reliable once a lot of people are using it at the same time. Most of that work ends up being about the model call, because it's the slowest and least predictable thing your app depends on.

Most teams start by calling a hosted model like GPT, Claude or Gemini through their respective API. A model call can take anywhere from a few seconds to hours. Now you might be asking, why is that important? Well, because your usage is capped in tokens per minute, and every part of your app that uses the same API key shares that one cap. On top of that, the frontier labs update their models and have outages on their own schedule, so you often find out something changed at the same moment your customers do. Now, if you host an open model on your own GPUs, you won't have to deal with the lab's limits and outages, but you take on the same problems yourself. The cap becomes how many requests your GPUs can serve at once, and when the server goes down, fixing it is your job, which section 7 covers.

You can't always make the model call faster (unless you play around with reasoning and token caps), but you can work out ahead of time how much it will pile up inside your app. The number of calls in progress at any moment is just how many start per second times how long each one takes. At about 2 calls a second and 4 seconds a call, you've got around 9 of them in progress. If the provider slows down to 12 seconds a call, that's 27 in progress, which is three times as many, even though your traffic didn't change at all. Every one of them holds a connection and a worker slot while it waits, so once those run out, new users start getting errors, and a slowdown at the provider turns into an outage in your app. Section 5 works through it with the numbers from section 2.

Each request also needs the right path, and which path is right depends on who's waiting for the answer. Someone watching a chat window needs the answer to start streaming back within a couple of seconds, while a nightly job can sit in a queue for hours. If you send both of them down the same path, a big batch job can use up the token cap and leave the chat feature with nothing, which section 4 covers.

A side-by-side comparison of a database call and a model call as dependencies. The database answers in single-digit milliseconds, has a connection limit you set, is deployed by your team, returns the same answer for the same query, and is priced by instance hour. The model call answers in seconds with latency set by how many tokens it writes, has a tokens-per-minute limit shared across every workload on the key, is deployed by the provider on their schedule, can return a different answer for the same input, and is priced per token. A band underneath says every difference in the right column is a design constraint on the code around it.
Nothing here is a flaw. It is a different kind of dependency, and the code around it has to be built for that kind.

So what's left for you to control is how many calls you let run at the same time, how long each one gets before you give up on it, where work waits when there's too much of it, and what happens when the provider slows down or stops. Part 2 covers the other half of production, which is knowing what's deployed and being able to roll it back.

Where it shows up

Pretty much any product where a model call sits between a request and a response runs into this, and what it looks like depends on who's waiting on the other end.

In a chat feature, somebody is watching the screen, so you stream the answer and the budget is a couple of seconds to the first token. A nightly batch job is the opposite, since nobody is waiting at all, which means the work can go in a queue and the budget is the whole night. A webhook handler sits somewhere awkward in between, because it has to answer a third party within three seconds while the model takes eight, so the work has to move somewhere else and the handler has to answer without it. And an internal tool at low volume looks like none of these, right up until the day its volume changes.

In all four, you end up asking the same questions. How long does one call take? Which limit do you hit first? How many calls can run in parallel? And what happens when an answer comes back late?

Keep reading

The rest of this lesson is free with an account

Create a free account to read the remaining 11 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.

  1. 02The week the agent stopped answering
  2. 03A model call is slow and metered, and it can change without you touching it
  3. 04Pick the request path from who's waiting
  4. 05Capacity is arrival rate times time in the system
  5. 06A queue keeps work safe and can hide an overload for hours
  6. and 6 more