How to control total executions of workflow

I’m using go-sdk to trigger a workflow using SignalWithStartWorkflow(). The signal is sent to this via a temporal client which sends signal whenever there is a message in the kafka topic. Now i want to control the executions, basically i want to stop this trigger after certain number of executions irrespective whether there are events flowing in the kafka topic or not. Is there some config which can control this or any other way to do this ?

Do you have a long running workflow which will process all the signals? Or when your workflow receives the signal, does it process the signal and then finishing executing, so that a second signal will start another workflow? Does each signal start a new workflow with a different workflow id?

Hi, yes each signal start a new workflow with a different workflowId. Here workflowId is basically the userId so if I receive the same event for the same user until the current is not complete than that signal is discarded else it starts a new run. This happens for all such userIds

Do you want to stop execution after a certain number of executions of the same userid, or across all userid’s?

I want to stop across all UserIds

I can think of a few different options:

Have a single, long running, coordination workflow. Deliver the signals to the coordination workflow. The coordination workflow would send them on to the execution workflow based on userid; and it could stop sending when you’ve reached your desired maximum number of messages. Likely the coordination workflow would need to use continue-as-new. Note however that while Temporal supports millions of concurrent workflows, any one particular workflow execution can only handle a limited number of events per second. So this might not work for you if your signal rate is too high.

Alternatively, in your Kafka consumer / Temporal client, use an external database to count the number of signals sent. Stop sending signals when you’ve reached your desired maximum.

Or, write a Kafka Streams application to copy messages from your Kafka event topic to a signal topic. Stop copying messages to the signal topic when you’ve reached your desired maximum number of signals. Have your Temporal client consume the signal topic.

Thanks for the replies, that helps.