Features

Middleware

Middleware allows you code to run at various points in an Inngest client's lifecycle, such as during a function's execution or when sending an event.

This can be used for a wide range of uses:

Middleware SDKs support

Middleware are available in the TypeScript SDK v2.0.0+ and Python SDK v0.3.0+.

Support in the Go SDK in planned.

Middleware lifecycle

Middleware can be registered at the Inngest clients or functions level.

Adding middleware contributes to an overall "stack" of middleware. If you register multiple middlewares, the SDK will group and run hooks for each middleware in the following order:

  1. Middleware registered on the client, in descending order
  2. Middleware registered on the function, in descending order

For example:

const inngest = new Inngest({
  id: "my-app",
  middleware: [
    logMiddleware, // This is executed first
    errorMiddleware, // This is executed second
  ],
});

inngest.createFunction(
  {
    id: "example",
    middleware: [
      dbSetupMiddleware, // This is executed third
      datadogMiddleware, // This is executed fourth
    ],
  },
  { event: "test" },
  async () => {
    // ...
  }
);

Learn more about the Middleware hooks and their execution order in "Creating a Middleware".