Preprocessing Requests for Model Serving
An inference server is the component that runs model inference. It hosts models, has access to the hardware they need, and returns responses based on application requests.
Why a Trained Model Needs Machinery Around It
Training a model produces a set of learned parameters, but those parameters do nothing for anyone on their own. Someone typing a question into a chat window never touches the parameters directly. Their words travel across a network, get handled by software, run through the model, and come back as an answer. Everything between the user's keyboard and the model's arithmetic is the machinery that makes a model usable, and that machinery is the subject of this article.
Keep one practical question in mind as you read. When a request arrives at a deployed model, which piece of software should be responsible for deciding which model to run and which hardware to use? The rest of the article answers that question by following one request from start to finish.
Following One Request Through the Stack
Imagine a single user prompt leaving a client application. The first stop is not the model. The request enters an inference service, which is a larger body of software whose responsibilities include receiving the request, deciding where it should go, and sometimes cleaning up or transforming its contents before anything else sees it. Only after that work is the request handed to the component that actually performs the computation.
Read the diagram as a relay. The service is the outer shell that the application talks to. Inside it, routing and any preprocessing happen first. The inference server is the stage that receives a prepared request, assigns the resources needed to run the appropriate model, and produces an output. That output then travels back through the same chain to the user. The server is not the whole story: a request can be received and reshaped before the server ever sees it, and the service is the part responsible for that front portion.
What the Inference Server Does
An inference server is the component that runs model inference. It hosts models, has access to the hardware they need, and returns responses based on application requests.
Each part of that definition describes a responsibility. Hosting models means the server holds the models it is able to run. Having access to hardware means it is connected to the computing resources those models need in order to run. Returning responses means it takes an application request, uses the right model and hardware to execute it, and sends back what the model produced.
The server's job is to turn a prepared request into a model response. The request arrives in a form the server can work with, the server assigns the resources required to run the appropriate model, and the model executes on that hardware. The result is the response. Notice that the server's work begins only after the request has been received and prepared, which is why the surrounding service matters.
The Inference Service Around the Server
The relationship between the two terms is one of containment. An inference service is the broader unit, and an inference server is one part of it. The service handles receiving, routing, and possibly preprocessing requests before they reach the server. The server's own responsibilities are narrower: it holds the models it can run, it is connected to the hardware those models need, and it answers requests by using that hardware to execute the right model.
A useful way to hold this in memory is to ask, for any given piece of work, whether it happens before or after the request reaches the server. Receiving, routing, and preprocessing belong to the service. Choosing and executing a model on available hardware belongs to the server. Both are needed for a working deployment, but they are separate jobs.
Tracing a Prompt Before It Reaches the Server
A chat prompt passes through the service
A user types a question into a chat application. Trace which layer handles each step, and state the point at which the model finally runs.
- 1Client sends the prompt
The application sends the user's words out over the network. The model is not involved yet.
- 2Service receives the request
The inference service takes in the request. This is front-portion work that belongs to the service, not the server.
- 3Service routes the request
The service decides where the request should go. Routing is a service responsibility, so it happens before the server is involved.
- 4Service preprocesses if needed
The service may clean up or transform the contents of the request so the server receives a prepared request.
- 5Server runs the model
The inference server assigns the hardware needed for the appropriate model, executes it, and produces an output. This is the first point where the model computes anything.
- 6Response returns to the user
The output travels back through the service to the client application, which shows the answer.
The model runs only after the service has received, routed, and possibly preprocessed the request. The server handles execution, and the service handles everything before that.
Using a Model API or Hosting Your Own
There are two broad ways to get a model response. The first is to call a hosted model API, such as those offered by OpenAI and Google. These are inference services that you consume rather than build. When your application calls one of these APIs, the provider has already put the receiving, routing, server, and hardware layers in place. If you rely on such a service, you will not be implementing most of the techniques covered in this chapter.
The second way is hosting a model yourself. In that case the whole inference service becomes your responsibility. You must build the layers that receive and route requests, optimize how the model runs, and keep the system maintained over time.
| Responsibility | Third-party model API | Hosting a model yourself |
|---|---|---|
| Receiving and routing requests | Provider has built it | You must build it |
| Preprocessing request contents | Provider has built it | You must build it |
| Hosting the model in an inference server | Provider has built it | You must build it |
| Access to the hardware the model needs | Provider has put it in place | You must set it up |
| Optimizing how the model runs | Provider handles it | You must build it |
| Maintaining the system over time | Provider handles it | You must maintain it |
Who builds the inference service under each option
Mistakes About Where Preprocessing Happens
Common mistake Treating the inference server and the inference service as the same thing
What it looks likeSaying the server receives the user's request directly from the application.
Why it failsThe service is the broader unit. It receives, routes, and possibly preprocesses requests before they reach the server.
Do this insteadDescribe the service as the outer shell that receives the request, and the server as the inner stage that runs the model.
Common mistake Assuming the model runs as soon as the request arrives
What it looks likeBelieving the first computation happens at the moment the prompt leaves the client.
Why it failsThe request is first received, routed, and possibly reshaped by the service before the server runs anything.
Do this insteadPlace the model's execution after the service's front-portion work.
Common mistake Believing that calling a model API leaves the infrastructure work to you
What it looks likeAssuming that using a hosted API means you still have to build the routing layer and the hardware setup.
Why it failsA hosted model API is an inference service the provider has already built, so most of the techniques in this chapter are not yours to implement.
Do this insteadRecognize that a hosted API shifts the service and server work to the provider, while self-hosting makes that whole stack your responsibility.
Practice: Sorting the Work
A team is deciding between calling a hosted model API and hosting a model on its own machines. For each of these jobs, say whether it would be the team's responsibility under self-hosting, and whether it belongs to the inference service or the inference server: receiving requests, routing requests, assigning hardware to run a model, and maintaining the system over time.
Hints
- Ask whether the job happens before or after the request reaches the server.
- Under a hosted API, the provider has already built the receiving, routing, server, and hardware layers.
- Maintenance is listed as a responsibility when you host a model yourself.
Key Takeaways
- An inference server runs model inference: it hosts models, has access to the hardware they need, and returns responses based on application requests.
- An inference service is the broader unit that contains the server and handles receiving, routing, and possibly preprocessing requests before they reach it.
- A request flows from the client through the service, into the server where the model runs, and back out through the same chain to the user.
- Using a hosted model API means the provider has built the service and server layers, while hosting a model yourself makes the entire inference service your responsibility to build, optimize, and maintain.