.NET Architecture & System Design Interview Question #18
What is session affinity or sticky sessions?
Architecture Fundamentals, Scalability, Availability & Performance Junior Beginner
Quick Interview Answer
Session affinity routes a client's subsequent requests to the same server instance, often because that instance holds local session state.
Detailed Explanation
Session affinity routes a client's subsequent requests to the same server instance, often because that instance holds local session state.
Sticky sessions can be useful in some systems, but they reduce routing flexibility and can complicate failover and load distribution. For many web applications, externalizing required session state allows instances to remain more interchangeable.
Code Example
Client A -> App 1 -> App 1 -> App 1
Client B -> App 2 -> App 2
This is session affinity.