jool
jool

Reputation: 2301

RavenDB and consistency

I'm new to RavenDB and have spent some time reading up on the details. I'm a bit confused on how the handle the eventual consistency issue.

Let's assume a user of a web page is in the process of creating something. For example a new "case". (i.e. first a POST request is sent and a new document is created in RavenDB). Once created the user get routed back to the overview of cases (i.e. a GET request fetches all cases by querying raven for all case documents). Now from what I can tell there is no way I can make sure the case document that was just created will be included in this query since the index may be stale?

For other users, they are unlikely to care if the case appears at once since they are most likely unaware it was created in the first place so that is fine. But the user that actually created the case is very likely to be very confused if it is missing from the overview of cases. In other words, this is an issue that must be addressed.

How?

Upvotes: 1

Views: 376

Answers (2)

Omir
Omir

Reputation: 320

I usually did something like this:

public IQueryable<Foo> GetAllFoos(bool waitForUpdatedIndex = false)
{
    IRavenQueryable<Foo> ret = _documentSession.Query<Foo>();

    if (waitForUpdatedIndex)
        ret.Customize(q => q.WaitForNonStaleResultsAsOfNow());

    return ret;
}

And then I would pass true for waitForUpdatedIndex if the user has previously added a new item.

Upvotes: 0

Ayende Rahien
Ayende Rahien

Reputation: 22956

You can use WaitForReplicationAfterSaveChanges for this, see: https://ravendb.net/docs/article-page/3.5/http/server/scaling-out/replication/write-assurance

Upvotes: 3

Related Questions