> ## Documentation Index
> Fetch the complete documentation index at: https://upstash-context7-agent-09df3c1c-9c05-4093-9d6e-e4e2644ee98c-8.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Notify

You can notify all the workflow runs waiting for a specific event ID.
There are two ways to send a notify request.

## Notify within Workflow

Notifies other workflows waiting for a specific event from within a workflow.

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { serve } from "@upstash/workflow/nextjs";

  export const { POST } = serve<string>(async (context) => {
    const { orderId, processingResult } = context.requestPayload;

    await context.run("process-order", async () => {
      // ...
    })

    const { notifyResponse } = await context.notify(
      "notify-processing-complete",
      `order-${orderId}`,
      {
        orderId,
        status: "completed",
        result: processingResult,
        completedAt: new Date().toISOString()
      }
    );

  });
  ```
</CodeGroup>

## External Notification

You can also notify workflows from external systems using the Workflow Client:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Client } from "@upstash/workflow";

  const client = new Client({ token: "<WORKFLOW_TOKEN>" });

  await client.notify({
    eventId: "order-completed-123",
    eventData: {
      orderId: "123",
      status: "completed",
      deliveryTime: "2 days",
      trackingNumber: "TRK123456"
    }
  });
  ```
</CodeGroup>

## Lookback Functionality

By default, if you call `notify` before a workflow reaches its `waitForEvent` step, the notification will be lost (race condition). To prevent this, you can provide a `workflowRunId` parameter which enables **lookback** - the notification will be stored and delivered even if sent before the wait step.

This is particularly useful when:

* You trigger a workflow and immediately want to send it an event
* You have concurrent operations where timing is unpredictable
* You want to eliminate race conditions in your event-driven workflows

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { Client } from "@upstash/workflow";

  const client = new Client({ token: "<WORKFLOW_TOKEN>" });

  // Trigger a workflow and get its run ID
  const { workflowRunId } = await client.trigger({
    url: "https://your-app.com/api/process-order",
    body: { orderId: "123" }
  });

  // Immediately notify it with lookback enabled
  // The notification will be delivered even if the workflow
  // hasn't reached waitForEvent yet
  await client.notify({
    eventId: "payment-verified",
    eventData: { verified: true, amount: 100 },
    workflowRunId: workflowRunId, // Enables lookback
  });
  ```
</CodeGroup>

The same also applies to `context.notify` by passing the `workflowRunId` as the fourth argument:

<CodeGroup>
  ```typescript TypeScript theme={null}
  import { serve } from "@upstash/workflow/nextjs";

  export const { POST } = serve<string>(async (context) => {
    const { orderId, processingResult } = context.requestPayload;

    await context.run("process-order", async () => {
      // ...
    })

    const { notifyResponse } = await context.notify(
      "notify-processing-complete",
      `order-${orderId}`,
      {
        orderId,
        status: "completed",
        result: processingResult,
        completedAt: new Date().toISOString()
      },
      "targetWorkflowRunId" // Enables lookback
    );

  });
  ```
</CodeGroup>

<Note>
  When using lookback with `workflowRunId`, the notification is targeted to a specific workflow run rather than all waiters with that event ID.
</Note>


## Related topics

- [context.notify](/workflow/steps/notify.md)
- [client.notify](/workflow/basics/client/notify.md)
- [Human-in-the-Loop](/workflow/howto/realtime/human-in-the-loop.md)
- [Overview](/workflow/features/wait-for-event.md)
- [Waiting for Events](/workflow/examples/waitForEvent.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.