beam-logo
Task Queues

Fan out long-running, GPU-heavy functions across the cloud with a single function call. Enqueue from an API or directly in Python, run thousands of tasks in parallel, and retrieve results when they’re ready — with automatic retries and zero infrastructure to manage.

app.py
from beam import task_queue, Output


# Run resource-intensive functions asynchronously
@task_queue(cpu=1.0, memory=128, gpu="A10G")
def handler():
    result = 839 * 18

    # Save the result to a file
    file_name = "result.txt"
    with open(file_name, "w") as f:
        f.write(f"The result is: {result}")

    # Upload the output to retrieve later
    Output(path=file_name).save()


# Enqueue a task from anywhere
handler.put()
Capabilities

Run thousands of tasks in parallel, without managing infrastructure.

Offload heavy functions to a managed queue, fan them out across the cloud, and retrieve results whenever you need them — Beam runs the compute and scales it for you.

How it works

From a Python function to a managed queue.

01

Define a task queue

Add the @task_queue decorator to any Python function and configure CPU, memory, GPU, and your image in one place — no YAML, no DSL, no new paradigms to learn.

02

Enqueue tasks

POST to the deployed API or call .put() in Python. Requests return a Task ID immediately and Beam fans the work out across workers so nothing blocks.

03

Retrieve your results

Get a webhook fired to your callback_url the moment a task finishes, or poll the /task API for outputs and live queue stats.

app.py
from beam import task_queue, Image


# 1. Decorate any function as a task queue
@task_queue(
    cpu=1.0,
    memory=128,
    gpu="T4",
    image=Image(python_packages=["torch"]),
)
def multiply(x):
    return {"result": x * 2}


# 2. Enqueue a task — returns instantly
multiply.put(x=10)
# => Enqueued task: f0d205da-e74b-47ba...

# 3. Retrieve the result via webhook or the /task API
FAQ

Frequently asked questions.

What is a task queue?

A task queue lets you deploy resource-intensive functions on Beam. Instead of processing tasks immediately, you add them to a queue and process them later — either sequentially or concurrently — without blocking the caller.

When should I use a task queue instead of an endpoint?

Endpoints are RESTful APIs designed for synchronous tasks that complete in 180 seconds or less. For longer-running or GPU-heavy jobs, use an async task_queue so requests return immediately and the work runs in the background.

Can I run tasks in parallel?

Yes. Enqueue as many tasks as you need and Beam fans them out across workers to run concurrently, autoscaling to handle the load and scaling back to zero when the queue is empty. You can also process tasks sequentially when ordering matters.

Do I have to manage any infrastructure?

No. Unlike self-hosted orchestrators that make you run and scale your own workers, Beam runs the compute for you. Define a function, attach the GPU and resources you need, and Beam provisions, scales, and tears down the workers automatically.

How do I create one?

Add the @task_queue decorator to any function and configure cpu, memory, gpu, and your image. You can then enqueue tasks over the deployed API or directly in Python with .put().

How do I get the result of a task?

Because task queues are async, the API returns a Task ID. Retrieve results either by adding a callback_url so Beam fires a webhook when the task completes, or by polling the /task API, where your saved Outputs appear in the outputs list.

What happens if a task fails?

Task Queues include a built-in retry system. If a task fails for any reason, such as an out-of-memory error or an application exception, it's retried three times before automatically moving to a failed state.

Can I queue tasks without exposing an endpoint?

Yes. Call the .put() method directly in Python to insert tasks into the queue programmatically — useful for triggering work from scripts or other services without deploying an API.

$30 free creditrefreshed monthly

Start shipping on infra
you won’t outgrow.

Run sandboxes and GPU workloads on your cloud, and scale out to ours when you need to. No infra to manage.