# Queues

Cloudflare Queues provide reliable, at-least-once message delivery for background processing. Quickback uses queues for embedding generation, webhook delivery, and custom background jobs.

## Built-in Queues

The compiler auto-configures queues when certain features are enabled:

| Feature | Queue Binding | Purpose |
|---------|--------------|---------|
| Embeddings | `EMBEDDINGS_QUEUE` | Async embedding generation via Workers AI |
| Webhooks | `WEBHOOKS_QUEUE` | Async webhook delivery with retry |
| Custom | User-defined | Your own background processing |

## Queue Defaults

| Setting | Default |
|---------|---------|
| Max batch size | 10 messages |
| Max batch timeout | 30 seconds |
| Max retries | 3 |

## Custom Queues

Define custom queue handlers for background processing like data pipelines, batch jobs, and async workflows. Custom handlers integrate into the same queue consumer as built-in queues.

```typescript
database: defineDatabase("cloudflare-d1", {
  binding: "DB",
  additionalQueues: [
    {
      name: "my-app-processing-queue",
      binding: "PROCESSING_QUEUE",
      maxBatchSize: 5,
      maxBatchTimeout: 60,
      maxRetries: 5,
    },
  ],
})
```

## How It Works

All queues share a single Cloudflare Workers queue consumer. The consumer inspects each message's `type` field to dispatch to the correct handler:

```
Message arrives → Check type field
                  ├─ "embedding"         → Embedding handler
                  ├─ "inbound"/"outbound" → Webhook handler
                  └─ "process_material"   → Custom handler
```

## Pages

- **[Custom Queue Handlers](/stack/queues/handlers)** — `defineQueue()`, handler context, and generated output
- **[Using Queues](/stack/queues/using-queues)** — Publishing messages, wrangler config, and deployment
