Update a counter in the db via a thread safe manner.