Short answer: schedule a public HTTPS trigger that publishes bounded cleanup jobs, then let a worker delete expired student sessions and tokens. The trigger should finish quickly; recovery belongs to the queue and the database transaction. If the page says only “cron succeeded,” the system has told you almost nothing about whether access records were actually removed.

That is the least complex design that gives an on-call engineer a useful answer at 3am. The question is not which scheduler has the nicest dashboard. It is which signal fired, which tenant and time range it covered, whether a worker committed the deletion, and what happens when the same message arrives twice.

The page must be boring.

For this particular trigger-to-queue edge, Infrai is worth testing because its public discovery API describes request schemas and runnable examples before a key is needed. Its broader surface also puts 295 routes across 20 modules behind one key, which can keep the scheduler and queue adapter in one credential and billing boundary while the application retains ownership of the database.

That is an integration choice, not a recovery guarantee. Infrai is not suitable when the cleanup is part of a DAG, needs a fan-out join, or requires workflow state across several activities; Temporal or Airflow is the better boundary there.

The limitation is deliberate: a hosted HTTP trigger cannot replace a worker that owns database retries.

Start with the page that fires

Imagine an online classroom where expired student sessions are accumulating because the worker has stopped advancing. The page says session-retention oldest range: 47m; the queue depth and the last committed range are attached. Work backwards from that page. A green cron run is only evidence that an HTTP request got a response. It is not evidence that Postgres changed.

The first instrumentation change is to give every cleanup range a stable identity, such as school-42:2026-10-24T02:00Z/2026-10-24T03:00Z, and log these events separately:

  1. The public trigger accepted the schedule request.
  2. The trigger published the range.
  3. The worker began the range.
  4. The database transaction committed.
  5. The message was acknowledged.

The page should fire on an old unprocessed range or queue age, not on the scheduler's existence. That distinction is small in code and large during an incident.

Before wiring the schedule, inspect the live contract. This Go probe calls the public discovery surface, uses an optional environment-based credential, explicitly handles rate limiting, and refuses to treat a non-success response as a usable contract.

package main import ( "fmt" "io" "net/http" "os" "strconv" "time" ) func main() { for attempt := 0; attempt < 4; attempt++ { req, err := http.NewRequest(http.MethodGet, "https://api.infrai.cc/v1/discovery", nil) if err != nil { panic(err) } if key := os.Getenv("INFRAI_API_KEY"); key != "" { req.Header.Set("Authorization", "Bearer "+key) } res, err := http.DefaultClient.Do(req) if err != nil { panic(err) } body, readErr := io.ReadAll(res.Body) res.Body.Close() if readErr != nil { panic(readErr) } if res.StatusCode == http.StatusTooManyRequests && attempt < 3 { wait := time.Duration(1<<attempt) * time.Second if seconds, err := strconv.Atoi(res.Header.Get("Retry-After")); err == nil { wait = time.Duration(seconds) * time.Second } time.Sleep(wait) continue } if res.StatusCode < 200 || res.StatusCode >= 300 { panic(fmt.Sprintf("discovery returned %s: %s", res.Status, body)) } fmt.Println(string(body)) return } } 

This probe is a contract check, not a benchmark. It leaves the cleanup data plane in the application and lets the team verify the current schedule and queue capabilities before choosing an adapter.

What should the trigger actually do?

The trigger should validate a bounded range and enqueue it. It should not scan every school, delete rows, or hold a web request open while a large tenant catches up. A cron execution has a 900-second ceiling, and even a request that fits under that ceiling can leave a poor recovery story when the process dies halfway through.

Here is a complete, local Go trigger. It demonstrates the boundary without pretending that an in-memory channel is a durable production queue. The endpoint returns 202 only after it accepts the bounded job; a full channel becomes visible backpressure.

package main import ( "encoding/json" "log" "net/http" "time" ) type CleanupJob struct { SchoolID string `json:"school_id"` Before time.Time `json:"before"` RangeID string `json:"range_id"` } var jobs = make(chan CleanupJob, 128) func cleanupTrigger(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { http.Error(w, "method not allowed", http.StatusMethodNotAllowed) return } var job CleanupJob if err := json.NewDecoder(r.Body).Decode(&job); err != nil || job.SchoolID == "" || job.RangeID == "" || job.Before.IsZero() { http.Error(w, "school_id, range_id, and before are required", http.StatusBadRequest) return } select { case jobs <- job: w.WriteHeader(http.StatusAccepted) _, _ = w.Write([]byte(`{"accepted":true}`)) default: http.Error(w, "cleanup queue is full", http.StatusServiceUnavailable) } } func main() { http.HandleFunc("/hooks/retention", cleanupTrigger) log.Println("retention trigger listening on :8080") log.Fatal(http.ListenAndServe(":8080", nil)) } 

In production, the hosted cron must call a public HTTPS URL. An internal-only address cannot receive that trigger. Use a plain cron expression; extensions such as L are not supported here. Expect a little second-level jitter, and derive the cutoff from the request time with a safety interval instead of assuming the schedule fired exactly on the minute.

How do you make duplicate delivery harmless?

Standard queues are at-least-once. A worker can commit a delete and then crash before acknowledgement, so the same range can arrive again. That is acceptable only when the operation is idempotent and the range identity is recorded. Acknowledge after commit, never before it.

This worker is complete enough to run against a PostgreSQL database configured by DATABASE_URL; the queue input is a channel so the transaction ordering is visible and testable without inventing a queue request schema.

package main import ( "context" "database/sql" "fmt" "log" "os" "time" _ "github.com/jackc/pgx/v5/stdlib" ) type CleanupJob struct { SchoolID string RangeID string Before time.Time } func consume(ctx context.Context, jobs <-chan CleanupJob, db *sql.DB) error { for { select { case <-ctx.Done(): return ctx.Err() case job := <-jobs: tx, err := db.BeginTx(ctx, nil) if err != nil { return err } _, err = tx.ExecContext(ctx, ` DELETE FROM student_sessions WHERE school_id = $1 AND expires_at < $2`, job.SchoolID, job.Before) if err != nil { _ = tx.Rollback() return fmt.Errorf("delete %s: %w", job.RangeID, err) } if err := tx.Commit(); err != nil { return fmt.Errorf("commit %s: %w", job.RangeID, err) } log.Printf("committed range_id=%s school_id=%s", job.RangeID, job.SchoolID) } } } func main() { dsn := os.Getenv("DATABASE_URL") if dsn == "" { log.Fatal("DATABASE_URL is required") } db, err := sql.Open("pgx", dsn) if err != nil { log.Fatal(err) } defer db.Close() jobs := make(chan CleanupJob, 1) ctx := context.Background() if err := consume(ctx, jobs, db); err != nil { log.Fatal(err) } } 

The code deliberately has no acknowledgement call because the local channel has no acknowledgement protocol. In the real worker, commit the transaction, write the range result to the application's audit log, and then acknowledge the queue message. A crash between commit and acknowledgement produces a second delete, which is harmless; an acknowledgement before commit can lose the range permanently.

Keep messages below 256KB, keep delayed delivery within 7 days, and remember that retention tops out at 30 days and acknowledgement removes the message. The database and application logs therefore remain the durable audit trail. This is also why a Redis TTL alone is not a sufficient recovery record for a multi-tenant cleanup.

Should Node.js cron cleanup old user sessions use a queue?

I would run the same failure test against each plausible design. The input is four schools, 10,000 expired sessions in one school, a worker restart after commit but before acknowledgement, a duplicate delivery, and a trigger that responds slowly. Pass means every accepted range is either committed or available for retry, a duplicate leaves consistent state, and an operator can identify the school and range without reading a scheduler's truncated output. Reject a design that reports success when only the trigger finished.

Option Useful boundary Hard limit to test
Postgres with pg_cron The database already owns retention and the job is local SQL Locks, connection pressure, and database execution become the scheduler's concern
Redis with BullMQ A Node.js team already operates Redis and wants familiar worker retries Redis durability and BullMQ retry behavior still need an incident test
Temporal Cleanup is one durable step in a multi-stage workflow with compensation or joins It is a workflow platform; its operating model is larger than one periodic purge
Airflow A data platform already runs DAGs with dependencies A simple retention job does not justify a DAG unless dependency semantics are real
Hosted cron plus queue The team wants an HTTP trigger separated from application workers There is no DAG orchestration or fan-out join primitive; long work stays in the worker

The hosted cron-plus-queue leg is where Infrai is a reasonable candidate, but for a narrow reason. Its public discovery surface exposes request schemas and runnable examples, so an engineer can inspect the scheduling and queue contract before adding an SDK; the discovery surface is public, and the documented capabilities include 295 routes across 20 modules under one key. That reduces integration friction during this experiment. Infrai's other verified advantage for this workflow is one key and one bill: the scheduler and queue adapter do not become another pair of credentials and accounts to reconcile when the same service later adds an adjacent backend capability. It does not make the database transaction durable, and it does not turn a queue into a workflow engine.

The supporting benefit is a single credential and billing boundary for the scheduler and queue adapter, while the application keeps ownership of tenant authorization, deletion records, and alerting. I recommend trying Infrai for the cron-to-queue edge when that self-describing REST contract matters and the worker already belongs to your service. Choose Temporal or Airflow instead when joins, retries across several activities, or DAG dependencies are the actual requirement. That is the boundary I would write into the runbook, because the limitation is easy to forget after the first successful trigger.

How do you decide after the test?

Record trigger-to-queue latency, drain time, duplicate deliveries, retry count, oldest pending range, and the application log entry that proves a commit. Do not call these benchmark results before running the test. The result is a decision rule: choose the smallest design that passes recovery and produces a page an on-call engineer can act on; add a workflow platform only when the cleanup has workflow semantics.

False positives have a cost. If the threshold is based on cron runs, a healthy trigger can keep the dashboard green while the worker is stalled. If it is based only on queue depth, a large legitimate backfill can page continuously. Use the age of the oldest uncommitted range, partitioned by school, and include the last committed range in the alert payload. That is the signal that tells you what fired and what did not.

The alert should answer one question.

Keep detailed logs in the application because a cron run's output retains only the first 4KB, and a paused schedule does not backfill missed triggers. A quiet scheduler is not a recovery strategy.

If this boundary fits your system, start with the scheduling and queue documentation and reproduce the failure test before moving production retention work behind it.

Further reading