Details on Conflict resolution in Cloud


#1

Our use case depends heavily on fast and frequent updates to counters like properties. Reading the documentation found that in Object Server the conflict resolution is set up via script on the server.

How is it dealt with in Cloud? Also since Counters are not exposed in client APIs how do we deal with counter type properties in cloud which needs frequent changes


#2

The Cloud has the same kind of conflict resolution as described in https://docs.realm.io/platform/customize/conflict-resolution.

Counters as a direct datatype are currently available in Java and .NET, while they have not yet been released for Swift/Objective-C and Javascript, so if you need to support these languages you can instead model a concurrent counter using a RealmList of integers.

In Java it would look something like this:

public class Counter extends RealmObject {
  private RealmList<Integer> counter = new RealmList<>();

  public void add(Integer val) {
    counter.add(val);
  }

  public long value() {
    long sum = 0;
    for (Integer val : counter) {
       sum += val;
    }
    return sum;
  } 
}

This is basically a custom implementation of a CDRT counter (https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type).