CLOUD CONCEPT

Online Inference

Online inference uses a deployed machine learning model to generate predictions or other outputs on demand as application requests arrive.

Cloud Concepts Hub →

What is Online Inference

Online inference connects a trained model to a live application so that new inputs can produce timely outputs, such as fraud scores, recommendations, or generated text. It matters when decisions depend on current requests rather than predictions computed in advance, requiring careful management of latency, availability, capacity, and cost.

Online inference is the use of a deployed machine learning model to process incoming application requests on demand. An application sends input to a model-serving endpoint and receives a prediction, classification, score, embedding, or generated response. Typical examples include scoring a payment before authorizing it, ranking products when a shopper opens a page, and answering a question in a chat application. The defining characteristic is that inference is triggered by current demand rather than a scheduled job over a collected dataset.

In the cloud, engineers commonly package a model and its inference code into a managed serving endpoint or a container-based application. A request is authenticated, validated, transformed into the model's expected input format, and passed to the model. The application then receives the processed output. Feature retrieval, network communication, preprocessing, model execution, and postprocessing all contribute to end-to-end latency. A fast model alone does not guarantee a fast application.

Real-time inference usually refers to synchronous online inference: the caller waits for an answer within the application's response-time budget. A checkout fraud check might need a result within a few hundred milliseconds, while a generative assistant may take longer and stream output as it becomes available. In machine learning discussions, real-time generally means sufficiently responsive for the application, not a hard guarantee that every request finishes before a strict deadline.

Batch inference processes a collected dataset as a job, such as scoring all customers overnight for a marketing campaign. It is appropriate when results are not needed immediately and can prioritize throughput and efficient resource utilization. Precomputing recommendations in a batch and retrieving them during a page request is not online model inference at retrieval time, although the application itself responds interactively.

Asynchronous inference accepts a request for later processing and returns the result separately, often through stored output, polling, or a notification. It is useful for long-running work, large inputs, or traffic that can tolerate queueing. An asynchronously submitted document-analysis request is demand-driven, but it does not have the same response contract as synchronous real-time inference. Exam questions commonly distinguish asynchronous, real-time, and batch inference by when work runs and how the caller receives results.

Serverless inference describes infrastructure management and capacity allocation rather than a separate timing requirement. A serverless endpoint can provide synchronous online inference without requiring the customer to manage individual servers. Depending on the service and configuration, scaling from zero or initializing a model can introduce cold-start delays. Provisioned capacity can improve predictability but adds cost, so serverless does not automatically mean lower latency or lower expense.

Production designs balance response time, throughput, availability, model quality, and cost. Continuously running instances can provide predictable readiness but incur charges during idle periods. Autoscaling helps handle variable traffic, although new capacity may take time to become ready. Engineers should load-test realistic payloads and concurrency, monitor tail latency and errors, and define timeouts and fallback behavior. They should also protect sensitive inputs, keep inference transformations consistent with training, and monitor prediction quality. Online inference does not mean online learning: generating a prediction normally does not update the model's parameters.

Key aspects of Online Inference

Online inference combines demand-driven predictions with explicit latency targets, suitable hosting capacity, reliable request handling, and ongoing model-quality monitoring.

Demand-driven model execution

The model processes inputs when an application needs an answer rather than waiting for a scheduled dataset-processing job. Use it when the output depends on the current user action or transaction.

Application-specific latency budgets

Measure the complete request path, including feature retrieval, preprocessing, network calls, and model execution. Track high-percentile latency because occasional slow requests can disrupt checkout flows or interactive experiences.

Distinct response contracts

Synchronous real-time inference returns the result within the active request, while asynchronous inference delivers it separately. Batch inference processes a collected dataset when immediate per-request results are unnecessary.

Independent hosting choices

Online inference can run on provisioned infrastructure or serverless infrastructure. Select a hosting model based on traffic variability, model resource requirements, startup behavior, and cost rather than assuming serverless means real-time.

Production reliability and scaling

Serving capacity must support expected concurrency and traffic bursts without excessive queueing. Configure timeouts, controlled retries, capacity limits, and appropriate fallback responses to prevent overload from spreading through the application.

Separation from model training

Inference applies an existing model; it does not normally retrain it or update its parameters. Keep input transformations compatible with training and monitor quality as real-world inputs change.

Cloud services for Online Inference

These services provide alternative managed paths for connecting applications to models; they do not need to be combined. SageMaker AI, Vertex AI, and Azure Machine Learning support deploying models behind online endpoints, while Amazon Bedrock exposes managed foundation models through inference APIs. In an application architecture, the serving service works with authentication, input validation, feature or context retrieval, and monitoring. Choose synchronous online inference when the caller needs an answer during the interaction, asynchronous processing when delayed delivery is acceptable, and batch processing for collected datasets. Evaluate serverless hosting separately from these response patterns.

Amazon SageMaker image Amazon SageMaker

Hosts models behind real-time endpoints for synchronous online inference and offers serverless inference for supported workloads. Its asynchronous inference and batch transform options illustrate how response timing and workload shape influence the choice of inference mode.

Open Amazon SageMaker →
Amazon Bedrock

Provides managed APIs for invoking foundation models on demand, including response streaming for supported models and APIs. Applications use these capabilities for interactive generation without managing the underlying model-serving infrastructure.

Open Amazon Bedrock →