Yes, you have a race condition. Instead of triggering the campaign using the API, trigger it from the Marketo side on lead creation.
I trust you are not running this process in response to individual end-user activity, or you're creating a DoS vulnerability.
Thanks a lot for quick answer and confirmation about race condition.
We did have 'Lead Generation' action to trigger a campaign based on some trigger and filter conditions, to begin with. But we had to modify that due to some business requirements.
As mentioned earlier, we have modified the campaign flow to introduce a delay as the first step, when the 'Campaign is Requested' via REST API. Wondering if there are any other ways to address this situation.
Appreciate your feedback and suggestions
But you can't fix race conditions with a delay: this is a fundamental reality of programming. (The sole exception is when you have a guarantee that data is periodically flushed, so if you wait longer than that your data will be committed.)
In order to synchronize the data commit with your outside process, you can fire a webhook notification back into your service, which then calls Request Campaign.
I'm curious about what set of business requirements could lead you to this method instead of a standard, more scalable interaction with Marketo.