DEV Community

Atlas Whoff
Atlas Whoff

Posted on

Inngest: Event-Driven Workflows Without Managing Queues

Inngest: Event-Driven Workflows Without Managing Queues

BullMQ requires Redis. Temporal requires a cluster. Inngest gives you durable, retryable background functions with zero infrastructure — just deploy your Next.js app.

What Inngest Does

You define functions. Inngest handles:

  • Reliable delivery (retries with backoff)
  • Scheduling and cron
  • Fan-out and coordination
  • Observability (every run logged)
  • Rate limiting and throttling

No Redis, no worker processes to manage.

Setup

npm install inngest
Enter fullscreen mode Exit fullscreen mode
// inngest/client.ts
import { Inngest } from 'inngest';
export const inngest = new Inngest({ id: 'my-app' });
Enter fullscreen mode Exit fullscreen mode

Define a Function

// inngest/functions/welcome-email.ts
import { inngest } from '../client';

export const sendWelcomeEmail = inngest.createFunction(
  { id: 'send-welcome-email', retries: 3 },
  { event: 'user/signup' },
  async ({ event, step }) => {
    // Each step is retried independently
    const user = await step.run('fetch-user', async () => {
      return db.user.findUnique({ where: { id: event.data.userId } });
    });

    await step.run('send-email', async () => {
      await resend.emails.send({
        to: user.email,
        subject: 'Welcome!',
        html: render(<WelcomeEmail name={user.name} />),
      });
    });

    // Wait 3 days, then send follow-up
    await step.sleep('wait-for-followup', '3d');

    await step.run('send-followup', async () => {
      await resend.emails.send({ to: user.email, subject: 'How is it going?' });
    });
  }
);
Enter fullscreen mode Exit fullscreen mode

API Route (Next.js)

// app/api/inngest/route.ts
import { serve } from 'inngest/next';
import { inngest } from '@/inngest/client';
import { sendWelcomeEmail } from '@/inngest/functions/welcome-email';

export const { GET, POST, PUT } = serve({
  client: inngest,
  functions: [sendWelcomeEmail],
});
Enter fullscreen mode Exit fullscreen mode

Trigger from Anywhere

// In your signup API route
await inngest.send({
  name: 'user/signup',
  data: { userId: newUser.id },
});
Enter fullscreen mode Exit fullscreen mode

Fan-Out Pattern

export const processOrder = inngest.createFunction(
  { id: 'process-order' },
  { event: 'order/created' },
  async ({ event, step }) => {
    // Run all three in parallel
    await Promise.all([
      step.run('charge-card', () => stripe.paymentIntents.confirm(event.data.paymentId)),
      step.run('reserve-inventory', () => inventory.reserve(event.data.items)),
      step.run('notify-warehouse', () => warehouse.notify(event.data.orderId)),
    ]);
  }
);
Enter fullscreen mode Exit fullscreen mode

Cron Jobs

export const dailyReport = inngest.createFunction(
  { id: 'daily-report' },
  { cron: '0 9 * * *' }, // 9 AM UTC
  async ({ step }) => {
    const metrics = await step.run('gather-metrics', getYesterdayMetrics);
    await step.run('send-report', () => sendReportEmail(metrics));
  }
);
Enter fullscreen mode Exit fullscreen mode

Inngest is a perfect fit for AI SaaS workflows — onboarding sequences, async AI processing, scheduled reports. The AI SaaS Starter Kit includes Inngest pre-configured with example functions. $99 at whoffagents.com.

Top comments (0)