<p>How to implement memory state/session replications with K8S? For instance, a web shopping cart system replicates the user HTTP sessions among cluster nodes over the network so that if a node is down, a process in another node can take over the user sessions.</p>
<p>K8S has StatefulSet which uses the disk storages to assure the state persistency, I think. If a pod is down, the restarted pod takes over the state form the disk. However, the overhead of persisting in-memory user sessions to disk is high and may not be fast enough.</p>
<p>I suppose the solution could be using memory cache server or etcd like systems. Is it the established practice? In my understanding, K8S is good for stateless processing in scale, and StatefulSet had been introduced to address stateful situation but not sure it is good fit for situation where fast stateful handover is required.</p>
<p>Please advise.</p>

<blockquote>
<p>How to implement memory state/session replications with K8S? For
instance, a web shopping cart system replicates the user HTTP sessions
among cluster nodes over the network so that if a node is down, a
process in another node can take over the user sessions.</p>
</blockquote>
<p>To store the state it's best to use the Redis or in-memory database.</p>
<blockquote>
<p>K8S has StatefulSet which uses the disk storages to assure the state
persistency, I think. If a pod is down, the restarted pod takes over
the state form the disk. However, the overhead of persisting in-memory
user sessions to disk is high and may not be fast enough.</p>
</blockquote>
<p>You are right but maybe you have not tried it before, i been using the Redis for Production in K8s with million of users but never faced issues. Redis has two options for backup the keys if you deploy on K8s.</p>
<p><strong>RDB</strong> and Append <strong>only-AOF</strong>, till now never faced <strong>Redis</strong> crashed or so, but only get crashed due to <strong>Out of Memory</strong>, so make sure your <strong>Key policy</strong> is set properly like <strong>LRU</strong> or so.</p>
<blockquote>
<p>In my understanding, K8S is good for stateless processing in scale</p>
</blockquote>
<p>You are right but people have been using the Deployment and Statefulsets for running Redis cluster and Elasticsearch clusters in K8s also with all backup and scaling options.</p>
<p>It's easy to configure &amp; manage the <strong>DB</strong> with K8s while with <strong>VM</strong> not much scalability there.</p>
<p>We have been running stateful sets with <strong>Redis</strong>, <strong>Elasticsearch</strong>, <strong>RabbitMQ</strong> since long in <strong>Prod</strong> and have not seen many issues. Make sure you attach the SSD high IOPS disk to POD and you are good to go.</p>
<p>Nice example : <a href="https://github.com/loopbackio/loopback4-example-shopping/blob/master/kubernetes/README.md" rel="nofollow noreferrer">https://github.com/loopbackio/loopback4-example-shopping/blob/master/kubernetes/README.md</a></p>
