You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The issue with transaction is that it could quite easily having write conflict during huge load on updating the same field in a collection.
We currently not retrying if this happens which leads to the failed event being push to the delayed queue for processing later.
A quick small improvement we can do to help the system being more effective is to add a exponential backoff retry on all db transactions and make sure the num of retry is controlled by a config value (3 is a good starting number).
Proposed solution
Implement a generic function transactionWithRetries that wraps mongoDB tx method. Allow a configurable backoff setting and specific error type that wil trigger retry, such as write conflict or connectivity issue.
Our service utilise mongodb transaction in a few places. For example https://github.com/babylonchain/staking-api-service/blob/main/internal/db/stats.go#L70
The issue with transaction is that it could quite easily having write conflict during huge load on updating the same field in a collection.
We currently not retrying if this happens which leads to the failed event being push to the delayed queue for processing later.
A quick small improvement we can do to help the system being more effective is to add a exponential backoff retry on all db transactions and make sure the num of retry is controlled by a config value (3 is a good starting number).
In the babylon-api we already doing it, just not exponentially. So maybe you can use some of the code from there, but just make sure we make it exponentially this time. https://github.com/babylonchain/babylon-api/blob/dev/internal/store/dbclient/common.go#L22
The text was updated successfully, but these errors were encountered: