How to Deploy an XGBoost Model with Custom Pre/Postprocessing on Vertex AI?

You recently used XGBoost to train a model in Python that will be used for online serving. Your model prediction service will be called by a backend service implemented in Golang running on a Google Kubernetes Engine (GKE) cluster. Your model requires pre and postprocessing steps. You need to implement the processing steps so that they run at serving time. You want to minimize code changes and infrastructure maintenance, and deploy your model into production as quickly as possible. What should you do?

  1. Use FastAPI to implement an HTTP server. Create a Docker image that runs your HTTP server, and deploy it on your organization’s GKE cluster.
  2. Use FastAPI to implement an HTTP server. Create a Docker image that runs your HTTP server, Upload the image to Vertex AI Model Registry and deploy it to a Vertex AI endpoint.
  3. Use the Predictor interface to implement a custom prediction routine. Build the custom container, upload the container to Vertex AI Model Registry and deploy it to a Vertex AI endpoint. Source Reference Answer
  4. Use the XGBoost prebuilt serving container when importing the trained model into Vertex AI. Deploy the model to a Vertex AI endpoint. Work with the backend engineers to implement the pre- and postprocessing steps in the Golang backend service.

Community Votes

C
58%
D
21%
B
21%

58% of anonymous learners picked answer C. Votes are pick records left by other test-takers — they are not the verified answer.

Community Insight

Tests understanding of Vertex AI custom prediction routines while highlighting the trap of separating model logic from transformation steps across different services.

This question evaluates deploying machine learning workloads on Google Cloud using Vertex AI custom containers to reduce infrastructure overhead. Community consensus confirms that leveraging the Predictor interface to bundle preprocessing, inference, and postprocessing together is the most efficient approach.

Option D is often selected due to familiarity with managed prebuilt containers, but it fails because offloading preprocessing to a separate Golang backend breaks the requirement for tightly integrated serving-time processing and increases operational complexity.

Community Discussion (9 comments)

ddogg 👍 6 Selected: C
Use the Predictor interface to implement a custom prediction routine. This allows you to include the preprocessing and postprocessing steps in the same deployment package as your model. Build the custom container, which packages your model and the associated preprocessing and postprocessing code together, simplifying deployment. Upload the container to Vertex AI Model Registry. This makes your model available for deployment on Vertex AI. Deploy it to a Vertex AI endpoint. This allows your model to be used for online serving. https://blog.thecloudside.com/custom-predict-routines-in-vertex-ai-46a7473c95db
Prakzz 👍 2 Selected: B
This approach minimizes code changes and infrastructure maintenance by leveraging Vertex AI's managed services for deployment. Implementing the preprocessing and postprocessing steps in a FastAPI server within a Docker container allows you to handle these steps at serving time efficiently. Deploying this Docker image to a Vertex AI endpoint simplifies the deployment process and reduces the burden of managing the infrastructure.
AzureDP900 👍 1
Option C is a good choice if You have specific requirements for preprocessing or postprocessing that can't be met by the prebuilt XGBoost serving container. You need more control over the deployment process or want to integrate with other services. You're comfortable building and managing custom containers. However, if you just want a simple, straightforward way to deploy your model as a RESTful API, Option D (using the XGBoost prebuilt serving container) might be a better fit!
livewalk 👍 1 Selected: B
FastAPI allows to create a lightweight HTTP server with minimal code.
Yan_X 👍 1 Selected: D
し Pre-built XGBoost container already includes pre- and postprocessing steps.
guilhermebutzke 👍 2 Selected: C
My answer C: Considering pre- and postprocessing implementation, The option C directly deals with implementing the processing steps in a custom container, offering full control over their placement and execution. This documentation says: “Custom prediction routines (CPR) lets you build [custom containers](https://cloud.google.com/vertex-ai/docs/predictions/use-custom-container) with pre/post processing code easily, without dealing with the details of setting up an HTTP server or building a container from scratch.” https://cloud.google.com/vertex-ai/docs/predictions/custom-prediction-routines So, it is better to use C instead of A or B. D is better because it offers the option of pre and post-processing, which is not available in D due to its use of prebuilt serving.
36bdc1e 👍 4
C . Build the custom container, upload the container to Vertex AI Model Registry, and deploy it to a Vertex AI endpoint. This option allows you to leverage the power and simplicity of Vertex AI to serve your XGBoost model with minimal effort and customization. Vertex AI is a unified platform for building and deploying machine learning solutions on Google Cloud. Vertex AI can deploy a trained XGBoost model to an online prediction endpoint, which can provide low-latency predictions for individual instances. A custom prediction routine (CPR) is a Python script that defines the logic for preprocessing the input data, running the prediction, and postprocessing the output data.
pikachu007 👍 2 Selected: D
Considering the goal of minimizing code changes, infrastructure maintenance, and quickly deploying the model into production, option D seems to be a pragmatic approach. It leverages the prebuilt XGBoost serving container in Vertex AI, providing a managed environment for serving. The pre- and postprocessing steps can be implemented in the Golang backend service, maintaining consistency with the existing Golang implementation and reducing the need for significant code changes.
vale_76_na_xxx 👍 1
I would say D

Comments & Corrections

No comments yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Expert Analysis

Why the Answer Is Correct

Option C correctly implements Vertex AI Custom Prediction Routines (CPR), allowing developers to extend the base Predictor class to handle custom load and predict workflows. Packaging the XGBoost model with Python-based preprocessing and postprocessing into a single custom container ensures all transformations execute within the same deployment unit. This strategy aligns with Google Cloud best practices for maintaining version consistency between data transformations and model weights while leveraging Vertex AI's managed endpoints for automatic scaling.

Why the Other Options Are Wrong

Options A and B propose building a generic FastAPI HTTP server, which introduces unnecessary boilerplate code and shifts infrastructure management responsibilities away from Vertex AI's optimized serving runtime. Option D suggests using the prebuilt XGBoost container but recommends moving critical data transformations to the Golang microservice, which creates inter-service latency, complicates dependency tracking, and directly contradicts the prompt's requirement to keep processing steps integrated at serving time.

Community Comment Notes

Multiple high-voted comments emphasize that custom containers provide full control over execution flow while simplifying deployment through a unified package. Comment [4] explicitly references the official Vertex AI documentation on custom prediction routines, validating that CPR natively supports embedding preprocessing and postprocessing logic. Although several users initially favored the managed prebuilt container for its simplicity, the discussion converged on Option C once the necessity of co-locating model and transformation code was clarified.

Official Reference

Exam Strategy

When scenarios emphasize bundled preprocessing or postprocessing alongside a trained model, immediately prioritize Vertex AI Custom Prediction Routines over custom web frameworks or external microservices. Familiarize yourself with how Vertex AI manages custom containers versus prebuilt images to quickly identify solutions that minimize both code complexity and ongoing infrastructure maintenance.

Related Analysis

Practice All PMLE Questions

Access 65 questions with complete answers and detailed explanations.

View Full PMLE Practice Test →

← Back to PMLE Study Guide