Short answer: for weekly gaming-customer reminders, use a small cron sweep to claim due rows, a durable queue for delayed messages, and an idempotency key that survives every retry. Email and SMS are delivery attempts, not proof of delivery; a public webhook should acknowledge quickly and let a worker do the slow work.
I run a one-person SaaS, so my useful unit is revenue per hour. The system has to ship weekly and outsource the undifferentiated work to boring primitives. The tricky part is not calculating “next Friday.” It is making a retry safe when a process dies between sending an SMS and marking the row complete.
Retry failures in Node.js queues are business events
Start with a durable reminder record. Store the customer, the intended instant in UTC, the IANA time zone used to calculate it, the channel, and a stable event key such as digest:customer_42:2026-W34. Keep the local display time for support, but compare due work in UTC. A time-zone offset is not a time zone; daylight-saving changes make that shortcut fail.
The scheduler only claims work. It should not call an email or SMS provider while holding a database lock. A short lease (locked_until) prevents two workers from taking the same row, and an atomic update changes pending to leased. If the worker disappears, the lease expires and the row becomes eligible again.
That is at-least-once processing. Exactly-once delivery is not a promise an external email or SMS API can make. The practical contract is “at least once internally, one business effect per idempotency key.”
Ship it.
How can cron, delayed messages, and webhooks handle retries?
Use cron as a clock, not as a queue. Every minute (or less often if the product allows it), it selects a bounded page of due reminders. The query must be repeatable: due_at <= now, status = 'pending', and an expired lease. A queue message carries the reminder ID and event key. It can be delayed until next_attempt_at, but the database remains the source of truth.
Here is the smallest worker shape I would ship. The send function is an adapter around an email or SMS API; it receives the same idempotency key on every attempt.
type Reminder = {
id: string;
eventKey: string;
channel: "email" | "sms";
recipient: string;
body: string;
attempts: number;
};
async function deliver(reminder: Reminder): Promise<void> {
const result = await send(reminder.channel, {
to: reminder.recipient,
body: reminder.body,
idempotencyKey: reminder.eventKey,
});
if (result.accepted) {
await db.markSent(reminder.id, reminder.eventKey);
return;
}
const retryable = result.code === "timeout" || result.code === "rate_limited";
if (!retryable || reminder.attempts >= 6) {
await db.markDeadLetter(reminder.id, result.code);
return;
}
const delayMs = Math.min(60 * 60_000, 2 ** reminder.attempts * 30_000);
await db.releaseForRetry(reminder.id, Date.now() + delayMs);
}
The dangerous window is between send returning success and markSent. A crash there produces a second attempt. The adapter must therefore deduplicate by event key, or your own outbox must record the provider request before dispatch. A consumer acknowledgement only means your worker finished handling the queue message; it does not magically undo a side effect. In a real replay, I would preserve the original payload, attempt number, provider response class, and lease owner in an audit row, then run the same event key through the adapter again. That gives support a factual answer without asking a tired founder to infer history from logs that rolled over overnight. It also makes a queue migration less scary: export pending rows, re-enqueue them, and keep the key unchanged.
Public webhook endpoints belong at the edge of this flow. Verify a signature, reject a stale timestamp, persist the event key, enqueue the work, and return 202 quickly. If the sender retries a 202 or a network timeout, the persisted key turns the second delivery into a no-op. Never make the webhook wait for an SMS carrier.
Evaluating time-zone rules for a weekly gaming digest
For a digest, I calculate the next occurrence from the customer’s IANA zone, then store the UTC instant. A weekly job that means “Monday at 09:00 in America/Los_Angeles” must be recalculated after each send, not advanced by 7 * 24 hours. Calendar weeks and elapsed hours diverge around daylight-saving transitions.
The catch is operational simplicity has a boundary. A cron sweep is a poor fit for sub-second reminders, millions of rows due at the same instant, or workflows that need visual history and human approvals. Stick with a hosted workflow engine or a specialized scheduler when those requirements pay for their operational cost. For one-person SaaS volumes, a database lease plus a queue is easier to inspect than a bespoke timing wheel.
I also keep the weekly digest content immutable once it is queued. If a player changes preferences later, that affects the next digest, not a message already claimed. This avoids a subtle duplicate: one worker renders the old audience while another retries with the new audience under the same event key.
Failure drills for delayed email, SMS, timezone, and webhook paths
Test the failure boundaries, not just the happy path. Freeze the clock around a daylight-saving transition. Run two workers against one row and assert one lease wins. Kill a worker after the adapter accepts the event and before markSent; a replay must not create a second business effect. Send the same webhook event three times and assert one queue message is processed.
My first implementation treated a provider timeout as a definite failure. That was wrong: the provider may have accepted the request before the connection died. Now a timeout is “unknown,” and the idempotency key decides whether retrying is safe. I’m not sure every downstream provider preserves keys for the same duration, so I document that retention window and cap retries accordingly. Your mileage may vary.
Track due_lag_seconds, lease expiries, retry counts, dead-letter size, and webhook signature failures. Alert on age, not only count: ten stuck reminders matter more than ten thousand healthy ones. Keep a replay command that takes an event key, because support will eventually ask why one customer missed a digest.
At scale, I would partition due scans by due_at, add an outbox table for provider calls, and move rendering to a versioned template worker. I would also separate email and SMS queues so a carrier slowdown cannot delay email. None of that changes the contract: UTC timestamps, explicit time zones, short leases, at-least-once delivery, and idempotent business effects.
That contract is the durable part. The cron expression, queue library, and public endpoint framework are replaceable details.
Top comments (0)