Sometimes you might need to ensure that changes made in the session will be replicated to more than one node of the cluster before the saveChanges returns.
It can be useful if you have some writes that are really important so you want to be sure the stored values will reside on multiple machines. Also it might be necessary to use
when you customize the read balance behavior and need to ensure the next request from the user
will be able to read what he or she just wrote (the next open session might access a different node).
You can ask the server to wait until the replication is caught up with those particular changes.
You can set a timeout (default: 15 seconds).
You can specify whether you want to throw on timeout, which may happen in case of network issues (default: true).
You can specify to how many replicas (nodes) the currently saved write must be replicated, before the saveChanges returns (default: 1).
You can specify whether the saveChanges will return only when the current write was replicated to majority of the nodes (default: false).
The waitForReplicationAfterSaveChanges waits only for replicas which are part of the cluster. It means that external replication destinations are not counted towards the number specified in replicas parameter, since they are not part of the cluster.
The usage of waitForReplicationAfterSaveChanges doesn't involve a distributed transaction (those are not supported since RavenDB 4.0). Even if RavenDB was not able
to write your changes to the number of replicas you specified, the data has been already written to some nodes. You will get an error but data is already there.
This is a powerful feature, but you need to be aware of the possible pitfalls of using it.