# Queues

> Send work to a queue from your app and process it in the background, with retries and a dead-letter queue.

Applies to: the Sypnia engine (open source, self-hosted) and Sypnia Cloud (paid service).  
Source: https://run.docs.sypnia.com/jobs/queues/

For agents: Run queues: [run.apps.<name>.queues.<queue>] tables in sypnia.toml (consumer file, batch, retries = attempts in all, default 5, 1–20, concurrency); send with @sypnia/run/queue queue(name).send(body, {delaySeconds, dedupeId}); consumer() handler; one SQS queue per app environment plus DLQ; failed batches retried with backoff then moved to DLQ (run queues dlq <q> [--replay]); at-least-once; dedupeId 5-minute window; delay ≤15 min; scaling up to concurrency; 256 KB message limit (use Files for bigger).

A queue holds messages until a consumer processes them. Use it for anything that should not make a visitor wait: sending e-mails, resizing images, printing kitchen tickets, importing a file.

`sypnia.toml`

```toml
[run.apps.laespiga.queues.kitchen]
consumer = "workers/kitchen.ts"
batch = 10
retries = 5          # attempts in all, 1 to 20 (5 when left out)
concurrency = 4
```

```ts
// in your app
import { queue } from '@sypnia/run/queue';
await queue('kitchen').send({ order: 1042 }, { delaySeconds: 0, dedupeId: 'order-1042' });

// workers/kitchen.ts
import { consumer } from '@sypnia/run/queue';
export default consumer<{ order: number }>(async (messages) => {
  for (const m of messages) await printTicket(m.body.order);
});
```

## How it behaves

- Each queue is an Amazon SQS queue of the app's environment, with a **dead-letter queue** next to it.
- A batch that throws is tried again with growing waits: **5 attempts** in all by default, or what `retries` says (1 to 20). After the last attempt its messages move to the dead-letter queue, where `run queues dlq kitchen` lists them and `--replay` sends them back.
- Delivery is **at least once**: process messages so that receiving one twice does no harm (`dedupeId` drops duplicates sent within five minutes).
- `delaySeconds` holds a message up to 15 minutes before it can be received.
- Consumers scale with the queue's length up to `concurrency`.

## Limits from AWS

A message body is up to 256 KB; put bigger payloads in [Sypnia Files](https://files.sypnia.com) and send the path.
