Serving models
Professional Machine Learning Engineer · Lesson 12 of 19 · 1:32:51
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Google Cloud Professional Machine Learning Engineer exam, on the official exam guide. In this lesson: online versus batch inference, Agent Platform Inference, Model Garden deployments, Cloud Run with GPUs, GKE, prebuilt serving containers (TensorFlow, PyTorch, scikit-learn, XGBoost), and custom containers (HTTP server, port, health and inference routes). Includes three original practice questions, with Cymbal Insurance, a fictional car and home insurer, as the example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Three ways to use one model
Cymbal Insurance's new fraud model is trained, and three teams want to use it. The claims app needs a score within a fraction of a second, and the renewal team needs four million scores once a month. Meanwhile, another team wants an open language model behind a chatbot prototype.
Online and batch inference
For online inference, you upload the model to Model Registry, deploy it to an endpoint, and each request gets an answer in real time, while you pay for the serving nodes as long as the model stays deployed. For batch inference, a job reads its input from Cloud Storage files or a BigQuery table, and writes the results to Cloud Storage or BigQuery. A batch job needs no endpoint, but the model must be in Model Registry, and the input and output must be in the model's region. So choose online inference when someone waits for each answer, and batch inference for large sets on a schedule.
Where to serve
Several services can serve a model. Agent Platform Inference gives managed endpoints with autoscaling, monitoring, and explanations. Model Garden deploys open models to an endpoint in a few clicks, and offers partner models through a managed API. Cloud Run serves any container without servers to manage, with GPUs on demand, like the L4, instances that start in seconds, and scaling down to zero when idle. And GKE gives full Kubernetes control over your own serving stack, but your team then runs the cluster.
Prebuilt containers
Prebuilt containers serve the common frameworks with no container to build: TensorFlow, PyTorch, scikit-learn, and XGBoost, plus an optimized TensorFlow runtime. You save the trained model's files to Cloud Storage, upload them to Model Registry with the matching prebuilt image, and deploy. Each image version has its own end of support, so keep the framework version current. This is the fastest path from a trained model to an endpoint.
Custom containers
A custom container fits other frameworks, extra libraries, or your own serving logic. The container runs an HTTP server, and Agent Platform sends it health checks and inference requests on the declared port, which is eight zero eight zero by default. You set the health route and the inference route, and store the image in Artifact Registry. The same model and container can then serve an endpoint or a batch job. And for simple preprocessing, custom inference routines, covered in lesson thirteen, avoid writing a web server at all.
Recap
Let's recap. Online inference needs an endpoint and answers in real time, and batch inference reads and writes Cloud Storage or BigQuery, with no endpoint. Agent Platform Inference gives managed endpoints, and Model Garden deploys open models in a few clicks. Cloud Run serves containers with GPUs on demand, and scales to zero, while GKE gives full control. Prebuilt containers serve TensorFlow, PyTorch, scikit-learn, and XGBoost. And custom containers run an HTTP server on the declared port, with health and inference routes.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
A chatbot prototype serves an open model on a GPU, gets bursts of traffic during office hours, and almost none at night. The team wants to pay nothing while it sits idle. Which option fits?
- A dedicated endpoint with one GPU node
- A new GKE cluster with a GPU node pool
- Cloud Run with a GPU
- A daily batch inference job
Show the answer
Cloud Run with a GPU
Cloud Run serves the container with a GPU on demand, starts new instances in seconds, and scales down to zero at night. “A dedicated endpoint with one GPU node” would keep paying for a dedicated GPU node all night long. “A new GKE cluster with a GPU node pool” would add a whole cluster to run, for a simple prototype. And “A daily batch inference job” would only answer once a day, which no chatbot can do.
A data scientist trained an XGBoost model in a notebook, and the claims app needs online scores this week. The team has no container experience. What is the fastest path?
- Upload it with the prebuilt XGBoost container
- Write a custom container with a web server
- Retrain the model with AutoML
- Run a monthly batch inference job
Show the answer
Upload it with the prebuilt XGBoost container
The prebuilt XGBoost container serves the saved model on an endpoint, with no container to write. “Write a custom container with a web server” would add container work that the team does not know, for no benefit here. “Retrain the model with AutoML” would throw away a model that already works. And “Run a monthly batch inference job” would only give monthly scores, while the app needs them online.
A custom container deploys, but the endpoint never becomes ready, and the logs show failed health checks. The server listens on port 5000, and no port was declared. What should the team fix?
- Add more nodes to the endpoint
- Deploy it in another region
- Retrain the model
- Serve on port 8080, or declare port 5000
Show the answer
Serve on port 8080, or declare port 5000
Agent Platform sends health checks to the first declared port, or to eight zero eight zero by default, so the server must listen there. “Add more nodes to the endpoint” would only add nodes that fail the same health checks. “Deploy it in another region” would move the same mistake to another region. And “Retrain the model” would change the model, not the port that nobody listens on.