Short answer: for scheduled data cleanup, use cron to run a recurring database scan until one batch can no longer finish comfortably inside its interval; add a message queue when you need bounded worker concurrency, independent retries, or isolation from slow downstream work. In either design, make the Postgres cleanup transition conditional and safe to repeat. The delivery mechanism can wake the work up, but the database must decide whether a held reservation is still eligible to expire.

For a customer-support system, the job is narrow: release reservations whose fixed hold window has ended. Don't begin with permanent deletion. Mark a row expired first, preserve enough information to audit the transition, and run physical retention as a separate policy. I've been paged for both missed jobs and duplicate deliveries, and the useful lesson is plain: a timer is not a completion guarantee, while a delivered message is not proof that the handler committed.

Start with the failure signal, not the scheduler

Define the invariant before choosing infrastructure: a reservation in held state may become expired after hold_expires_at, and repeating that attempt must not produce another business transition. That gives the operator something stronger than “cron ran at 02:00.” It gives a queryable outcome.

Track the age of the oldest overdue held reservation. Also track rows claimed, rows changed, batch duration, retry count, and the gap between hold_expires_at and expired_at. A run that reports success after changing zero rows can be healthy; a steadily growing overdue age cannot. Alert on the business lag, with the threshold tied to the support workflow's tolerance, rather than alerting merely because one trigger was late.

Duplicates deserve equal attention. A queue consumer may receive a message again after its visibility timeout, so the handler has to tolerate another delivery. Extending visibility can give long-running work more time, but it doesn't remove the need for an idempotent state change. If a handler calls a rate-limited downstream HTTP service, treat 429 Too Many Requests as backpressure and honor Retry-After when it is present; don't turn that response into a tight retry loop.

One detail changes the whole design: expiring the reservation and sending a customer notification are two separate effects. Commit the expiry in Postgres first. Represent any notification as durable follow-up work, preferably in the same transaction through an outbox record, so a process exit can't leave an untraceable gap between database commit and message publication.

Should scheduled data cleanup jobs use cron or a message queue?

Cron is the smaller operational system when a bounded query can find all overdue rows, each transition is quick, and a later run can catch anything missed by an earlier trigger. It is often the cheapest option in that situation because it reuses the database and scheduler already being operated. The catch is that a single scanning process becomes a poor fit when work duration is highly variable, downstream calls dominate runtime, or one batch needs more parallelism than the database should absorb at once.

A message queue earns its place when each reservation needs independently paced work, consumers need explicit concurrency limits, or retries must be isolated per item. It also adds moving parts: publication has to be durable, consumers need visibility-timeout discipline, poison work needs a terminal policy, and operators must watch both queue age and database lag. A queue is therefore not automatically the safer or cheaper choice. It shifts the failure boundary.

For this reservation case, the practical default is a hybrid only when scale requires it: a periodic scanner discovers eligible IDs and records outbox work, then queue workers perform bounded follow-up. The database transition remains conditional. Stick with the direct scanner when expiry is only a local row update and batches stay well within the operating window; choose queued workers when measured lag or downstream latency proves that isolation is needed.

I'm not sure where that boundary sits for your workload. Query plans, row counts, hold-window clustering, and downstream latency will resolve it; a vendor price table won't.

Make the reservation transition safe to repeat

The following Go program runs a bounded scan. It uses row locks with SKIP LOCKED, so overlapping workers can take different eligible rows, and the WHERE status = 'held' predicate makes a repeated attempt a no-op after the first commit. Set DATABASE_URL in the process environment and run it from the scheduler you already trust.

package main import ( "context" "fmt" "log" "os" "time" "github.com/jackc/pgx/v5/pgxpool" ) const expireBatchSQL = ` WITH eligible AS ( SELECT id FROM reservations WHERE status = 'held' AND hold_expires_at <= $1 ORDER BY hold_expires_at, id FOR UPDATE SKIP LOCKED LIMIT $2 ) UPDATE reservations AS r SET status = 'expired', expired_at = $1 FROM eligible WHERE r.id = eligible.id AND r.status = 'held' RETURNING r.id` func expireBatch(ctx context.Context, db *pgxpool.Pool, now time.Time, limit int) (int, error) { rows, err := db.Query(ctx, expireBatchSQL, now, limit) if err != nil { return 0, err } defer rows.Close() changed := 0 for rows.Next() { var reservationID string if err := rows.Scan(&reservationID); err != nil { return changed, err } changed++ } return changed, rows.Err() } func main() { ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second) defer cancel() db, err := pgxpool.New(ctx, os.Getenv("DATABASE_URL")) if err != nil { log.Fatal(err) } defer db.Close() started := time.Now() changed, err := expireBatch(ctx, db, time.Now().UTC(), 500) if err != nil { log.Fatal(err) } fmt.Printf("reservation_expiry changed=%d duration=%s\n", changed, time.Since(started)) } 

Keep the transaction short. The code does no network I/O while locks are held, and its batch limit is a guardrail rather than a throughput promise. If more than 500 rows are overdue, the next invocation can claim another batch. If the cleanup interval is too slow to drain the backlog, first confirm the query plan and index for the eligibility predicate, then increase invocation frequency or worker count carefully while watching database lock time and lag. For queued follow-up, use the same reflex in the consumer: pass a stable reservation ID, attempt a conditional transition, acknowledge only after the database commit, and treat “zero rows changed” as an already-completed delivery rather than an error. Make the outbox identifier unique so retrying the scanner does not publish an unbounded number of logical copies. Consider the ugly timing window: worker A commits the expiry, loses its lease before acknowledgement, and worker B receives the same reservation. Worker B's conditional update changes zero rows, checks that the current state is already expired, and acknowledges. No second notification is implied merely by that duplicate delivery, because notification work has its own unique outbox key. If worker A instead loses its lease before commit, its transaction ends without a committed transition and worker B can perform the update. This distinction belongs in the runbook because an operator staring at two delivery log lines needs to know whether they represent two attempts or two customer-visible effects. Exactly-once language hides that question; an observable, repeatable state transition answers it.

Attempts are not effects.

Verify deployment and keep rollback boring

Before enabling writes, run the eligibility query in read-only mode against production-shaped data. Inspect its plan, estimate the largest expiry wave, and verify that rows with a future hold_expires_at, a non-held status, or an already populated expired_at remain untouched. Then enable a small batch and compare three counts: eligible before, changed during the run, and eligible after. Re-run the same IDs. The second transition count should be zero.

Deploy with a kill switch that prevents new claims without terminating in-flight database commits. During rollout, watch oldest-overdue age and batch duration together. Falling lag with stable database latency is the desired signal. Rising lag means capacity is inadequate; rising database latency means the cleanup is competing too aggressively. Pause, reduce the batch or concurrency, and reassess the plan.

Rollback is operational, not magical. Disable new claims first. Let current transactions finish, then verify the invariant and preserve the transition log. Automatically changing expired rows back to held can reopen reservations that support agents have already replaced, so restoration should be a reviewed business action based on recorded IDs and timestamps. This is why soft expiry belongs ahead of irreversible deletion.

Test the awkward boundaries too: two workers selecting at once, a retry after commit but before acknowledgement, a reservation updated by an agent at the cutoff, and a clock value exactly equal to hold_expires_at. Use a database-controlled or explicitly passed UTC timestamp consistently. Short test. Big payoff.

Use a decision rule the on-call can explain

Choose the direct scheduled scan when the work is a local conditional update, overdue rows are efficiently discoverable, missed triggers are recovered by the next scan, and the measured batch duration has comfortable headroom. It minimizes coordination and keeps diagnosis in one place.

Choose scanner-plus-queue when per-item work varies widely, downstream rate limits require pacing, independent retries matter, or database lag cannot be controlled with short batches. It is not suitable as a substitute for idempotency, nor does it repair an unsafe publish-after-commit gap by itself. Use a transactional outbox or another atomic handoff pattern for that boundary.

The cheapest architecture is the one that meets the delivery objective with the fewest failure modes your team must operate. For stale customer-support reservations, start with the conditional Postgres scan, measure business lag, and introduce queued delivery only in response to evidence. Keep the invariant unchanged across both designs. That makes migration dull — which is exactly what an expiry runbook should aim for.

References

Further reading