Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Serverless Computing

Serverless computing runs code on demand while the provider manages and scales servers, down to zero, billing per request. Covers cold starts and AI use.

Serverless computing is a cloud execution model in which the provider runs code only when an event calls for it, starts and scales the underlying servers automatically, shuts them down to zero when traffic stops, and bills for requests and execution time instead of reserved machines. Servers still exist, but developers never provision, patch, or size them. The model became mainstream with AWS Lambda, announced in November 2014, and now spans function platforms such as Lambda, Azure Functions, and Cloud Run functions, along with serverless containers such as Google Cloud Run and Azure Container Apps. UC Berkeley researchers described its strengths and limits in the 2019 paper "Cloud Programming Simplified: A Berkeley View on Serverless Computing". For machine learning, serverless suits model serving with bursty or unpredictable traffic, where paying for an idle GPU server between bursts would cost more than the work itself.

How Serverless Execution Works#

Code is packaged as a function or a container image and attached to triggers: an HTTP request, a file landing in object storage, a message on a queue, or a schedule. When an event arrives and a warm instance is free, the platform runs the handler on it at once. Otherwise it performs a cold start: it creates an isolated sandbox, such as one of the Firecracker microVMs that AWS built for Lambda, loads the code, starts the language runtime, and runs the initialization code outside the handler before handling the event. Instances are stateless and disposable, so anything that must outlive a request goes to external storage or a database.

Cold Starts and Machine Learning Models#

Machine learning makes cold starts expensive, because initialization imports a framework such as PyTorch and loads model weights that can take hundreds of megabytes. The standard pattern loads the model once per instance, outside the handler or on first use, so that every warm invocation reuses it. This handler follows that pattern with a ResNet-50 classifier from torchvision:

import time

import torch
import torchvision

model = None  # module state survives between invocations while the instance stays warm


def handler(event, context):
    """Classify one image tensor, building the model only on a cold start."""
    global model
    cold_start = model is None
    if cold_start:
        model = torchvision.models.resnet50().eval()  # built once per instance
    with torch.inference_mode():
        logits = model(event["image"])
    return {"cold_start": cold_start, "class_id": int(logits.argmax())}


for _ in range(3):
    start = time.perf_counter()
    response = handler({"image": torch.rand(1, 3, 224, 224)}, context=None)
    print(response["cold_start"], f"{(time.perf_counter() - start) * 1000:.0f} ms")

On an Apple M5 Pro CPU, the first call builds the network and takes roughly 0.2 seconds, while the two warm calls that reuse it take about 15 ms each. Teams shrink the remaining cold start with smaller container images, compact or quantized models, and lighter runtimes such as ONNX Runtime, or remove it by keeping a minimum number of warm instances, such as Lambda provisioned concurrency or Cloud Run minimum instances, which bills for idle time again.

Serverless for AI Workloads#

Serverless fits event-driven computer vision pipelines. An upload to object storage can trigger a function that validates and resizes the image during data preprocessing before it joins a training dataset, and in a security alarm system, a motion sensor can send a single frame to an object detection function that alerts only when it finds a person. Platform limits decide the rest: AWS Lambda runs each invocation for at most 15 minutes with up to 10,240 MB of memory and no GPU, which fits CPU inference with compact models and rules out long training runs, let alone distributed training across many GPUs. GPU serverless has filled that gap: Cloud Run attaches NVIDIA L4 GPUs to containers that still scale to zero, and platforms such as Modal bill GPU time by the second.

Ultralytics Platform gives the same trade-off to YOLO deployments: an endpoint at the default size of 1 vCPU and 2 GiB is free and scales to zero when idle, and starting from idle can take up to about a minute, while custom sizes keep one instance warm and bill for its uptime.

  • Infrastructure as a Service: Virtual machines that run, and bill, around the clock whether or not requests arrive, with the customer managing the operating system and scaling. Long training jobs usually run here.
  • Kubernetes: Orchestrates containers on clusters the team operates. Knative adds request-driven scaling to zero on top of it, which KServe uses to serve models.
  • Edge computing: Runs code on or near the devices that produce data. Serverless runs it in a cloud region, and some edge platforms combine the two by running functions in many small locations near users.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning