Search code examples
riak

How to handle stale reads in Riak for things like sessions in the face of network partition


If one is storing sessions in Riak, there is a possibility of a read being stale.

Isn't this bad? For example, session data. User logs out and then refreshes the page and they are still shown as logged in.

Also, if there is a network partition or something making a node unresponsive (excessive I/O or CPU usage), then the user could log out which destroys the session but if a subsequent read happens on the other side of the nodes they are still going to be logged in because on that side the session hasn't been destroyed. What is the answer?


Solution

  • With an eventually consistent datastore like Riak there is a risk of stale reads under some conditions however in most environments this is offset by Riak's availability profile (where stale reads are better than no reads or an inability to write).

    Riak does have some features that can help you with session storage like expiry (when using BitCask or In Memory backends) and the Riak documents have some examples and links to real world session store use cases built on Riak that are worth a look: http://docs.basho.com/riak/latest/dev/data-modeling/.