0
0
HLDsystem_design~12 mins

Sticky sessions in HLD - Architecture Diagram

Choose your learning style9 modes available
System Overview - Sticky sessions

This system manages user sessions by ensuring that once a user connects to a specific server, all their subsequent requests go to the same server. This is called sticky sessions. It helps maintain user state without sharing session data across servers.

Key requirements include session persistence, load balancing, and fault tolerance.

Architecture Diagram
User
  |
  v
Load Balancer (with sticky sessions)
  |
  +-------------------+-------------------+
  |                   |                   |
App Server 1       App Server 2       App Server 3
  |                   |                   |
Database (shared by all servers)
  |
Cache (optional for session data)
Components
User
client
Initiates requests to the system
Load Balancer (with sticky sessions)
load_balancer
Distributes user requests to the same app server based on session info
App Server 1
service
Handles user requests and maintains session state
App Server 2
service
Handles user requests and maintains session state
App Server 3
service
Handles user requests and maintains session state
Database
database
Stores persistent data shared by all app servers
Cache
cache
Optionally stores session data for faster access
Request Flow - 10 Hops
UserLoad Balancer (with sticky sessions)
Load Balancer (with sticky sessions)App Server 2
App Server 2Database
App Server 2Load Balancer (with sticky sessions)
Load Balancer (with sticky sessions)User
UserLoad Balancer (with sticky sessions)
Load Balancer (with sticky sessions)App Server 2
App Server 2Database
App Server 2Load Balancer (with sticky sessions)
Load Balancer (with sticky sessions)User
Failure Scenario
Component Fails:App Server 2
Impact:Users assigned to App Server 2 lose session state and cannot be served until reassigned
Mitigation:Load balancer detects failure and reassigns users to other servers; session data can be stored in shared cache or database to restore state
Architecture Quiz - 3 Questions
Test your understanding
What component ensures that a user’s requests go to the same server?
ACache
BLoad Balancer with sticky sessions
CDatabase
DUser client
Design Principle
Sticky sessions use the load balancer to keep user requests on the same server, simplifying session management by avoiding distributed session storage. However, this creates a dependency on the load balancer and app servers, so shared storage or cache is recommended for fault tolerance.