V9 brought us support for containers and a microservices architecture, and this completely changed how environments are deployed. In this post, I will discuss the development team's views on the role of session affinity with the new architecture.
First, a recap: session affinity (aka sticky sessions) means that all requests during a session should land on the same server. In V7/V8, where affinity is mandatory, it is achieved thru the use of the JSESSIONID session cookie. When a shopper issues a first request, the server that it lands to (using round robin or random assignment) generates the JSESSIONID cookie. For subsequent requests, the WAS IHS Plug-in matches the cookie to a server and redirects the request. In installations with multiple clusters or data centers, you also need to setup cluster affinity.
In pre-V9 environments the use of affinity is primarily for performance. WC implements a number of user and session caches and these Data Cache caches live in the JVMs (but can also be configured in WXS), and by having all of a user's requests on the same server, the cache hit ratios (usage of cache) increases improving performance. Also, in V7/V8 invalidations are typically configured to flow across servers using DRS (the Search servers use the CACHEIVL table only) and when affinity is used, subsequent requests won't run into timing issues where the invalidation hasn't arrived from a different server.
Although affinity works well (and it is required) pre-V9 versions, it's not such a clear fit for V9. There are a number of reasons for this. For starters, containers are much more dynamic in nature. With an orchestration framework such as Kubernetes, environments scale up and down as needed, and you can't assume a container will remain active for the length of a session (the same is true pre-V9 but not as much). As we are following a microservices deployment model and stateless architecture design, all the services should be stateless and ready to service any clients.
Also, as WC changes from a single monolithic application into a collection of microservices, the concept of affinity becomes convoluted. Do you only need affinity from browser to store? What about affinity to all the other microservices Tx/Search/Xc, etc? It's also worth mentioning that affinity is not enabled out-of-the-box as it used to be with WAS and the IHS plug-in. It is still possible to configure it, but the process is not straightforward. You would need to configure a nginx or HAProxy ingress controller with a cookie or IP based technique (many clients don't consume cookies).
As we cannot make assumptions for which container will handle subsequent requests, V9 is designed, developed and tuned without expecting affinity to be present, and therefore there is no need to configure it.
If you need affinity due to custom requirements or legacy code, you are free to configure it, but I strongly recommend that all new code and configurations are done without the assumption of affinity, to help achieve a more robust and scalable implementation. The following are some of the considerations to follow:
- Code synchronizations at the JVM level (Java locks) will not be effective as requests can land on different servers. If you are using Java locks to protect a service, you need a different solution.
- For volatile user and session caches, consider the impact of invalidations. Kafka needs a few milliseconds to replicate and this could lead to the use of stale data. This is particularly evident on modern implementations (e.g. single-page applications / SPA with AngularJS), that span multiple concurrent requests that land on different servers. You need to be particularly mindful of requests that change data other requests depend on, and you might need to serialize certain requests to avoid this scenario.
- Don't implement in-memory databases to store temporary data, such to collect browsing or checkout data. Use a shared service instead.
In addition to these, for a good architecture, follow all the best practices for Cloud deployments, even if you are not on cloud yet ! including the ones for the use of ephemeral storage.
Finally, and for full disclosure, I am aware of certain marketing features that became unavailable since the drop of affinity. You can find more info in the Knowledge Center: Marketing Tool - Limitations.