Deploy a Celery app on Vercel
Deploy a Celery app to Vercel with the Python runtime, Vercel Queues, and Vercel Functions. Vercel builds each Celery worker as a private, queue-triggered Vercel Function, so you don't need to run a long-lived worker process.
Create a Celery app or use an existing one:
Celery projects on Vercel must declare their dependencies in pyproject.toml
[project]name ="celery-on-vercel"version ="0.1.0"requires-python =">=3.12"dependencies = ["celery>=5.3.0","fastapi",]This example uses FastAPI to enqueue tasks. You can use any supported Python web framework for the producer.
Create a Celery application and set its default queue:
import osfrom celery import CeleryQUEUE_NAME ="celery"app =Celery("celery-on-vercel", broker=os.getenv("CELERY_BROKER_URL", "vercel://"),)app.conf.task_default_queue = QUEUE_NAME@app.taskdefadd(x:int,y:int) ->int:return x + yThe vercel:// broker sends Celery tasks to Vercel Queues. Vercel sets
CELERY_BROKER_URL to vercel:// automatically during local development and
after deployment unless you set the environment variable yourself.
Export the Celery application from a worker entrypoint. Importing tasks
registers its tasks on the application:
from tasks import app__all__= ["app"]Add the web entrypoint and Celery worker to pyproject.toml:
[tool.vercel]entrypoint ="main:app"[[tool.vercel.subscribers]]entrypoint ="worker:app"topics = ["celery"]The subscriber entrypoint uses the module:object format. The topics value
must match the Celery queue name in tasks.py.
Vercel builds main:app as the public web application and worker:app as a
private Vercel Function. Only Vercel Queues can invoke the worker function.
Import a task into your web application and call delay as you would in any
Celery application:
from fastapi import FastAPIfrom tasks import addapp =FastAPI()@app.post("/tasks")defenqueue_task(x:int,y:int): task = add.delay(x, y)return{"taskId": task.id}Each call to delay publishes a message to the celery topic. Vercel Queues
then invokes the subscriber function to run the task.
Use vercel dev to run the web application and Celery subscriber locally:
vercel devvercel dev starts both your web application and Celery worker locally. You
don't need to run celery worker in another terminal.
Deploy the project by connecting your Git repository or by using the Vercel CLI:
vc deployVercel installs the Celery adapter during the build and provides Queue authentication to the deployed functions. You don't need to provision Redis, RabbitMQ, or separate queue credentials.
When your web function calls delay or apply_async, the Vercel broker
transport publishes the task to the configured topic. Vercel Queues invokes the
private subscriber function, which runs the task and acknowledges the message
after it succeeds.
If the function raises an exception or times out, Vercel Queues makes the message available for another delivery. Queues provides at-least-once delivery, so tasks should be idempotent.
To control the retry delay or limit concurrent task executions, add options to the subscriber:
[[tool.vercel.subscribers]]entrypoint ="worker:app"topics = ["celery"]retry_after_seconds =60max_concurrency =10See Queues concepts for details about retries, visibility timeouts, concurrency, and message retention.
Celery tasks run inside Vercel Functions, so all Vercel Functions limitations apply, including maximum duration and bundle size.
- Task arguments: Arguments must be JSON-serializable. Vercel Queues supports messages up to 100 MB.
- Long-running processes: Vercel uses queue-triggered functions instead of a
persistent
celery workerprocess. Worker control commands and features that require persistent process state aren't available. - Periodic tasks:
celery beatrequires a long-running process. Use Vercel Cron Jobs to call a route that enqueues Celery tasks.
For more about deploying Celery on Vercel, see:
Was this helpful?