cadence-workflowcadencetemporal-workflow

Which one will suit for complete workflow design Temporal or Cadence


I wanted to design a complete end-to-end workflow orchestration engine.

It has the following requirements

  1. Linear workflow
  2. Parallel workflow - I wanted to execute n no of activities parallelly. After validates the results from all the activities I wanted to proceed to the next state or will fail the workflow
  3. Batch - say I have 30 activities to be completed but I want this to be done in a batch fashion. Like if the window size is 5 then I wanted to execute 5 activities at a time T. After executing all the activities and validates the results will proceed further or fail the workflow.
  4. Loop - wanted to run an activity infinitely until some condition meets
  5. Child Workflow
  6. Polling

Solution

  • All 1-5 are supported easily in Cadence workflow. I am not sure what you mean by Polling. If you can provide more details, I will update this answer to help you.

    Here is the sample to execute activities in Leaner+parallel/batch+loop:

      @Override
      public long calculate(long a, long b, long c) {
        LOGGER.info("workflow start...");
    
        long result = 0;
    
        // Async.invoke takes method reference and activity parameters and returns Promise.
        Promise<Long> ab = Async.function(activities::multiple, a, b);
        Promise<Long> ac = Async.function(activities::multiple, a, c);
        Promise<Long> bc = Async.function(activities::multiple, b, c);
    
        // Promise#get blocks until result is ready.
        this.abPlusAcPlusBc = result = ab.get() + ac.get() + bc.get();
    
        // waiting 30s for a human input to decide the factor N for g(n), based on a*b+a*c+b*c
        // the waiting timer is durable, independent of workers' liveness
        final boolean received = Workflow.await(Duration.ofMinutes(2), () -> this.factorForGn > 1);
        if (!received) {
          this.factorForGn = 10;
        }
    
        long fi_1 = 0; // f(0)
        long fi_2 = 1; // f(1)
        this.currentG = 1; // current g = f(0)*f(0) + f(1)*f(1)
        long i = 2;
    
        for (; i < this.factorForGn; i++) {
          // get next fibonacci number
          long fi = fi_1 + fi_2;
          fi_2 = fi_1;
          fi_1 = fi;
    
          this.currentG += activities.multiple(fi, fi);
        }
    
        result += this.currentG;
        return result;
      }
    

    And this is the sample of using ChildWorkflow.