We are using Laravel with webhook heavily.
We are getting about 10 requests / second via webhook and some services are sending the multiple same request at the same time via webhook. We need to save only 1 entry for the same request. (service_id, param)
We are getting duplicate entry issue in the following logic:
$model = MyModel::where("service_id", $request->service_id)->where("param", $request->param)->first();
if($model)
{
//update model
}else {
//create new model
}
When I check service_id
and param
in MyModel, there are a lot of duplication entries.
I think while one is being created, the other same request can query and create new one.
Can anyone help me how to solve this issue? I think we can use Queue so that we can handle syncronously but Queue is not our option for now.