Update view count synchronously is not a good idea, especially when using RDBMS database.
update vacancy_view set
count = count + 1
where vacancy_id = $id
The row may get blocked if a lot of users view same vacancy within a short period of time.
I'd suggest use "inserting" instead. The inserting could be synchronous or asynchronous, depends on benchmark. But this implementation details could be hidden behind the applicationEvents abstraction. The view count could be sum up whenever it is requested or cached, in this use case, eventual consistency is usually tolerated.
class VacancyController {
public function viewVacancy($vacancyId) {
$vacancy = $this->repo->find($vacancyId);
$this->applicationEvents->raise(VacancyViewedEvent($vacancyId))
return $vacancy;
}
}
It is said some nosql databases(such as Cassandra) fit well in view counting scenario, but I don't have experience with that yet.