Inngest to Temporal in 6 days

Shail Patel, Netic Engineering

Netic builds AI agents that answer calls and texts for home-service businesses such as plumbers, HVAC companies and pest control. Behind every conversation there are background jobs: paging a technician, sending a reminder, ending a call that never connected. Between September 29 and October 4 we merged about 100 PRs that moved 40 of those jobs, roughly 2.3M runs a week, from Inngest to Temporal.

Two of those jobs show why this had to be done carefully, and they pull in opposite directions. Emergency paging: when someone calls a plumber at 2am about a burst pipe, we text the on-call technician and keep paging until a person acknowledges. It has to go out right away and can never drop a message. Campaign sends: texts that go out to a business's customers, like a reminder that a tune-up is due. They are high volume and can be retried, but must never reach a customer twice. Most of the migration was about keeping both true while the system changed underneath.

Porting the function bodies was the easy part. The hard part was the behavior Inngest gave us for free that nobody had written down, and knowing at each step whether the cutover was actually working. This post covers both, with the specifics we would want if we were starting an Inngest to Temporal migration today.

~100PRs merged
2.28Mruns / week moved
6,272peak runs / min
~119kruns / wk deduped only by Inngest config

Why?

On InngestOn Temporal
One runtimeThe long tail of jobs, running inside our Vercel app. On-call needed a second retry model, pause mechanism and dashboard.Already ran ~905k workflows and 6.9M activities a week on workers we operate in GCP.
Environment isolationInngest pushes work to an endpoint that every deploy re-registers. Demo deploys holding prod keys took over prod jobs and once sent real campaign texts.Workers pull work. Only one service per environment polls its namespace, and a web deploy contains no worker.
FailoverJobs ran on Vercel, outside our regional design.Jobs run next to the workers and database, inside the two-region active-active design.

The method

Every job went through the same four stages.

  1. Build darkWrite the Temporal workflow next to the Inngest function and deploy it with no traffic, or in shadow mode, where it runs for real but its texts and calls go to a table instead of a phone. Before anything can run on both sides, rebuild the duplicate protection that Inngest's config was providing.
  2. Cut overFlip a feature flag or unpause a schedule. One or two customers for one send window first, then everyone. The Inngest function is paused, not deleted, and a tripwire monitor now pages if it starts even one run.
  3. ReconcileEvery hour, a workflow compares what should have happened with what did, job by job, and reports each comparison to Datadog as pass or fail.
  4. RetireDelete the function from the code, resync the Inngest app and confirm it is archived. The tripwire stays on. A run now means an old deployment is still serving the function.

Gates were tiered by what a failure costs. Campaign sends can be fixed forward, so on October 1 they dropped the bakes and went to a one-window canary, then 100%. Emergency paging kept its gates, because a failure there can happen at 2am with nobody watching, and a missed page cannot be fixed in the morning. The rule: skip a gate that only costs time, keep one that protects against something irreversible.

What Inngest was doing for free

Inngest and Temporal both run code reliably, but they disagree about what happens when you don't say anything. These are the options and defaults we were depending on without knowing it.

Config was the unique key

In Inngest you prevent duplicate work with options on the function: idempotency (run once per key), rateLimit (at most N runs per key per period), concurrency and cancelOn. For about 78% of our campaign sends, those options were the only thing stopping a second text. There was no unique constraint in the database, and nothing a grep for UNIQUE would find. Temporal has none of these options, so each one had to become something explicit.

  • Idempotency keys became workflow IDs. We build the Temporal workflow ID from the same fields as the Inngest idempotency key and start it with the REJECT_DUPLICATE reuse policy. A second start for the same send is then refused, even after the first has finished, for as long as Temporal retains the first run. One catch: the Temporal TypeScript SDK version we run has no conflict-policy option for child workflows, so every startChild has to catch WorkflowExecutionAlreadyStartedError and treat it as "already handled".
  • Rate limits became a key in Redis. A rateLimit such as "one text per customer per campaign per window" has no Temporal equivalent. We replaced it with a Redis key (we use Upstash) written with SET key NX EX seconds: set the key only if it does not exist, and expire it when the window ends. If the write succeeds, send. If the key is already there, something was sent recently, so skip. We gave the Redis key the same string Inngest used for its rate-limit key and had the Inngest function start writing it too, 12 hours before the first customer moved. When Temporal took over, Redis already knew what Inngest had sent that day, so the first Temporal run could not repeat it.

Retries, timeouts and "not now"

  • Retries default the other way. Most of our Inngest functions ran retries: 0. A Temporal activity retries forever unless you say otherwise, and a retried send is a second text or a second phone call. If you are migrating: go through every activity that has an effect outside your database and set maximumAttempts yourself. Every send activity of ours got maximumAttempts: 1.
  • A timeout skips your error handling. When a Temporal workflow hits its execution timeout, the server closes it. Your catch and finally blocks never run, so "on failure, mark the row failed" does not happen. And because that workflow ID is now used, starting it again under REJECT_DUPLICATE does nothing. For us that meant a send could sit in scheduled forever with no error anywhere. If you are migrating: do not count on cleanup inside the workflow when it times out. Keep everything the workflow waits for well inside the timeout, and add a separate periodic check that looks for rows stuck in a non-final state.
  • "Not now" is not a failure. Quiet hours are the hours a customer must not be texted, such as after 8pm local time. In our first port, a send that landed in quiet hours took the same path as a failed send. Review caught it: a text due at 8:05pm would have been marked failed and never sent. If you are migrating: the "can't do it right now" cases (quiet hours, a rate limit, a lock someone else holds) are easy to fold into the error path, and once retries are turned down that path is final. Give "defer" its own outcome that reschedules the work without spending an attempt.

Schedules catch up; crons did not

If an Inngest cron misses its time, that run is gone and the next one happens at the next cron time. A Temporal schedule is different in two ways, and both can run stale work.

  • Temporal remembers runs it could not start. If the schedule could not fire for a while, Temporal starts every run it missed as soon as it can, as long as each is inside the schedule's catch-up window. The default window is one year. Setting catchupWindow: 0 does not turn this off, because zero is treated as "not set".
  • A run that starts on time can still execute late. Workers are the processes we run that pick work up from Temporal. If they are down, say from a bad deploy or a regional outage, Temporal still starts each run on schedule. It waits in the queue and executes when a worker comes back, which could be hours later.

Either way, a job meant for 2pm can run at 6pm. For a job that texts customers, that is a batch of messages built for the afternoon going out in the evening, possibly after quiet hours have started. Drag the slider to see the first case for a job scheduled every 15 minutes. Each bar is one run that was due while the schedule could not fire.

The fix has two parts, one for each case. Every schedule with side effects sets catchupWindow explicitly, to at most min(interval, 10 minutes), so older missed runs are dropped. And every such run starts by comparing the time it was scheduled for with the clock. If it is later than the job's allowed lateness, it exits without doing anything and leaves the work to the next on-time run.

Overlap is the other default to check. When a run is still going as the next one comes due, Inngest's concurrency: 1 queues the next one. Temporal's default overlap policy, SKIP, drops it. Jobs that have to process every 15-minute bucket use BUFFER_ONE, which keeps one run waiting.

What only the cutover needed

One problem had nothing to do with Inngest's defaults. It exists only because, for a while, both systems are live.

Claim the row before sending

During a cutover, the Inngest function and the Temporal workflow can both pick up the same text. Inngest's idempotency key only stops a second Inngest run. A Temporal workflow ID only stops a second Temporal workflow. Neither can see the other.

The one thing both can see is the database. Every text we plan to send is a row in a table, with status scheduled. Before sending, a runtime has to claim the row: it writes its own ID onto the row with a single UPDATE that only matches if nobody else has written theirs.

UPDATE campaign_outbound
SET delivery_claimed_at = now(), delivery_claim_id = $mine
WHERE id = $id AND status = 'scheduled'
  AND (delivery_claim_id IS NULL OR delivery_claim_id = $mine)

Postgres applies one UPDATE to a row at a time, so exactly one runtime gets "1 row updated" and sends. The other gets "0 rows updated", records a skip and stops. The last line lets the same ID claim again, so a runtime that retries its own step is not locked out by its own claim. If the send itself fails, the claim is released so the normal failure handling can try again later. Here are the four cases.

Monitors unlocked the automation

A migration like this is mostly waiting and checking. Is the new job running? Is the old one really off? Are the results the same? We ran most of the steps with coding agents, and an agent cannot look at a dashboard and decide it feels fine. It needs a command that returns pass or fail.

That is what the monitors are for. They do not fix anything. Each one does two jobs: it pages a person when something is wrong, and it is a gate. A job cannot move to its next stage until a script reads that job's monitors from Datadog and every one is healthy.

To keep that manageable across 40 jobs we wrote what we call the schedule manifest. It is not a Temporal feature. It is a TypeScript file in our repo with one entry per job: when it runs, on which queue, how often it should report success, which Inngest function it replaces, which stage of the migration it is in and which correctness checks apply. This is the trimmed entry for the ring-timeout sweep, a job that runs every minute and ends inbound calls that rang too long without connecting:

defineSchedule({
  id: "ring-timeout-sweep-schedule",
  envs: { prd: "active", stg: "paused", dev: "paused" },
  spec: { cronExpressions: ["* * * * *"], timezone: "UTC" },
  workflowType: "ringTimeoutSweepWorkflow",
  taskQueue: QUEUES.CRITICAL,
  catchupWindow: { minutes: 5 },
  overlap: "SKIP",
  // "expect a successful run at least this often"
  heartbeat: { interval: { minutes: 2, seconds: 30 } },
  migration: {
    tier: MigrationTier.T0,
    reconcileCheckIds: ["rt_settle", "rt_gap", "rt_dup", /* ... */],
    maxLateness: { minutes: 5 },
  },
})

Two things read this file. A script creates and updates the Temporal schedules from it. A generator writes the Datadog monitors from it, and a test fails CI if the generated monitors do not match. Nobody writes these monitors by hand, and changing a job's stage in the manifest changes its alerts.

For the ring-timeout sweep, that entry produces 13 monitors, and each one answers one of four questions. Nine of them depend on reconcile checks: SQL queries that run every hour, compare what the job did with what should have happened, and report pass or fail to Datadog. (The rt_ in the check names is our prefix for "ring timeout".) Pick a stage to see which monitors are live, then click any monitor.

Two rules keep the monitors themselves honest. Anything that should always have data, like the heartbeat and each check's result, alerts on silence, because a job that has stopped looks exactly like a job with nothing to report. And before monitors are applied, a validation step refuses any heartbeat or tripwire whose metric has had no data in 30 days, so a typo in a tag cannot create a monitor that stays green forever.

What they caught

  • Schedule drift. Comparing the live Temporal schedules with the manifest found one running a 10-second catch-up window where the manifest said 0. Temporal stores any window under 10 seconds as 10 seconds. We put the same floor in the manifest, and all 34 schedules then matched exactly.
  • An Inngest cron that was still on. Before enabling the Temporal version of a scheduled campaign job, we checked the pause state of every Inngest cron by key. One was still live. It was paused before its next run, which would otherwise have gone out alongside the Temporal one.

Takeaways

  1. List what the old system does for you through configuration. In Inngest, dedup, rate limits, concurrency and cancellation are options on the function. They are not in your code or your database, so nothing carries them over. Each one has to be rebuilt on purpose.
  2. Set every default explicitly. Retries, timeouts, schedule catch-up and overlap all behave differently in Temporal. A job ported line for line keeps its logic and changes its behavior.
  3. While both systems are live, dedup has to sit where both can see it. Neither runtime's idempotency can see the other, so the guard belongs in the database.
  4. Alert on everything you turn off. A paused or retired job should never run again, so one run is enough to page.
  5. Make every gate a command that returns pass or fail, and write the order of the steps down. That is what lets an agent, or a tired person, run the migration safely.