Search code examples
hashmicroservicesstatelessrevision-history

How to ensure that the variable was modified from only one side


I've got an application with a lot of stateless microservices, which passes their variable context one to another. I've got a case when I'm starting few chains of services with the same context in parallel and then waiting for them to finish. Each service can modify its variable context, but after all of chains is finished I have to merge their variable contexts and ensure there is no conflicts.

It's illustrated in the examples below: incorrect example correct example

It's possible to solve this problem by storing the whole history of variable modifications, but it's a huge data overhead which I'd like to avoid.

Another solution I see is to find some hashing function, which lets to calculate the hash of modification history by the existing hash and new data, and also lets to check if one history data is prefix of another history data by knowing their hashes only. But I'm unable to find such a function.

I'm looking for any applicable algorithm with has as less data overhead as possible.


Solution

  • What you need are Version clocks, an old idea that can be used to merge paralel data modifications and to detect conflicts.

    It's possible to solve this problem by storing the whole history of variable modifications, but it's a huge data overhead which I'd like to avoid.

    With vector clocks you don't keep the entire history, but a counter for each variable and node (so each variable has a vector of counters).