Serving

Model serving (API)

Statistics Austria: Plumber APIs on RSconnect

Since all models are implemented in R, we use the plumber package to expose them as RESTful APIs. Each trained model is wrapped in an API endpoint that handles incoming requests, calls the standardized .predict() function, and returns the results in a structured JSON format.

These APIs are deployed on RStudio Connect (rsconnect), which provides a managed environment for hosting, scaling, and securing the services. This setup allows other applications to interact with the models in a language-agnostic way, independent of the underlying R implementation.

Deployment

Practical experience: deployment at Destatis
  • Using separate environments for development and production, that are build using the same set-up for an easy deployment using CI/CD workflows (for instance with Gitlab).
  • Using Cloudera AI Model component to standardize and simplify the transition from experimentation to production. The model component package a trained model (from experiments or registry), define how it should be served, deploy it as a live endpoint, monitor/version it and roll back if needed. Cloudera builds a Docker container image automatically, including a base runtime (Python, R, etc.), dependencies needed, model and serving code (wrapper), that will be deployed on a Kubernetes Cluster (managed by Cloudera, but possibly hosted on your private servers). At the end of the process, the model is exposed as a REST API endpoint, using the wrapper function as explained in chapter 2.
Statistics Austria: Standardized Model Query Interfaces

To facilitate interaction with the deployed APIs, we developed an R package that standardizes the process of querying the models. This package acts as a client interface between downstream applications and the deployed endpoints.

Input data, along with optional parameters (e.g. model configuration or code selections), are serialized into JSON format and sent to the API using the httr package. The API response is then parsed and transformed into a structured output table, which can be further processed or stored locally in various formats (e.g. CSV, database tables). This approach ensures a clear separation between model serving and model consumption.

From dev to production: deal with environments

Statistics Austria: Synchronized R Environments Across Deployment

To ensure consistency between development and production, package versions are explicitly defined and synchronized across environments using a requirements.txt file specifying the dependencies plus their respective version. This guarantees that the same dependencies used during model development are also available on the rsconnect instance.

By aligning environments in this way, we reduce the risk of incompatibilities and ensure that models behave identically when deployed. Combined with versioned code and model artifacts, this setup supports a smooth transition from development to production and contributes to the overall reproducibility and stability of the system.