How to build a PagerDuty alternative

How to build a PagerDuty alternative with a weekly rotation, signed alert intake, acknowledgement, and durable escalation. Test retries before routing alerts.

  • guide
  • vibe-coding

How to build a PagerDuty alternative starts with one team and a test alert. We will build Shiftbell, the project on the PagerDuty catalog page. It chooses an assignee, records an incident, and sends an email through a provider you already use.

Keep your existing incident service in place while testing. This tutorial builds a small routing tool. Before it carries production alerts, you need to exercise delivery failures and recovery with the people who will receive them.

Read the PagerDuty teardown for the product boundary. Here we will concentrate on implementation prompts and observable checks. Our fixture uses a team named Cedar with Ada and Ben on a weekly rotation. Those names and incidents are sample data.

How to build a PagerDuty alternative with one escalation policy

The first version accepts a signed webhook, finds the on-call person, and records a pending delivery. A background worker sends the email. An authenticated team member can acknowledge or resolve the incident. A scheduled worker escalates incidents whose acknowledgement deadline passed.

Use explicit states: open, acknowledged, and resolved. Sending an email is a delivery event, not an incident state. Otherwise a successful provider response can accidentally look like a resolved incident.

The catalog separates a basic schedule and email path, a more complete handoff and timeline version, and a much larger incident platform. This tutorial pulls acknowledgement into the basic path because escalation needs a durable stop condition. Leave phone calls, SMS, event correlation, automatic remediation, and status pages outside this build.

Choose the stack and persistence boundary

Use Astro server rendering for the dashboard, HTMX for small form updates, and Alpine for a local countdown display. Put incident state in D1 and run scheduled work in a Worker. Store email credentials as deployment secrets. The browser never calculates who receives the next alert.

Use an outbox table beside the incident tables. Creating the incident, its initial timeline entry, and its delivery job must be one atomic operation. A request that crashes after committing can then retry without creating another incident or losing the delivery.

Here is the proposed flow. Every box describes our implementation.

Signed webhookUnique event ID Incident + outboxOne transaction Delivery workerRetry safely Ack or escalateCheck live state
Durable jobs let intake finish independently of email delivery.

Step 1 Create the schema and rotation fixtures

Keep teams, members, schedule assignments, incidents, inbound events, deliveries, and timeline events separate. An assignment records a member, start, and end. Use UTC instants for boundaries and an IANA timezone for editing the schedule. Store the original local rule so the next week’s boundary can be recalculated correctly across daylight saving changes.

An incident records its team, external deduplication key, status, current escalation step, assigned member, and next deadline. Give inbound event ids a unique constraint scoped to the sender. Give delivery jobs a unique key derived from incident and escalation step.

Create Shiftbell with migrations and an isolated test database. Model teams,
active members, time-bounded assignments, incidents, inbound event receipts,
delivery outbox, and an append-only timeline. Use half-open assignment intervals:
start inclusive, end exclusive. Reject overlapping assignments for this v1.
Seed Cedar with Ada and Ben using fixed test timestamps. Add a server function
that finds the assignee at an explicit instant. Keep clock access injectable.

Check the instant just before a handoff, the exact boundary, and just after. At the exact boundary, Ben should receive the new assignment. Also test a gap. A gap must create an unassigned warning for the organizer, rather than silently guessing a recipient.

Step 2 Accept a signed alert once

The sender signs the exact request bytes with a shared secret. Verify the signature before parsing JSON. Include a timestamp and reject stale messages according to a documented tolerance. Avoid logging the signature or secret. Use a separate secret for each inbound integration.

For the first version, accept a title, event id, source name, and deduplication key. Bound every field and the total request size. Render incident text as text, so a title containing markup cannot inject HTML into the dashboard or email.

Add a signed webhook route. Verify a timestamped HMAC over the raw body using
constant-time comparison. Validate bounded fields after signature verification.
In one transaction, insert the inbound event receipt, create or locate the open
incident, append its timeline event, and enqueue initial delivery if needed.
Repeated event IDs return the original result. Invalid requests create no rows.

Replay the same signed request twice. Check the database for one receipt and one initial delivery. Change one byte in the body and send it with the old signature. Expect rejection and no new rows. Then send a legitimate repeat signal with a different event id but the same open incident key; it should enrich the timeline without paging again under this chosen policy.

Step 3 Deliver from the outbox

Claim due jobs with an expiring lease. Record attempts, the next retry time, and the provider reference when available. A worker can crash after a provider accepts an email but before the local update. Use provider idempotency where supported. Otherwise document that this narrow crash window can produce a duplicate email.

A delivery log should say queued, accepted, failed, or unknown. Calling an email delivered because the provider accepted it would hide a bounce. Add provider feedback later if you need delivery confirmation.

Implement an outbox processor with leases, bounded retries, backoff, and a visible
failed state. Inject the mail adapter for tests. Before sending, re-read incident
status and recipient membership. Skip obsolete jobs. Put incident ID and step in
the provider idempotency key when supported. Redact addresses in diagnostic logs.

Make the fake provider fail twice and succeed on the third attempt. Verify that retries preserve the intended recipient and timeline. Then pause or remove that member before delivery. The job should require reassignment rather than emailing someone who left the rotation.

Step 4 Add acknowledgement and resolution

Require team authentication for state changes. The email links to an incident page, where a member confirms the action with a POST. A link scanner opening an email must never acknowledge an incident through a GET request.

Use conditional updates from the expected state. Resolving an open incident is allowed. Repeating acknowledgement on an already acknowledged incident should return the current state without creating another transition. Every real transition records the actor and server timestamp.

Build authenticated incident detail pages with acknowledge and resolve forms.
Enforce team membership on reads and writes. Validate CSRF protection. Update
state conditionally and append a timeline event in the same transaction. GET
requests never mutate incidents. Repeating a completed action is harmless.

Open the link signed out and in another team’s session. Neither should disclose the incident body. Acknowledge as Ada, refresh, then submit the old form again. The timeline should contain one acknowledgement. Resolve and confirm all pending escalation jobs become obsolete.

Step 5 Escalate using a durable deadline

A scheduled worker finds open incidents whose deadline has passed. It claims the expected escalation step with a conditional update and inserts the next delivery atomically. Two worker invocations must not both advance the same step.

Re-read state inside that transaction. Acknowledgement may arrive after the scan but before the claim. Decide what happens when the policy ends. For this v1, mark the policy exhausted and show it prominently to the organizer; do not loop forever.

Add a scheduled escalation scan. Advance only an open incident at its expected
step with a passed deadline. Atomically set the next step and enqueue its delivery.
An acknowledged or resolved incident cannot advance. Exhausted policies remain
visible with an explanation. Expose queue age and failed jobs in the dashboard.

Run two scans against the same frozen clock. Expect one step advancement and one delivery. Repeat with an acknowledgement committed between scan and claim. Expect no advancement. Move the clock beyond several deadlines and verify your documented catch-up policy; avoid flooding recipients with every missed intermediate message.

Step 6 Deploy and rehearse recovery

Create separate test and production databases. Apply migrations to the test deployment first. Configure the webhook secret, mail credentials, and authenticated team access through the host’s secret and access settings. Never seed production with sample email addresses.

Deploy Astro with the runtime adapter supported by your installed version. Configure the Worker schedule and its D1 binding through Wrangler. Follow the current Cloudflare Cron Triggers documentation for trigger setup, and verify execution through logs and a test incident.

Record the deployed version, migration version, and queue configuration in the README. Export a database backup, restore it into a fresh test database, and confirm that the timeline still identifies the active incident and next deadline. Do this before relying on the app for an overnight alert.

Fix the failures that affect routing

If nobody receives an email, inspect the outbox first. No job means intake failed or the incident was deduplicated. A queued job suggests a worker or binding problem. An accepted provider reference moves the investigation to provider feedback and the destination mailbox.

If the wrong person receives a page, inspect the stored assignment interval and team timezone. Reproduce using the incident timestamp, rather than today’s schedule. If escalation continues after acknowledgement, inspect the conditional update and the delivery worker’s final status check.

Keep an explicit empty state for no active rotation and a visible degraded state for an exhausted queue. Link from that dashboard to the exact failed job. The uptime monitor guide can supply test signals, while the cron monitor guide explains missed execution checks.

Use Shiftbell alongside your current alert service until handoff, duplicate intake, provider failure, acknowledgement races, and restoration have all been rehearsed. Start with the PagerDuty build prompt and keep the phone bridge out of the first release.

Related articles

Read all articles →