Skip to main content

User Onboarding Process

View as Markdown

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.

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, 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.

user_signup_flow.pyPython
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,
)
user_signup_flow.pyPython
class AccomplishTask1(Step[None]):

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)
user_signup_flow.pyPython
@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

Run it

Start the examples of one language as in Run an example from the playground. In the 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

Dex Web Graph showing signup, verification, and both onboarding tasks

Next

Money Transfer