Nov 17, 20264 min read

Amazon SQS Delay Queues: DelaySeconds, per-Message Delay and When to Use Them

Postpone SQS message delivery by up to 15 minutes with a queue delay or a per-message timer, including the FIFO limitation, and what to do when you need a longer wait.

Illustration for Amazon SQS Delay Queues: DelaySeconds, per-Message Delay and When to Use Them

Amazon SQS delay queues postpone delivery of new messages so a consumer does not see them until a delay of up to 15 minutes has elapsed. That covers "wait a bit, then retry the webhook" or "give the writer a moment to commit before the reader starts."

It does not cover "send this reminder tomorrow." The maximum DelaySeconds value is 900 seconds, and FIFO queues cannot set a per-message delay at all.

This guide sets up a delay queue and a per-message timer, then shows an Encore pattern that stores a due time and lets a cron job pick up work when the wait is longer than SQS can express, or when you want the schedule declared in application code.

Delay options at a glance

Queue DelaySecondsPer-message DelaySecondsLonger than 15 minutes
Maximum900 seconds900 seconds, standard queues onlyEventBridge Scheduler, or a due-time table plus cron
FIFOAllowed on the queue, and changes apply to messages already in the queueNot allowedSame alternatives
Standard queue changeNot retroactiveOverrides the queue default for that messageNot applicable
Use whenEvery new message should wait the same timeA few messages need a different waitThe wait is hours or days

Set a queue delay

When you create or update a standard or FIFO queue, set DelaySeconds between 0 and 900. New messages (and, on FIFO queues, messages already in the queue if you change the setting) stay invisible to ReceiveMessage until the delay ends. The delay queues documentation also notes that this is not a visibility timeout: visibility timeout starts after the consumer receives the message.

~
$ aws sqs create-queue --queue-name webhook-retry \ --attributes DelaySeconds=60,VisibilityTimeout=30,MessageRetentionPeriod=345600$ aws sqs send-message --queue-url "$QUEUE_URL" \ --message-body '{"delivery_id":"d_123"}' \ --delay-seconds 120

The send-message call's --delay-seconds 120 overrides the queue default of 60 seconds for that message, on a standard queue only. On a FIFO queue the same flag is rejected; set the delay on the queue, and include a MessageGroupId.

Best fit: retries and short buffers that always complete within 15 minutes.

When 15 minutes is not enough

EventBridge Scheduler can start a one-time or recurring action without that 15-minute cap, and AWS recommends it for more flexible scheduling. Another pattern is to write a run_after timestamp in Postgres and have a job select due rows. The Encore example below uses that pattern: Encore Pub/Sub has no DelaySeconds parameter.

How do you delay work with Encore?

Encore

Encore brings infrastructure from code: you declare a database and a cron job in Go, and a deploy provisions Postgres and platform managed cron in your own AWS or GCP account. Encore does not expose SQS DelaySeconds. Store the due time on a row, and let a job claim due work. Encore cron jobs do not run locally or in preview environments; call the private endpoint to test.

A coding agent can add the table, the enqueue handler and the cron endpoint in the same change, then call the endpoint from the local development dashboard.

var _ = cron.NewJob("send-due-webhooks", cron.JobConfig{ Title: "Send webhooks whose delay has elapsed", Every: 1 * cron.Minute, Endpoint: SendDueWebhooks, }) //encore:api private func SendDueWebhooks(ctx context.Context) error { rows, err := db.Query(ctx, ` UPDATE webhook_outbox SET claimed_at = now() WHERE id IN ( SELECT id FROM webhook_outbox WHERE run_after <= now() AND sent_at IS NULL AND (claimed_at IS NULL OR claimed_at < now() - interval '5 minutes') ORDER BY run_after LIMIT 100 FOR UPDATE SKIP LOCKED ) RETURNING id, url, payload`) if err != nil { return err } defer rows.Close() for rows.Next() { var id, url, payload string if err := rows.Scan(&id, &url, &payload); err != nil { return err } if err := sendWebhook(ctx, url, payload); err != nil { _, _ = db.Exec(ctx, ` UPDATE webhook_outbox SET claimed_at = NULL WHERE id = $1 AND sent_at IS NULL`, id) continue } if _, err := db.Exec(ctx, ` UPDATE webhook_outbox SET sent_at = now() WHERE id = $1`, id); err != nil { return err } } return rows.Err() } func sendWebhook(ctx context.Context, url, payload string) error { // POST the payload to url. Return a network or non-2xx error so the claim can be retried. return nil }

1 * cron.Minute divides 24 hours evenly, which the cron schedule rules require. Encore provisions an IAM role for the service, or a service account on GCP.

Best fit: waits that may exceed 15 minutes, or work you want declared next to the API in Go rather than as a queue setting.

How to choose

Pick a queue or per-message DelaySeconds when the wait is at most 15 minutes and the consumer already reads SQS. Pick EventBridge Scheduler when you need a one-off or recurring action further in the future. Pick Encore when the due time belongs in your database and a platform managed cron job should claim the work in your own AWS or GCP account.

Frequently asked questions

What is an SQS delay queue?

A delay queue postpones delivery of new messages so consumers cannot receive them until the delay has elapsed. The queue-level DelaySeconds value can be 0 to 900 seconds, which is 15 minutes. For standard queues, changing the queue delay does not affect messages already in the queue.

Can I delay a single SQS message instead of the whole queue?

Yes, on a standard queue. SendMessage accepts DelaySeconds from 0 to 900, and that value overrides the queue default for that message. FIFO queues do not allow a per-message delay; you can set DelaySeconds only on the queue.

What if I need to wait more than 15 minutes?

SQS delay queues and message timers cannot schedule work further ahead than 15 minutes. Amazon recommends EventBridge Scheduler for longer or more flexible schedules. In application code, store the due time in the database and have a cron job publish or process rows that are due.

Does Encore support SQS DelaySeconds?

Encore Pub/Sub does not expose a delay-queue setting, so for a short wait you can record the due time on a row and let a platform managed cron job publish or process due work. Encore cron jobs do not run locally or in preview environments, so call the private endpoint to test.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders