> ## Documentation Index
> Fetch the complete documentation index at: https://trigger.dev/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Self-hosting buffered tasks

> Run buffered tasks on a self-hosted instance: check your object store and its permissions, add consumer processes, size them, and know what happens when a dependency fails or you turn the feature off.

**Buffered tasks work on a self-hosted instance with no extra services: the webapp keeps buffered items in your object store and turns closed windows into runs.** They're on by default for every organization. The "private beta" note on the buffered tasks pages applies to Trigger.dev cloud only.

The defaults need no changes to Docker Compose or the Helm chart. This page covers what to check before you rely on it, how to scale it out, and how it behaves when something fails. Every variable is listed in the [webapp environment reference](https://trigger.dev/docs/self-hosting/env/webapp.md#buffered-tasks).

## Check your object store

Buffered items are stored under the `buffer/` prefix of a bucket in your object store, the same store that holds large payloads. The bucket is the one configured for `BUFFERED_TASKS_OBJECT_STORE_PROTOCOL` (or `OBJECT_STORE_DEFAULT_PROTOCOL` when it's unset), falling back to `OBJECT_STORE_BUCKET`, then `packets`.

The store must support conditional writes: `If-None-Match: *` and `If-Match` on `PutObject`.

| Store | Conditional writes |
| - | - |
| Amazon S3, general purpose and S3 Express One Zone directory buckets | Yes |
| MinIO 2025 releases, including the `bitnamilegacy/minio:latest` image in the Docker Compose setup | Yes |
| MinIO 2023 releases (tested: 2023.3.20) | No, they answer a conditional write with `404` |

For any other S3-compatible store, run this check with the AWS CLI (2.27 has the `--if-none-match` option used here), using the webapp's credentials:

```bash theme={"theme":"css-variables"}
ENDPOINT=http://localhost:9000   # your OBJECT_STORE_BASE_URL
BUCKET=packets
KEY=buffer/probe/manual-check

# 1. Creates the object
aws s3api put-object --endpoint-url $ENDPOINT --bucket $BUCKET --key $KEY --if-none-match '*'
# 2. Must fail with PreconditionFailed (412)
aws s3api put-object --endpoint-url $ENDPOINT --bucket $BUCKET --key $KEY --if-none-match '*'
# Clean up
aws s3api delete-object --endpoint-url $ENDPOINT --bucket $BUCKET --key $KEY
```

On a store with conditional writes, step 1 succeeds and step 2 fails with `An error occurred (PreconditionFailed) when calling the PutObject operation`. If step 2 succeeds, or step 1 fails with anything but an access error (MinIO 2023 answers `NoSuchKey`), the store doesn't support them.

The webapp runs a fuller version of this check at startup. When the store refuses conditional writes, buffered triggers answer `501`, the webapp logs `Buffered tasks are disabled: the object store lacks conditional writes`, and it checks again every minute, so upgrading the store needs no restart. When the store can't be reached, buffered triggers answer `503` and it checks again after 10 seconds. Everything else keeps working either way.

### Bucket permissions

The webapp's credentials need these on the `buffer/` prefix:

* `s3:PutObject`, `s3:GetObject` and `s3:DeleteObject` on `<bucket>/buffer/*`
* `s3:ListBucket` on `<bucket>`, for keys starting with `buffer/`

A missing permission shows up as `503` on buffered triggers and `Buffer object store check failed; retrying later` in the log, not as a `501`.

## What the object store holds

Each item is in the object store from the moment its trigger gets a `202` until its window's run exists. After that, the items are the run's payload, stored like any other payload.

* **Durability.** A `202` is sent only after the item is written. Accepted items are as durable as your object store.
* **Cleanup.** The webapp deletes objects under `buffer/` once it no longer needs them, about once a minute. Don't delete objects there yourself or add an expiry rule to the prefix: open windows and the shard layout live there.
* **Size.** The prefix holds items that haven't run yet plus small bookkeeping objects. With windows running on time it stays small: a 30 minute test at 400 items a second kept object counts flat and every snapshot under 1MB.
* **Requests.** Each process that stores items writes one object per batch, about 20 writes a second whatever the item rate (`BUFFERED_TASKS_INGEST_INTERVAL_MS`, default 50ms). Raise the interval to make fewer requests, at the cost of that much latency on every buffered trigger.

Redis never holds items. Buffered tasks use it only for the ingest rate limit and caches.

## Add consumer processes

One webapp process does everything by default (`BUFFERED_TASKS_ROLE=all`) with 1 shard. To spread the work of closing windows, run more processes from the same image with `BUFFERED_TASKS_ROLE=consumer`, and set the same `BUFFERED_TASKS_SHARD_COUNT` on the webapp and every consumer. Consumers share the shards and rebalance when one joins or leaves.

A consumer needs the webapp's environment (database, Redis, object store, `ENCRYPTION_KEY`). It serves only `/healthcheck`, doesn't run the run engine's workers or replication, and needs no published port.

With Docker Compose, add a service to `hosting/docker/webapp/docker-compose.yml` that extends the webapp, and set the shard count on both:

```yaml hosting/docker/webapp/docker-compose.yml theme={"theme":"css-variables"}
services:
  webapp:
    # ...existing settings
    environment:
      # ...existing variables
      BUFFERED_TASKS_SHARD_COUNT: 16

  buffer-consumer:
    extends:
      service: webapp
    ports: !reset []
    environment:
      BUFFERED_TASKS_ROLE: consumer
      TRIGGER_BOOTSTRAP_ENABLED: 0 # only the webapp sets up the worker group
    deploy:
      replicas: 2
```

`!reset` needs Docker Compose 2.24 or later.

The Helm chart has no values for consumer processes. Set `BUFFERED_TASKS_SHARD_COUNT` in `webapp.extraEnvVars`, and run consumers as your own Deployment with the webapp's image, environment and `BUFFERED_TASKS_ROLE=consumer`.

Shard count rules:

* 1 to 256 shards. The count can only grow: to a multiple of the current count, at most 4 times it per change, and at least 10 minutes after the last change. A refused change logs `Buffer consumer keeps the prefix's shard count` and keeps the old count.
* Use at least as many shards as you'll ever want consumers, since each shard has one owner at a time.

### Separate ingest processes

At higher rates you can also split accepting items from storing them: `api` processes take buffered triggers and forward them to `ingest` processes, which write them to the object store. Set `BUFFERED_TASKS_INGEST_ORIGIN` on `api` processes and the same `BUFFERED_TASKS_INGEST_SECRET` on both roles. You can run several `ingest` processes behind one address; each registers itself in the object store and consumers read from all of them.

Most self-hosted instances don't need this: one process stores a few thousand items a second.

## Sizing

Measured on our test hosts:

| Component | Capacity |
| - | - |
| One webapp on MinIO, `BUFFERED_TASKS_ROLE=all` | 200 items a second over 500 keys, trigger p50 49ms, windows starting p50 0.3s after their deadline |
| One `ingest` process | About 3,200 items a second with one item per request (1.4 CPU cores), about 21,000 with 10 items per request |
| One consumer | About 630 window runs a second; 0.11 CPU cores at 1,000 items a second when it holds no busy shard |

The cost of storing items is per request, not per item: send items in batches where you can. Window runs also count against your run engine's capacity like any other run.

## When something fails

| Failure | What happens |
| - | - |
| Object store down | Buffered triggers answer `503` with `retry-after: 2` and the SDK retries for up to 60 seconds. Items that already got a `202` aren't affected. |
| Redis down | Buffered triggers and windows keep working. The ingest rate limit lets every request through until Redis is back. |
| A process storing items crashes | Items that got a `202` are already in the object store. Requests in flight fail and the SDK retries them. |
| A consumer crashes | Its shards are taken over about 10 seconds later, when its leases run out, and their windows run then. A consumer that's stopped normally hands its shards over at once. |
| Postgres or the run engine down | Windows that close can't create their runs yet. The consumer keeps them and retries, and every item still runs once. |

Useful log lines to alert on: `Buffer ingest write failed, callers get a 503`, `Buffer shard lease lost`, `Buffer window trigger failed, will retry`, `Buffer consumer tick failed` and `Buffered tasks are disabled`. The webapp also exports OpenTelemetry metrics under `buffered_tasks.*`, such as `buffered_tasks.held.items`, `buffered_tasks.consumer.lag` and `buffered_tasks.window.overdue`.

## Turn it off or roll back

Set `BUFFERED_TASKS_ENABLED=0`, or turn off the `bufferedTasks` flag for one organization on the admin dashboard. New buffered triggers then answer `403` with `Buffered tasks aren't enabled for this organization yet.`

Items that were already accepted still run: consumers don't check the flag, so open windows close and run as usual. Keep the consumer processes running until they have.

If you go back to a webapp version without buffered tasks, the items it accepted stay in the object store and their windows don't run until a version with buffered tasks runs again.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.