I have a use case in which I have two workflows. workflow 2 is dependent on workflow 1 completion means workflow 2 can only starts if workflow 1 is completed. Both workflow starts from kafka event. Workflow 1 max txn per second can be as high as 500. bit it is not 1 to 1 mapping with workflow 2 which can just 1% of workflow 1. How can I achieve this? One option 1 is signal await, is it scalable at this scale in terms of cost and resources. Another option is global variable check by workflow 2 and start when this variable is set to true. Please suggest. It is in java
Have you considered having just 1 workflow. It will receive both events and execute the logic accordingly?
Hi Maxim. actual these events can come in any order and workflow 2 may or may not happen but workflow 1 will always be there . Hence I think this approach wont work
It should work fine.
The workflow execute “sequence 1” when the event 1 is received. If event 2 is received when the sequence 1 is running then the “sequence 2” is executed after the “sequence 1” is done.
If event 2 is received first then workflow waits for event 1 before executing anything.
Something like:
@WorkflowInterface
public interface OneThenTwo {
@WorkflowMethod
void run();
@SignalMethod
void one(Input1 arg);
@SignalMethod
void two(Input2 arg);
}
public class OneThenTwoWorkflowImpl implements OneThenTwo {
private Input1 input1;
private Input2 input2;
@Override
public void run() {
Workflow.await(()->input1 != null);
executeSequence1(input1);
if (input2 != null) {
executeSequence2(input2);
}
}
@Override
public void one(Input1 arg) {
input1 = arg;
}
@Override
public void two(Input2 arg) {
input2 = arg;
}
private void executeSequence1(Input1 input1) {
// whatever
}
private void executeSequence2(Input2 input2) {
// whatever
}
}
Thanks Maxim. do you see any issue with signal and await at high tps i.e. 500 txn per sec
Temporal scales out linearly with the number of workflows. Ensure your cluster is provisioned correctly (or use Temporal cloud) and your workers can process the load.
Yes, we are on the cloud already. still wanted to confirm in terms of cost, resource etc
Follow up question: what is the behavior if workflow one doesn’t exist yet? Workflow two await will still await? Cases like event 1 and event 2 might be out-of-order (which could be rate, but could happen). Also, if event1 and event2 are same workflow type, how to make the workflow implementation generic so that only workflow two needs to wait and workflow one doesn’t?
This is not a high load for the cloud. File a ticket at support.temporal.io to get help with the cost estimate.
Use SignalWithStart to send both signals. This would start workflow if not running for any of them.
The implementation I posted works fine if signals are received in any order. Note that it creates a single workflow that processes both signals, not two workflows.