NikaN
Convex Community3y ago
15 replies
Nika

OptimisticConcurrencyControlFailure on Event Handlers

My backend service is subscribed to blockchain events and whenever there's an event, it inserts the row in the Convex database.

There're times when lots of events happen at once, and that's where the Convex is having OptimisticConcurrencyControlFailure problems (VIEW THE PHOTO).

The function which handles the event is very simple:

0) We query a table in convex to get a specific row.
_id
from this queried row will be used for the insert later.
1) we call mutation on convex client with the convex public function
2) Inside the public function we check if there's already an existing row with a specific column value,
3) If it is, we throw an error
4) If not, we insert the row.

Data read or written in this mutation changed while it was being run. Consider reducing the amount of data read by using indexed queries with selective index range expressions

Each event handler requires at least 2 queries. So I guess that's what causing the error considering the error message above about "amount of data read".

Do you have any work-around ideas?
image.webp
Was this page helpful?