---
title: "User Onboarding Process"
description: "A new user signs up, verifies the email address, and then finishes two setup tasks in order. While a stage waits for the user, the Flow sends reminders."
canonical_url: "https://docs.superdurable.io/examples/user-onboarding-process/"
source: "docs/content/use-cases/user-onboarding-process.mdx"
locale: "en"
language: "python"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# User Onboarding Process

Code on this page is in Python. Other languages: [Go](https://docs.superdurable.io/examples/user-onboarding-process.go.md) · [Java](https://docs.superdurable.io/examples/user-onboarding-process.java.md) · [TypeScript](https://docs.superdurable.io/examples/user-onboarding-process.typescript.md) · [Rust](https://docs.superdurable.io/examples/user-onboarding-process.rust.md)

A new user signs up, verifies the email address, and then finishes two setup tasks in order. While a stage waits for the user, the Flow sends reminders.

**SDKs:** Python · Go · TypeScript · Java · Rust

**Shows:** [Reminder](https://docs.superdurable.io/design-patterns/durable-timer/reminder.md).

**Flow graph: UserOnboardingFlow**

**Steps**

1. `Submit` (start Step): Store the sign-up form and send the verification email. Next: `VerifyEmail`. Writes `Form`.
2. `AccomplishTask1`: Wait for the user to finish task 1 and send a reminder when it is late. Next: `AccomplishTask2`, or `AccomplishTask1` again. Reads `Form`, `Task1Completed`; writes `Status`.
3. `AccomplishTask2`: Wait for the user to finish task 2, then complete onboarding. Next: the Flow completes, or `AccomplishTask2` again. Reads `Form`, `Task2Completed`; writes `Status`.
4. `VerifyEmail`: Wait for email verification and send a reminder when it is late. Next: `AccomplishTask1`, or `VerifyEmail` again. Reads `Form`, `VerifyEmail`; writes `Status`.

**RPCs**

- `accomplish_task_1`: Reads `Status`; publishes to `Task1Completed`.
- `accomplish_task_2`: Reads `Status`; publishes to `Task2Completed`.
- `verify`: Reads `Status`; publishes to `VerifyEmail`.

Example: [examples/python/dex_examples/products/signup/user_signup_flow.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/products/signup/user_signup_flow.py)

## Product requirements

- The username is the Flow ID. A second signup with the same username starts no second Flow, and the start endpoint reports that onboarding already exists.
- The stages run in a fixed order: verify the email, finish task 1, finish task 2. Then the Flow sends a welcome email and completes.
- Each stage sends a reminder every 24 seconds in the example until the user acts.
- The application advances the stages through three RPCs: verify, accomplish task 1, and accomplish task 2. An RPC called at the wrong stage changes nothing and replies, for example, `task 1 is not waiting`.
- A user who never finishes keeps getting reminders until the Flow completes, is canceled, or reaches its Flow timeout.

## Flow design

**Submit** stores the form, sends the verification email, and moves to `VerifyEmail`. Then `VerifyEmail`, `AccomplishTask1`, and `AccomplishTask2` each wait for the user.

Each waiting Step races a 24-second Timer against its own Channel with `AnyOf`. When the Channel message arrives first, `Execute` moves to the next stage. When the Timer fires first, `Execute` sends a reminder and moves back to the same Step, which starts a new Timer.

Two choices shape the Flow:

- **One Channel per stage.** `VerifyEmail`, `Task1Completed`, and `Task2Completed` are separate, so a user action wakes only the Step that waits for it.
- **The stage lives in the `Status` Attribute.** Each `WaitFor` sets it, and the value is saved with the `WaitFor` result. The RPCs read it to reject an action that arrives at the wrong stage.

A real email call needs an [idempotency key](https://docs.superdurable.io/concepts/step.md#idempotency-keys), because a Step that was cut off can run again. The examples pass none. In Python, Go, Java, and TypeScript the email sender is a stub, and the Rust example records events instead.

## Core implementation

The first snippet declares the Flow. The second shows the `AccomplishTask1` Step; the Python tab also shows the RPC that publishes to its Channel. The Rust example takes only the email as input and records events instead of sending emails. Each linked example also has the RPCs, the HTTP controller, and an integration test.

**Python**

```python
class UserOnboardingFlow(Flow[SignupForm]):
    form = Attribute("Form", SignupForm)
    status = Attribute("Status", str)
    verify_email = Channel[None]("VerifyEmail", type(None))
    task_1_completed = Channel[None]("Task1Completed", type(None))
    task_2_completed = Channel[None]("Task2Completed", type(None))

    def __init__(self, service: MyDependencyService) -> None:
        self.service = service
        self.verify_step = VerifyEmail(service, self.form, self.verify_email, self.status)
        self.task_1_step = AccomplishTask1(
            service,
            self.form,
            self.status,
            self.task_1_completed,
        )
        self.task_2_step = AccomplishTask2(
            service,
            self.form,
            self.status,
            self.task_2_completed,
        )
        self.submit = Submit(service, self.form, self.status, self.verify_step)

    def get_steps(self) -> StepList[SignupForm]:
        return StepList.start_step(self.submit).other_steps(
            self.verify_step,
            self.task_1_step,
            self.task_2_step,
        )

    def get_persistence_schema(self) -> PersistenceSchema:
        return PersistenceSchema.of(
            self.form,
            self.status,
            self.verify_email,
            self.task_1_completed,
            self.task_2_completed,
        )
```

```python
class AccomplishTask1(Step[None]):
    def __init__(
        self,
        service: MyDependencyService,
        form: Attribute[SignupForm],
        status: Attribute[str],
        task_1_completed: Channel[None],
    ) -> None:
        self.service = service
        self.form = form
        self.status = status
        self.task_1_completed = task_1_completed

    def wait_for(self, context: Context, input: None) -> Wait:
        self.status.set(context, "waiting_for_task_1")
        return Wait.any_of(
            Timer.by_duration(timedelta(seconds=24)),
            self.task_1_completed.for_one(),
        )

    def execute(self, context: Context, input: None) -> StepDecision:
        signup_form = self.form.get(context)
        if self.task_1_completed.results(context):
            self.service.send_email(
                signup_form.email,
                "complete onboarding task 2",
                "task 2 is ready",
            )
            return go_to(AccomplishTask2, None)
        self.service.send_email(
            signup_form.email,
            "task 1 reminder",
            "please complete onboarding task 1",
        )
        return go_to(AccomplishTask1, None)
```

```python
@rpc
def accomplish_task_1(self, context: Context) -> RPCResult[str]:
    if self.status.get(context) != "waiting_for_task_1":
        return RPCResult("task 1 is not waiting")
    self.task_1_completed.publish(context, None)
    return RPCResult("task 1 accomplished")
```

Example: [examples/python/dex_examples/products/signup/user_signup_flow.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/products/signup/user_signup_flow.py)

## Run it

<a id="demo"></a>

Start the examples of one language as in [Run an example from the playground](https://docs.superdurable.io/install.md#run-an-example-from-the-playground). In the [examples playground](https://github.com/superdurable/dex/tree/main/examples/playground), choose **User onboarding process**. Call **Submit** with a `username`, which becomes the Flow ID. Then call **Verify**, **Accomplish task 1**, and **Accomplish task 2** in that order with the same `username`.

Before each call, wait until the `Status` Attribute in Dex Web shows the stage that call needs: `waiting_for_verification`, `waiting_for_task_1`, or `waiting_for_task_2`. A call that arrives too early changes nothing and replies, for example, `task 1 is not waiting`. Wait for the status to change, then call again.

The Rust example also offers **Start (Rust)**. It generates a Flow ID when you leave `workflowId` empty; pass that ID as the `username` of the later calls.

In Dex Web, open the Flow's **Events**. **Timeline** shows when each user action arrived. **Graph** shows each completed Step and the Timer and Channel it waited on.

[![Dex Web Timeline showing signup, verification, and both onboarding tasks](https://docs.superdurable.io/img/use-cases/user-onboarding-process-timeline.png)](https://docs.superdurable.io/img/use-cases/user-onboarding-process-timeline.png)

[![Dex Web Graph showing signup, verification, and both onboarding tasks](https://docs.superdurable.io/img/use-cases/user-onboarding-process-graph.png)](https://docs.superdurable.io/img/use-cases/user-onboarding-process-graph.png)

## Next

[Money Transfer](https://docs.superdurable.io/examples/money-transfer.md)
