Prompt
I'm building scheduled notifications and need delayed job processing
Latest observation
Nov 2, 2026
OpenAI APIWeb search: off
To build scheduled notifications with delayed job processing, you generally want a system where you:
- Store the notification intent
- Schedule it for a future time
- Have a worker process jobs when they become due
- Retry/fail safely if delivery doesn’t work
Here’s a solid pattern.
1) Core architecture
Components
- API/backend: receives request to schedule notification
- Database: stores notification/job records
- Queue / delayed job system: holds jobs until they’re due
- Worker(s): poll or consume jobs and send notifications
- Notification provider: email, push, SMS, in-app, etc.
2) Data model
You can store scheduled notifications like:
notifications
- id
- user_id
- channel
- title
- message
- scheduled_at
- status -- pending, processing, sent, failed, canceled
- attempts
- last_error
- created_at
- updated_at
Useful fields:
scheduled_at: when to runstatus: lifecycle stateattempts: retry trackinglast_error: debuggingidempotency_key: avoid duplicates
3) Scheduling approaches
Option A: Use a real delayed queue
Best if your stack supports it.
Examples:
- BullMQ / Redis
- Sidekiq
- Celery
- RabbitMQ delayed exchange
- SQS + delay seconds (limited to 15 minutes per message)
- Cloud Tasks / Cloud Scheduler
Pros
- Simple worker flow
- Good retry support
- Less custom scheduling logic
Cons
- Some systems have delay limits
- Long-term scheduling may need a DB-backed approach
Option B: DB-backed scheduler + worker
Best for long delays or high control.
Flow:
- Insert job into DB with
scheduled_at - Worker runs every N seconds:
- fetch due jobs where
scheduled_at <= now()andstatus = pending - lock them
- mark
processing - send notification
- mark
sentorfailed
- fetch due jobs where
Pros
- Works for any delay length
- Very reliable
- Easy to inspect jobs
Cons
- You must implement locking, retries, and deduplication carefully
4) Safe processing pattern
When a worker picks a job, use an atomic update so two workers don’t process the same job.
Example logic:
- Select a batch of due jobs with row locking
- Update status from
pendingtoprocessing - Process outside the transaction
- On success: set
sent - On failure: increment attempts, set back to
pendingorfailed
If using Postgres, FOR UPDATE SKIP LOCKED is very useful.
5) Retry strategy
Typical retry policy:
- Retry 3–5 times
- Exponential backoff
- Mark as
failedafter max attempts
Example:
- attempt 1 immediately
- attempt 2 after 1 min
- attempt 3 after 5 min
- attempt 4 after 15 min
Track:
next_run_atattemptsmax_attempts
6) Idempotency
Very important for notifications.
You want to avoid sending the same notification twice if:
- worker crashes after sending but before marking sent
- job is retried
- scheduler duplicates a task
Use:
idempotency_key- unique constraint on
(user_id, channel, scheduled_at, idempotency_key)or similar - provider-side dedupe if available
7) Example delayed job flow
When user schedules notification
POST /notifications
{
"user_id": 123,
"message": "Reminder tomorrow",
"scheduled_at": "2026-11-03T09:00:00Z"
}
Backend:
- validate scheduled time
- save record in DB as
pending - either:
- enqueue delayed job, or
- rely on worker polling
Worker loop
every 30 seconds:
jobs = find_due_jobs(limit=100)
for job in jobs:
lock job
mark processing
try:
send_notification(job)
mark sent
except:
increment attempts
if attempts < max_attempts:
reschedule with backoff
else:
mark failed
8) If you’re using Redis/BullMQ
A common Node.js approach:
- Add jobs with
delay: scheduledAt - now - Use workers to process
- Let BullMQ handle retries and backoff
Example idea:
await queue.add("sendNotification", data, {
delay: scheduledAt - Date.now(),
attempts: 5,
backoff: {
type: "exponential",
delay: 60000
}
});
Good for:
- medium-scale systems
- straightforward delayed processing
9) If you need high reliability
Consider:
- DB as source of truth
- queue as execution layer
- periodic reconciliation job:
- find
pendingnotifications past due - re-enqueue anything missed
- find
This protects against queue outages.
10) Recommended design
If you want a robust production setup:
- DB table for notifications
- Queue for execution
- Worker service for delivery
- Retry/backoff
- Idempotency keys
- Periodic cleanup/reconciliation
If you want, I can give you:
- a Node.js/TypeScript example with BullMQ,
- a Python example with Celery,
- or a database polling implementation with SQL/Postgres.