RequestOptions.SessionToken Property

Definition

Gets or sets the token for use with session consistency in the Azure DocumentDB database service.

public string SessionToken { get; set; }
Property Value

The token for use with session consistency.

Remarks

One of the ConsistencyLevel for Azure DocumentDB is Session. In fact, this is the deault level applied to accounts.

When working with Session consistency, each new write request to Azure DocumentDB is assigned a new SessionToken. The DocumentClient will use this token internally with each read/query request to ensure that the set consistency level is maintained.

         <p>
         In some scenarios you need to manage this Session yourself; 
         Consider a web application with multiple nodes, each node will have its own instance of <xref href="Microsoft.Azure.Documents.Client.DocumentClient"></xref>
         If you wanted these nodes to participate in the same session (to be able read your own writes consistently across web tiers) 
         you would have to send the SessionToken from <xref href="Microsoft.Azure.Documents.Client.ResourceResponse`1"></xref> of the write action on one node
         to the client tier, using a cookie or some other mechanism, and have that token flow back to the web tier for subsequent reads.
         If you are using a round-robin load balancer which does not maintain session affinity between requests, such as the Azure Load Balancer,  
         the read could potentially land on a different node to the write request, where the session was created. 
         </p><p>
         If you do not flow the Azure DocumentDB SessionToken across as described above you could end up with inconsistent read results for a period of time.
         </p></p>