$npx -y skills add inngest/inngest-skills --skill inngest-durable-functionsUse when building functions that must survive process crashes, retry automatically on failure, run on a schedule, react to events, or maintain state across infrastructure failures — e.g., webhook handlers that drop events, flaky cron jobs, background jobs that fail mid-execution,
| 1 | # Inngest Durable Functions |
| 2 | |
| 3 | Master Inngest's durable execution model for building fault-tolerant, long-running workflows. This skill covers the complete lifecycle from triggers to error handling. |
| 4 | |
| 5 | > **These skills are focused on TypeScript.** For Python or Go, refer to the [Inngest documentation](https://www.inngest.com/llms.txt) for language-specific guidance. Core concepts apply across all languages. |
| 6 | |
| 7 | ## Core Concepts You Need to Know |
| 8 | |
| 9 | ### **Durable Execution Model** |
| 10 | |
| 11 | - **Each step** should encapsulate side-effects and non-deterministic code |
| 12 | - **Memoization** prevents re-execution of completed steps |
| 13 | - **State persistence** survives infrastructure failures |
| 14 | - **Automatic retries** with configurable retry count |
| 15 | |
| 16 | ### **Step Execution Flow** |
| 17 | |
| 18 | ```typescript |
| 19 | // ❌ BAD: Non-deterministic logic outside steps |
| 20 | async ({ event, step }) => { |
| 21 | const timestamp = Date.now(); // This runs multiple times! |
| 22 | |
| 23 | const result = await step.run("process-data", () => { |
| 24 | return processData(event.data); |
| 25 | }); |
| 26 | }; |
| 27 | |
| 28 | // ✅ GOOD: All non-deterministic logic in steps |
| 29 | async ({ event, step }) => { |
| 30 | const result = await step.run("process-with-timestamp", () => { |
| 31 | const timestamp = Date.now(); // Only runs once |
| 32 | return processData(event.data, timestamp); |
| 33 | }); |
| 34 | }; |
| 35 | ``` |
| 36 | |
| 37 | ## Function Limits |
| 38 | |
| 39 | **Every Inngest function has these hard limits:** |
| 40 | |
| 41 | - **Maximum 1,000 steps** per function run |
| 42 | - **Maximum 4MB** returned data for each step |
| 43 | - **Maximum 32MB** combined function run state including, event data, step output, and function output |
| 44 | - Each step = separate HTTP request (~50-100ms overhead) |
| 45 | |
| 46 | If you're hitting these limits, break your function into smaller functions connected via `step.invoke()` or `step.sendEvent()`. |
| 47 | |
| 48 | ## When to Use Steps |
| 49 | |
| 50 | **Always wrap in `step.run()`:** |
| 51 | |
| 52 | - API calls and network requests |
| 53 | - Database reads and writes |
| 54 | - File I/O operations |
| 55 | - Any non-deterministic operation |
| 56 | - Anything you want retried independently on failure |
| 57 | |
| 58 | **Never wrap in `step.run()`:** |
| 59 | |
| 60 | - Pure calculations and data transformations |
| 61 | - Simple validation logic |
| 62 | - Deterministic operations with no side effects |
| 63 | - Logging (use outside steps) |
| 64 | |
| 65 | ## Function Creation |
| 66 | |
| 67 | ### Basic Function Structure |
| 68 | |
| 69 | ```typescript |
| 70 | const processOrder = inngest.createFunction( |
| 71 | { |
| 72 | id: "process-order", // Unique, never change this |
| 73 | triggers: [{ event: "order/created" }], |
| 74 | retries: 4, // Default: 4 retries per step |
| 75 | concurrency: 10 // Max concurrent executions |
| 76 | }, |
| 77 | async ({ event, step }) => { |
| 78 | // Your durable workflow |
| 79 | } |
| 80 | ); |
| 81 | ``` |
| 82 | |
| 83 | ### **Step IDs and Memoization** |
| 84 | |
| 85 | ```typescript |
| 86 | // Step IDs can be reused - Inngest handles counters automatically |
| 87 | const data = await step.run("fetch-data", () => fetchUserData()); |
| 88 | const more = await step.run("fetch-data", () => fetchOrderData()); // Different execution |
| 89 | |
| 90 | // Use descriptive IDs for clarity |
| 91 | await step.run("validate-payment", () => validatePayment(event.data.paymentId)); |
| 92 | await step.run("charge-customer", () => chargeCustomer(event.data)); |
| 93 | await step.run("send-confirmation", () => sendEmail(event.data.email)); |
| 94 | ``` |
| 95 | |
| 96 | ## Triggers and Events |
| 97 | |
| 98 | ### **Event Triggers** |
| 99 | |
| 100 | Triggers are defined in the `triggers` array in the first argument of `createFunction`: |
| 101 | |
| 102 | ```typescript |
| 103 | // Single event trigger |
| 104 | inngest.createFunction( |
| 105 | { id: "my-fn", triggers: [{ event: "user/signup" }] }, |
| 106 | async ({ event }) => { /* ... */ } |
| 107 | ); |
| 108 | |
| 109 | // Event with conditional filter |
| 110 | inngest.createFunction( |
| 111 | { id: "my-fn", triggers: [{ event: "user/action", if: 'event.data.action == "purchase" && event.data.amount > 100' }] }, |
| 112 | async ({ event }) => { /* ... */ } |
| 113 | ); |
| 114 | |
| 115 | // Multiple triggers (up to 10) |
| 116 | inngest.createFunction( |
| 117 | { |
| 118 | id: "my-fn", |
| 119 | triggers: [ |
| 120 | { event: "user/signup" }, |
| 121 | { event: "user/login", if: 'event.data.firstLogin == true' }, |
| 122 | { cron: "0 9 * * *" } // Daily at 9 AM |
| 123 | ] |
| 124 | }, |
| 125 | async ({ event }) => { /* ... */ } |
| 126 | ); |
| 127 | ``` |
| 128 | |
| 129 | ### **Cron Triggers** |
| 130 | |
| 131 | ```typescript |
| 132 | // Basic cron |
| 133 | inngest.createFunction( |
| 134 | { id: "my-fn", triggers: [{ cron: "0 */6 * * *" }] }, // Every 6 hours |
| 135 | async ({ step }) => { /* ... */ } |
| 136 | ); |
| 137 | |
| 138 | // With timezone |
| 139 | inngest.createFunction( |
| 140 | { id: "my-fn", triggers: [{ cron: "TZ=Europe/Paris 0 12 * * 5" }] }, // Fridays at noon Paris time |
| 141 | async ({ step }) => { /* ... */ } |
| 142 | ); |
| 143 | |
| 144 | // Combine with events |
| 145 | inngest.createFunction( |
| 146 | { |
| 147 | id: "my-fn", |
| 148 | triggers: [ |
| 149 | { event: "manual/report.requested" }, |
| 150 | { cron: "0 0 * * 0" } // Weekly on Sunday |
| 151 | ] |
| 152 | }, |
| 153 | async ({ event |