Could a subscription action create an entity twice?

Can the following code create 2 workflows?

class UserJournalAction {
  override def onCreate(...): Action.Effect[Empty] = {
    val createRequest = Create.of(...)
    val reply = components.workflow.create(createRequest).execute()
    effects.asyncReply(reply)
  }
}

The protobuf for the subscription would be …

service UserJournal {
  option (kalix.codegen).action = {};

  rpc OnCreate(...) returns (google.protobuf.Empty) {
    option (kalix.method).eventing.in.event_sourced_entity = "users";
  }
}

… and the protobuf for the workflow (it could be an entity as well) would be …

service Workflow {
  option (kalix.codegen).workflow = { ... }
  
  rpc Create(...) returns (google.protobuf.Empty) {
    option (kalix.method).id_generator.algorithm = VERSION_4_UUID;
  }
}

I can’t figure out from the docs whether the action can process an event twice (even if the first event was successful). Or whether committing the event as processed and the creation of the workflow is atomic.

If the answer is “yes”, then the utility of the id generation is drastically reduced :smiley:

option (kalix.method).id_generator.algorithm = VERSION_4_UUID;

Thanks.

Yes, it could potentially.

All eventing in streams are at-least-once, normally events are processed just once but there are failure scenarios where an event could be redelivered.

To make it water tight the command it triggers would have to be idempotent, for example using an id for the workflow that is derived from the event, for example uses the entity id that produced the event.

That’s what I thought. Thanks @johanandren