User Onboarding Process
View as MarkdownA 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, andTask2Completedare separate, so a user action wakes only the Step that waits for it. - The stage lives in the
StatusAttribute. EachWaitForsets it, and the value is saved with theWaitForresult. 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.
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,
)
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)
@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
type UserOnboardingFlow struct {
dex.FlowDefaults
service service.MyService
}
func NewUserOnboardingFlow(applicationService service.MyService) *UserOnboardingFlow {
return &UserOnboardingFlow{service: applicationService}
}
func (flow *UserOnboardingFlow) GetSteps() []dex.StepDef {
return []dex.StepDef{
dex.DefineStartStep(submitStep{service: flow.service}),
dex.DefineStep(verifyEmail{service: flow.service}),
dex.DefineStep(accomplishTask1Step{service: flow.service}),
dex.DefineStep(accomplishTask2Step{service: flow.service}),
}
}
func (flow *UserOnboardingFlow) GetRPCs() []dex.RPCDef {
return []dex.RPCDef{
dex.DefineRPC(flow.Verify, nil),
dex.DefineRPC(flow.AccomplishTask1, nil),
dex.DefineRPC(flow.AccomplishTask2, nil),
}
}
func (*UserOnboardingFlow) GetPersistenceSchema() dex.PersistenceSchema {
return dex.PersistenceSchema{
Attributes: []dex.AttributeDef{Form, Status},
Channels: []dex.ChannelDef{VerifyEmail, Task1Completed, Task2Completed},
}
}
func (accomplishTask1Step) WaitFor(ctx dex.Context, _ dex.None) (*dex.Wait, error) {
if err := Status.Set(ctx, StatusWaitingForTask1); err != nil {
return nil, err
}
return dex.AnyOf(dex.Timer(24*time.Second), Task1Completed.ForOne()), nil
}
func (step accomplishTask1Step) Execute(
ctx dex.Context,
_ dex.None,
) (*dex.StepDecision, error) {
form, err := Form.Get(ctx)
if err != nil {
return nil, err
}
results, err := Task1Completed.GetConditionResults(ctx)
if err != nil {
return nil, err
}
if len(results) > 0 {
step.service.SendEmail(form.Email, "complete onboarding task 2", "task 2 is ready")
return dex.GoTo(accomplishTask2Step{}, nil), nil
}
step.service.SendEmail(form.Email, "task 1 reminder", "please complete onboarding task 1")
return dex.GoTo(accomplishTask1Step{}, nil), nil
}
@Component
public class UserOnboardingFlow implements Flow<SignupForm> {
public final Attribute<SignupForm> form = Attribute.define("Form", SignupForm.class);
public final Attribute<String> status = Attribute.define("Status", String.class);
public final Channel<Void> verifyEmail = Channel.define("VerifyEmail", Void.class);
public final Channel<Void> task1Completed = Channel.define("Task1Completed", Void.class);
public final Channel<Void> task2Completed = Channel.define("Task2Completed", Void.class);
private final MyDependencyService service;
private final Submit submit = new Submit();
private final VerifyEmail verifyEmailStep = new VerifyEmail();
private final AccomplishTask1 accomplishTask1Step = new AccomplishTask1();
private final AccomplishTask2 accomplishTask2Step = new AccomplishTask2();
public UserOnboardingFlow(final MyDependencyService service) {
this.service = service;
}
@Override
public StepList<SignupForm> getSteps() {
return StepList.startStep(submit).otherSteps(
verifyEmailStep,
accomplishTask1Step,
accomplishTask2Step);
}
@Override
public PersistenceSchema getPersistenceSchema() {
return PersistenceSchema.of(form, status, verifyEmail, task1Completed, task2Completed);
}
final class AccomplishTask1 implements Step<Void> {
@Override
public Wait waitFor(final Context context, final Void input) {
status.set(context, WAITING_FOR_TASK_1);
return Wait.anyOf(
Timer.byDuration(Duration.ofSeconds(24)),
task1Completed.forOne());
}
@Override
public StepDecision execute(final Context context, final Void input) {
final SignupForm signupForm = form.get(context);
if (!task1Completed.getConditionResults(context).isEmpty()) {
service.sendEmail(signupForm.email, "complete onboarding task 2", "task 2 is ready");
return StepDecision.goTo(AccomplishTask2.class, null);
}
service.sendEmail(signupForm.email, "task 1 reminder", "please complete onboarding task 1");
return StepDecision.goTo(AccomplishTask1.class, null);
}
}
Example: examples/java/src/main/java/io/superdurable/dex/products/signup/UserOnboardingFlow.java
export class UserOnboardingFlow implements Flow<SignupForm> {
public readonly form = new Attribute("Form", signupFormCodec);
public readonly status = new Attribute("Status", stringCodec);
public readonly submit = new Submit(this);
public readonly verifyEmailStep = new VerifyEmail(this);
public readonly accomplishTask1Step = new AccomplishTask1(this);
public readonly accomplishTask2Step = new AccomplishTask2(this);
public constructor(public readonly service: MyDependencyService = myDependencyService) {}
public getFlowType(): string {
return "UserOnboardingFlow";
}
public getSteps() {
return StepList.startStep(this.submit).otherSteps(
this.verifyEmailStep,
this.accomplishTask1Step,
this.accomplishTask2Step,
);
}
public getPersistenceSchema(): PersistenceSchema {
return {
attributes: [this.form, this.status],
channels: [verifyEmail, task1Completed, task2Completed],
};
}
class AccomplishTask1 implements Step<void> {
public waitFor(context: Context, _input: void): Wait {
this.flow.status.set(context, "waiting_for_task_1");
return Wait.anyOf(Timer.byDuration(VERIFY_TIMER_MS), task1Completed.forOne());
}
public execute(context: Context, _input: void): StepDecision {
const signupForm = this.flow.form.get(context);
if (task1Completed.results(context).length > 0) {
this.flow.service.sendEmail(
signupForm.email,
"complete onboarding task 2",
"task 2 is ready",
);
return goTo(AccomplishTask2, undefined);
}
this.flow.service.sendEmail(
signupForm.email,
"task 1 reminder",
"please complete onboarding task 1",
);
return goTo(AccomplishTask1, undefined);
}
}
Example: examples/typescript/src/products/signup/user-signup-flow.ts
#[derive(Default)]
pub struct UserOnboardingFlow {
submit: Submit,
verify_email: VerifyEmail,
accomplish_task_1: AccomplishTask1,
accomplish_task_2: AccomplishTask2,
}
impl Flow for UserOnboardingFlow {
type StartInput = String;
fn steps(&self) -> StepList<'_, Self::StartInput> {
StepList::start(&self.submit)
.and(&self.verify_email)
.and(&self.accomplish_task_1)
.and(&self.accomplish_task_2)
}
fn persistence(&self) -> PersistenceSchema {
PersistenceSchema::new()
.attribute(&ONBOARDING_STATUS)
.channel(&VERIFY_EMAIL)
.channel(&TASK_1_COMPLETED)
.channel(&TASK_2_COMPLETED)
}
fn rpcs(&self) -> RpcList<Self> {
RpcList::new()
.function_without_input(VERIFY_ONBOARDING, Self::verify)
.function_without_input(ACCOMPLISH_ONBOARDING_TASK_1, Self::accomplish_task_1)
.function_without_input(ACCOMPLISH_ONBOARDING_TASK_2, Self::accomplish_task_2)
}
}
impl Step for AccomplishTask1 {
type Input = String;
fn wait_for(&self, context: &mut Context, _input: Self::Input) -> HandlerResult<Wait> {
ONBOARDING_STATUS.set(context, WAITING_FOR_TASK_1.to_string())?;
Ok(Wait::any_of([
TASK_1_COMPLETED.for_one(),
Timer::by_duration(Duration::from_secs(24)),
]))
}
fn execute(&self, context: &mut Context, email: Self::Input) -> HandlerResult<StepDecision> {
if !TASK_1_COMPLETED.condition_results(context)?.is_empty() {
context.record_event("onboarding-task-2", email.clone())?;
return Ok(StepDecision::go_to(&AccomplishTask2, email));
}
context.record_event("task-1-reminder", email.clone())?;
Ok(StepDecision::go_to(&AccomplishTask1, email))
}
}
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.

