Online inference

Online inference is running a model on demand, the moment a request arrives, and returning the result straight away, as opposed to working out predictions in advance in batches.

There are two basic ways to get answers from a trained model. Google's Machine Learning Crash Course calls them dynamic inference, also known as online or real-time inference, where predictions are generated on demand when a client asks, and static inference, also known as offline or batch inference, where predictions for common inputs are worked out in advance and stored. Every chatbot conversation is online inference: the reply cannot be prepared before the question is asked.

Each approach has costs. Online inference can handle any input, including rare ones nobody anticipated. But it is compute-intensive and sensitive to delay, which can force teams to use simpler models, and it needs closer monitoring because there is no chance to check predictions before users see them. Batch inference makes cost less of a concern and lets predictions be reviewed before release, but it has nothing to offer for inputs it did not anticipate, and its results can be hours or days out of date. Google's illustration: a model that takes an hour per prediction belongs in a batch job, while one that answers in 2 milliseconds suits online use.

Many products use both. An online shop might compute each customer's homepage recommendations overnight in a batch, then use online inference to suggest related items the moment something lands in the basket. A fraud check on a card payment has to be online, because the decision is needed before the payment is approved.

Cloud platforms package these choices. Amazon SageMaker, for example, offers real-time endpoints for interactive, low-latency work, serverless endpoints for traffic with idle periods that can tolerate a cold start, asynchronous endpoints for large requests that can wait a little, and batch jobs. Language model providers make the same split: OpenAI's Batch API charges half the price of normal requests in exchange for results within 24 hours.

The practical choice comes down to whether someone is waiting. If a person or a process needs the answer now, the request must be served online, with capacity sized for peak demand. If the answer can wait, batching is usually cheaper and easier to check.

Common questions

What is the difference between online and batch inference?

Online inference runs the model when each request arrives and returns the answer immediately. Batch inference processes many inputs together, ahead of time or on a schedule, and stores the results. Online suits interactive uses; batch suits work that can wait.

Is online inference more expensive than batch inference?

Usually, per prediction. Online systems must keep capacity ready for peak demand and meet tight time limits, while batch jobs can run when hardware is free. OpenAI, for example, prices its Batch API at half the cost of standard requests in return for a 24-hour completion window.

When should I use batch inference instead?

When nobody is waiting for the result: scoring a whole customer list, generating product descriptions for a catalogue, classifying a large archive or running evaluations. Batch work is cheaper and can be checked before anyone sees the output.

Is real-time inference the same as online inference?

Yes. Online, real-time and dynamic inference are used to mean the same thing: generating a prediction on demand when a request comes in, rather than looking up one computed earlier.

Finding more

Search for "online vs batch inference", "real-time inference endpoint" or "static vs dynamic inference" to compare the approaches. Reliable sources include machine learning courses from major providers, cloud platforms' deployment documentation and model providers' pricing and API guides. Prices and limits for batch and real-time services change often, so check the provider's current documentation.

Working out what this means for your business?

Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.