Written by Huifer, solo developer and maintainer of TanStack Ship. I have run email automation on TanStack Start + Cloudflare Workers + D1 since 2022, and push is the channel I bolt on last — because the trigger and data-model work is the same, but the delivery rules are unforgiving. This post is the schema and workflow design I now start from. Where I lack a trustworthy measurement, I say so instead of quoting a number.
Verified sources: TanStack Start docs · web.dev push notifications · Cloudflare Workers docs · MDN Push API · RFC 8030 — Web Push protocol · RFC 8292 — VAPID
Last updated: 2026-10-26 · Changelog
Push Notification Automation: Trigger Workflows + Data Model
Push notification automation is the system that turns an event — a signup, a state change, a schedule tick, a stretch of silence — into a queued, deduplicated, permission-checked web push message. It has three layers: a trigger model, a workflow sequence engine, and a notification data model. This guide defines each layer and gives you the D1 schema and Workers code that implement them. It is written for solo founders and full-stack developers deciding what their SaaS stack must handle natively — and if you are evaluating boilerplates instead of building from zero, see which SaaS templates include this.
If you searched for a "push notification automation trigger workflow sequence," you are really searching for the wiring between those three layers — so let's name them precisely.
TL;DR
- Push notification automation = triggers + sequences + a data model. Skip any layer and you get duplicate or silently dropped notifications.
- Design trigger classes first (user action, state change, schedule, inactivity), then encode them as deduplicated events.
- Idempotency is the whole game: a unique constraint per (enrollment, step) beats every retry bug I have hit.
- Web push itself is standardized and free to send — the real cost is state management, not vendor fees.
Definition (for citation): Push notification automation is the practice of sending web push messages from defined triggers through a sequenced workflow, backed by a data model that records subscriptions, enrollments, and delivery outcomes, so each notification fires exactly once.
A note on provenance: in our Search Console data (user-provided, 28-day window), this query cluster currently surfaces our email marketing automation guide at an average position of 5.4 with 32 impressions — meaning readers arrive at the email post wanting the push answer. This article is that answer. The two channels share the trigger and data-model layers; only delivery differs.
The trigger model: five event classes that start a push
A trigger is anything that says "this user should now receive a notification." In production I have found it a mistake to let triggers talk to the sender directly. Every trigger should first write an event with a deduplication key, and everything downstream reads events — never raw webhooks or raw cron ticks. This matters more for push than email because push delivery is instant and user-visible; a duplicate is a UX bug in your users' notification center.
| Trigger class | Fires when | Example | Deduplication key | Typical failure mode |
|---|---|---|---|---|
| User action | Explicit in-product event | Published a release, completed a task | event_id | Re-enrollment when a webhook replays |
| State change | A row crosses a threshold | Invoice past due, quota exceeded | entity_id + state | Flapping state re-fires daily |
| Schedule | Cron tick | Monday digest at 09:00 | cron slot + user | Duplicate sends on overlapping cron runs |
| Inactivity | Absence of an event | 14 days with no session | user_id + gap window | Firing after the user already returned |
| Late/backfill | Event arrives out of order | Subscription renewed while offline | provider dedupe ID | Silent drop or double send |
The right-column failure modes are structural, not measured benchmarks — they are the states my sequence tables are designed to make impossible. Webhook duplicates are not hypothetical: Stripe's own webhook documentation tells you endpoints must tolerate the same event delivered more than once, so your trigger layer must deduplicate before it enrolls anyone.
The workflow sequence engine: steps, delays, and idempotency
A sequence (what email folks call a drip campaign) is an ordered list of steps with delays. A workflow is the larger machine: trigger → conditions → one or more sequences. An enrollment is the per-user state machine inside that workflow: which sequence, which step, when the next step is due.
I define sequences as data, not code, because I edit them weekly and redeploying a Worker for a copy tweak is a smell:
// sequences.ts — push notification automation sequence definition
export type SequenceStep = {
index: number
offsetMinutes: number // delay from enrollment time
templateId: string
requireAll: string[] // conditions that must still hold when the step fires
}
export const trialEndingSequence: SequenceStep[] = [
{ index: 0, offsetMinutes: 0, templateId: "trial-day-2", requireAll: ["trial_active"] },
{ index: 1, offsetMinutes: 60 * 48, templateId: "trial-last-day", requireAll: ["trial_active"] },
{ index: 2, offsetMinutes: 60 * 24, templateId: "trial-expired", requireAll: ["trial_expired"] },
]
Why sequences break on retries
The runner itself is boring: query enrollments where next_due_at <= now, check requireAll conditions, send, advance the cursor. What is not boring is what happens when the platform retries you. Cloudflare Cron Triggers can invoke your handler again, and any HTTP send can time out after the push service already accepted the message. Without a hard guard you send the "trial ends today" push twice — and there is no undo button in someone's notification tray.
My rule: the delivery row is the lock. Insert a row into notification_deliveries with a primary key of (enrollment_id, step_index, endpoint) and advance the cursor in the same D1 batch — D1 batches run as a single transaction, so both writes commit or neither does. If a retry arrives, the primary-key insert fails, the code path treats that as "already sent," and the cursor advances. One constraint replaces an entire class of distributed-systems anxiety.
The notification data model: a D1 schema that survives retries
This is the layer people skip, then rebuild twice. Five tables carry the whole system:
-- SQLite/D1 schema for push notification automation
CREATE TABLE push_subscriptions (
user_id TEXT NOT NULL,
endpoint TEXT PRIMARY KEY,
p256dh TEXT NOT NULL,
auth TEXT NOT NULL,
user_agent TEXT,
created_at INTEGER NOT NULL,
last_seen_at INTEGER
);
CREATE TABLE sequences (
id TEXT PRIMARY KEY,
name TEXT NOT NULL,
trigger_event TEXT NOT NULL, -- e.g. 'trial.started'
active INTEGER NOT NULL DEFAULT 1
);
CREATE TABLE sequence_steps (
sequence_id TEXT NOT NULL,
"index" INTEGER NOT NULL, -- 'index' is a reserved word in SQLite: quote it
offset_minutes INTEGER NOT NULL,
template_id TEXT NOT NULL,
require_all TEXT NOT NULL, -- JSON array of condition keys
PRIMARY KEY (sequence_id, "index")
);
CREATE TABLE sequence_enrollments (
id TEXT PRIMARY KEY,
user_id TEXT NOT NULL,
sequence_id TEXT NOT NULL,
cursor INTEGER NOT NULL DEFAULT 0,
next_due_at INTEGER NOT NULL,
status TEXT NOT NULL, -- active | done | exited
UNIQUE (user_id, sequence_id) -- one enrollment per user per sequence
);
CREATE TABLE notification_deliveries (
enrollment_id TEXT NOT NULL,
step_index INTEGER NOT NULL,
endpoint TEXT NOT NULL,
sent_at INTEGER NOT NULL,
push_status INTEGER, -- HTTP status returned by the push service
PRIMARY KEY (enrollment_id, step_index, endpoint) -- the idempotency lock
);
What each table buys you:
push_subscriptions— the browser-granted endpoint plus the encryption keys (Push API subscription payload). One user can have several rows — laptop and phone are different endpoints.sequences/sequence_steps— the workflow definitions as data, so a drip campaign is editable without a deploy.sequence_enrollments— the per-user state machine. TheUNIQUE (user_id, sequence_id)constraint is what makes a replayed trigger event a no-op instead of a second enrollment.notification_deliveries— the audit log and the idempotency lock in one. When you ask "did we send this?", the answer is a query, not a guess.
Note the "index" quoting in sequence_steps: index is a reserved word in SQLite and an unquoted column will fail your migration. I learned that the annoying way.
Delivery: VAPID, the service worker, and a Workers cron runner
The delivery layer is the most standardized part of this whole system, which is good news: the Web Push protocol (RFC 8030) defines how a server hands a message to a push service, VAPID (RFC 8292) defines how your server identifies itself, and payload encryption is its own RFC so intermediaries never see plaintext. The web.dev push overview walks the browser side: a service worker receives the push and shows the notification. A successful submission returns HTTP 201; push services can return 429 when you exceed rate limits, which is why my runner batches 100 enrollments per minute rather than blasting a queue.
Two platform realities to design around, both documented: on iOS and iPadOS 16.4 and later, web push works only for sites the user has added to the Home Screen, per Apple's web push documentation — so expect iOS enrollment to be a fraction of desktop, and do not treat that as a bug. And subscriptions expire: when a push service answers 404 or 410, the Push API spec describes the subscription as gone, so delete the row and let re-subscription happen naturally.
// worker/cron.ts — Cloudflare Workers Cron Trigger (runs every minute)
import { sendNotification } from "web-push"; // VAPID-signed per RFC 8292
export default {
async scheduled(_controller: unknown, env: Env): Promise<void> {
const now = Date.now();
const due = await env.DB.prepare(`
SELECT e.id, e.user_id, e.sequence_id, e.cursor,
s.template_id, s.require_all
FROM sequence_enrollments e
JOIN sequence_steps s
ON s.sequence_id = e.sequence_id AND s."index" = e.cursor
WHERE e.status = 'active' AND e.next_due_at <= ?
LIMIT 100
`).bind(now).all();
for (const row of due.results) {
const sub = await env.DB.prepare(
"SELECT endpoint, p256dh, auth FROM push_subscriptions WHERE user_id = ?"
).bind(row.user_id).first();
if (!sub) { await markExited(env, row.id); continue; }
try {
await sendNotification(
{ endpoint: sub.endpoint, keys: { p256dh: sub.p256dh, auth: sub.auth } },
JSON.stringify({ templateId: row.template_id, seq: row.sequence_id }),
{ vapidDetails: {
subject: "mailto:you@example.com",
publicKey: env.VAPID_PUBLIC_KEY,
privateKey: env.VAPID_PRIVATE_KEY,
}},
);
await recordDeliveryAndAdvance(env, row.id, row.cursor, sub.endpoint, 201);
} catch (err: any) {
if (err?.statusCode === 404 || err?.statusCode === 410) {
// Subscription gone — prune; the user re-subscribes when they return
await env.DB.prepare("DELETE FROM push_subscriptions WHERE endpoint = ?")
.bind(sub.endpoint).run();
}
// Anything else: leave the cursor in place; the next cron run retries
}
}
},
};
One honest deployment note: the popular web-push package is Node-oriented. On Workers I run it under nodejs_compat; the alternative is a smaller VAPID-and-encryption helper library. Budget an evening for this detail — it is the only part of the stack where the docs disagree with each other.
Does your stack include this? The buyer decision checklist
Here is the buyer decision this article supports: most of push automation is state management, not sending. The send itself is ~40 lines of standardized code. Everything else — permission flow, event deduplication, enrollment state, retries, pruning — is the capability a SaaS boilerplate either includes or makes you build. Before choosing a stack, check for:
- A permission-prompt flow that requests notification permission on user gesture, not page load
- VAPID key management as environment configuration, not hardcoded values
- Trigger events written to a deduplicated event table (not in-memory only)
- A sequence runner with idempotent delivery and retry behavior
- A delivery log you can query, and pruning for expired subscriptions
- Cron/scheduled execution on the server, so sequences survive browser closes
If your current stack fails three or more of those, you are one integration away from rebuilding this article. That is precisely the trade-off worth evaluating before you commit: browse TanStack templates to see which starter includes notification infrastructure, and see template pricing and license terms once you know the capability exists. The license price is secondary to whether the state layer ships in the box.
Limitations, disclosure, and what I have not measured
Disclosure: I maintain TanStack Ship, so links to my own templates are a material connection, stated plainly. I earn nothing from the third-party services referenced here, and there are no affiliate links in this post.
Limitations, labeled honestly:
- Measured: nothing in this post. I deliberately quote no open rates, click rates, or delivery percentages from my own properties — I do not have a measurement setup I would defend publicly, and an invented number would be worse than none. Where you would expect a benchmark, treat it as [needs source].
- User-provided: the Search Console figures (32 impressions, average position 5.4 over 28 days) come from our own property and describe discovery behavior, not notification performance.
- Documented/structural: the RFC behaviors, iOS Home Screen requirement, 201/429/404/410 status semantics, and D1 transaction guarantees are cited to primary documentation above.
- Estimated: the "expect iOS enrollment to be a fraction of desktop" claim is a design assumption based on the Home Screen install requirement, not a measured ratio.
- This schema is designed for SQLite/D1 semantics; porting to Postgres changes the quoting rules and transaction wrapper, though not the model.
FAQ: push notification automation
What is push notification automation?
It is an event-driven system that sends web push messages without manual sending: a trigger (user action, state change, schedule, or inactivity) creates a deduplicated event, a workflow enrolls the user in a sequence, and a data model tracks each enrollment and delivery so every notification fires exactly once.
How is a push drip campaign different from an email drip campaign?
The trigger and data-model layers are nearly identical; delivery differs. Push is permission-bound, short-lived, and best for time-sensitive states like a trial ending or quota exceeded, while email carries long-form content and works without a browser session. Most products run both channels off the same event bus.
Do web push notifications work on iOS?
Yes, since iOS and iPadOS 16.4 — but only for web apps the user has added to the Home Screen, and the user must grant notification permission after installing. Desktop Chrome, Edge, and Firefox support web push for normal sites, so iOS is the constraint, not the standard.
The decision, in one sentence
Push notification automation is a state-management problem: model triggers as deduplicated events, keep enrollment state in your database, and make delivery idempotent with a per-step lock. The specific next action: preview the templates built on TanStack Start + Cloudflare Workers + D1 and decide whether to build this notification layer yourself or start from one that already includes it.