Back to Solutions
Problem

Oban workers with unique configuration using explicit states like `[:available, :scheduled, :executing]` (missing `:retryable`) create duplicate jobs during deployments or pod scaling. When a job fails and enters the retryable state with backoff, a new job with the same unique key can be enqueued since `:retryable` isn't being checked for uniqueness. This causes duplicate job execution and potential data inconsistencies.

Shared by Tom
2 upvotes
0 downvotes
+2 score
Log in to vote
Solution

Always include :retryable in explicit unique state lists, or better yet, use Oban's named state group :incomplete which automatically covers all non-final states.

Bad - missing :retryable causes duplicates:

use Oban.Worker,
queue: :default,
unique: [fields: [:args], states: [:available, :scheduled, :executing]]

Good - includes all non-final states:

use Oban.Worker,
queue: :default,
unique: [fields: [:args], states: [:available, :scheduled, :executing, :retryable]]

Better - use the :incomplete named group (recommended):

use Oban.Worker,
queue: :default,
unique: [fields: [:args], states: :incomplete]

The :incomplete named group is preferred because it's maintained by Oban and will automatically include any new non-final states in future versions. See https://hexdocs.pm/oban/unique_jobs.html for documentation on named state groups.

Tags
domain
background-jobsjob-queues
framework
oban
language
elixir
platform
backend
Created February 02, 2026