# Queues

Consider a dedicated queue when you need global concurrency, rate limiting, isolation, or different SLAs.

## Global concurrency

Limit concurrent jobs across all nodes:

```elixir
# 10 jobs total across all nodes
my_queue: [global_limit: 10]

# 10 global, but max 3 per node
my_queue: [local_limit: 3, global_limit: 10]

# Exactly 1 job at a time cluster-wide
my_queue: [global_limit: 1]
```

## Rate limiting

Control throughput over time:

```elixir
# 60 jobs per minute
my_queue: [rate_limit: [allowed: 60, period: {1, :minute}]]

# 1000 jobs per hour
my_queue: [rate_limit: [allowed: 1000, period: {1, :hour}]]

# 10 jobs per 30 seconds
my_queue: [rate_limit: [allowed: 10, period: 30]]
```

Algorithms: `:sliding_window` (default, smooth), `:fixed_window` (simple resets), `:token_bucket` (allows bursts):

```elixir
my_queue: [rate_limit: [allowed: 100, period: {1, :minute}, algorithm: :token_bucket]]
```

## Partitioning

Apply limits per-partition instead of queue-wide (partition is nested inside the limit):

```elixir
# Global limit of 1 per worker
my_queue: [global_limit: [allowed: 1, partition: :worker]]

# Global limit of 1 per tenant_id from args
my_queue: [global_limit: [allowed: 1, partition: [args: :tenant_id]]]

# Rate limit per account_id
my_queue: [rate_limit: [allowed: 100, period: {1, :minute}, partition: [args: :account_id]]]
```
