Implement Optimistic Concurrency Control in Golang for all entities

187 views Asked by At

I am trying to implement Optimistic concurrency control(OCC) in my golang microservice. I have 4 entities and I want to have OCC for all of them.

For this I am planning to use a column in each entity called version. Every table will have this column. I am planning to ask clients of my API to send a version field in the Update request and the update will be successful only if the version in the request matches with the version in DB. This is OCC in its most plain form.

What I am want to do now is have this logic at a single place in an extensible fashion. So that if all the entities and new entities can resuse the same function/method for implementing OCC. I just want to separate the logic of version checking and update at the separate place, There will be an Update method for all the entities where they can choose to update the individual rows separately but the logic of version checking and update should be in a common place. Again i want to implement this in golang.

I am also open to use any library if available. But due to legacy reason I can't use any orm. The library must provide OCC without any changes in how the existing queries are implemented.

I know it's kind of a vague ask but I just want to make sure that I explore all possibilities there are to explore.

0

There are 0 answers