🐝
Mess around software system design
  • README
  • ArchitectureTradeOffAnalysis
    • Estimation
    • Middleware
    • Network
    • Server
    • Storage
  • Conversion cheat sheet
  • Scenarios
    • TinyURL
      • Estimation
      • Flowchart
      • Shortening mechanisms
      • Rest API
      • Performance
      • Storage
      • Follow-up
    • TaskScheduler
      • JDK delay queue
      • Timer based
      • RabbitMQ based
      • Kafka-based fixed delay time
      • Redis-based customized delay time
      • MySQL-based customized delay time
      • Timer TimingWheel
      • Industrial Scheduler
      • Workflow Engine
      • Airflow Arch
    • GoogleDrive
      • Estimation
      • Flowchart
      • Storage
      • Follow-up
    • Youtube
      • Estimation
      • Flowchart
      • Performance
      • Storage
      • Follow-up
      • Netflix
    • Uber
      • Estimation
      • Rest api
      • Flowchart
      • KNN algorithms
      • Geohash-based KNN mechanism
      • Redis implementation
      • Storage
    • Twitter
      • Estimation
      • Flowchart
      • Storage
      • Scalability
      • Follow-up
    • Instant messenger
      • Architecture overview
      • Presence
      • Unread count
      • Notifications
      • Read receipt
      • Large group chat
      • Storage-Offline 1:1 Chat
      • Storage-Offline group chat
      • Storage-Message roaming
      • NonFunc-Realtime
      • NonFunc-Reliability
      • NonFunc-Ordering
      • NonFunc-Security
      • Livecast-LinkedIn
    • Distributed Lock
      • Single machine
      • AP model based
      • CP model based
      • Chubby-TODO
    • Payment system
      • Resilience
      • Consistency
      • Flash sale
    • Key value store
      • Master-slave KV
      • Peer-to-peer KV
      • Distributed cache
  • Time series scenarios
    • Observability
      • TimeSeries data
      • Distributed traces
      • Logs
      • Metrics
      • NonFunc requirments
  • Search engine
    • Typeahead
    • Search engine
    • Distributed crawler
      • Estimation
      • Flowchart
      • Efficiency
      • Robustness
      • Performance
      • Storage
      • Standalone implementation
      • Python Scrapy framework
    • Stream search
  • Big data
    • GFS/HDFS
      • Data flow
      • High availability
      • Consistency
    • Map reduce
    • Big table/Hbase
    • Haystack
    • TopK
    • Stateful stream
    • Lambda architecture
    • storm架构
    • Beam架构
    • Comparing stream frameworks
    • Instagram-[TODO]
  • MicroSvcs
    • Service Registry
      • Flowchart
      • Data model
      • High availability
      • Comparison
      • Implementation
    • Service governance
      • Load balancing
      • Circuit breaker
      • Bulkhead
      • Downgrade
      • Timeout
      • API gateway
      • RateLimiter
        • Config
        • Algorithm comparison
        • Sliding window
        • Industrial impl
    • MicroSvcs_ConfigCenter-[TODO]
    • MicroSvcs_Security
      • Authentication
      • Authorization
      • Privacy
  • Cache
    • Typical topics
      • Expiration algorithm
      • Access patterns
      • Cache penetration
      • Big key
      • Hot key
      • Distributed lock
      • Data consistency
      • High availability
    • Cache_Redis
      • Data structure
      • ACID
      • Performance
      • Availability
      • Cluster
      • Applications
    • Cache_Memcached
  • Message queue
    • Overview
    • Kafka
      • Ordering
      • At least once
      • Message backlog
      • Consumer idempotency
      • High performance
      • Internal leader election
    • MySQL-based msg queue
    • Other msg queues
      • ActiveMQ-TODO
      • RabbitMQ-TODO
      • RocketMQ-TODO
      • Comparison between MQ
  • Traditional DB
    • Index data structure
    • Index categories
    • Lock
    • MVCC
    • Redo & Undo logs
    • Binlog
    • Schema design
    • DB optimization
    • Distributed transactions
    • High availability
    • Scalability
    • DB migration
    • Partition
    • Sharding
      • Sharding strategies
      • Sharding ID generator overview
        • Auto-increment key
        • UUID
        • Snowflake
        • Implement example
      • Cross-shard pagination queries
      • Non-shard key queries
      • Capacity planning
  • Non-Traditional DB
    • NoSQL overview
    • Rum guess
    • Data structure
    • MySQL based key value
    • KeyValueStore
    • ObjectStore
    • ElasticSearch
    • TableStore-[TODO]
    • Time series DB
    • DistributedAcidDatabase-[TODO]
  • Java basics
    • IO
    • Exception handling
  • Java concurrency
    • Overview
      • Synchronized
      • Reentrant lock
      • Concurrent collections
      • CAS
      • Others
    • Codes
      • ThreadLocal
      • ThreadPool
      • ThreadLifeCycle
      • SingletonPattern
      • Future
      • BlockingQueue
      • Counter
      • ConcurrentHashmap
      • DelayedQueue
  • Java JVM
    • Overview
    • Dynamic proxy
    • Class loading
    • Garbage collection
    • Visibility
  • Server
    • Nginx-[TODO]
  • Distributed system theories
    • Elementary school with CAP
    • Consistency
      • Eventual with Gossip
      • Strong with Raft
      • Tunable with Quorum
      • Fault tolerant with BFT-TODO
      • AutoMerge with CRDT
    • Time in distributed system
      • Logical time
      • Physical time
    • DDIA_Studying-[TODO]
  • Protocols
    • ApiDesign
      • REST
      • RPC
    • Websockets
    • Serialization
      • Thrift
      • Avro
    • HTTP
    • HTTPS
    • Netty-TODO
  • Statistical data structure
    • BloomFilter
    • HyperLoglog
    • CountMinSketch
  • DevOps
    • Container_Docker
    • Container_Kubernetes-[TODO]
  • Network components
    • CDN
    • DNS
    • Load balancer
    • Reverse proxy
    • 云中网络-TODO
  • Templates
    • interviewRecord
  • TODO
    • RecommendationSystem-[TODO]
    • SessionServer-[TODO]
    • Disk
    • Unix philosophy and Kafka
    • Bitcoin
    • Design pattern
      • StateMachine
      • Factory
    • Akka
    • GoogleDoc
      • CRDT
Powered by GitBook
On this page
  • Session Server
  • Problme
  • Possible approaches
  • Architecture

Was this helpful?

  1. TODO

SessionServer-[TODO]

PreviousRecommendationSystem-[TODO]NextDisk

Last updated 3 years ago

Was this helpful?

Session Server

Problme

Possible approaches

Replicate session across servers

  • Def: Copy session data across multiple servers. Built-in support by servers such as Tomcat.

  • Cons:

    • Not scalable: When there is a large number of servers N, each time needs to replicate to the rest N-1 machines. Will take a lot of intranet bandwidth.

    • Limit by single machine memory: Server session is stored inside memory and will be limited to the memory capacity of a single machine.

Store session data in cookie

  • Def: Store session in client cookie

  • Cons:

    • All client to server traffic needs to come with cookie. If the size of cookie is big, then high consumption on network bandwidth.

    • Session data size will be limited to cookie size (usually 4K limit)

Sticky session

  • Def: Change the load balancer strategy to guarantee that the request from the same client always land on the same server. For example, Nginx supports load balancing strategy based on IP hash, userId, loginId, etc.

  • Cons:

    • Uneven traffic. There will be cases when all machines within a company share a single external Ip address. Relying on sticky session based routing will result in uneven traffic distribution.

    • Tight Coupling between application and load balancing: When the number of server increases, the configuration on Nginx also needs to be changed.

    • Bad user experience: Lose session data if tomcat server restarts. The user needs to sign in again.

Shared storage

  • Def: Store data in a shared storage such as Redis

  • Example:

    • Redis

    • Microsoft implementation: ASP.NET State Server Protocol

  • Pros:

    • When server restarts / scales horizontally, no loss of session data

  • Cons:

    • An additional call to Redis upon each request

Architecture

  • Problems

    • where to store SessionId and SessionServer mapping?

    • What if session server dies

    • Upgrade and scale

    • Service discovery

Sesssion server internal design

How to design a high performant memory based LRU cache

  • Thread unsafe LRU Cache

  • Thread safe LRU Cache

  • Thread safe and high performant LRU cache

    • segment lock - Determine the number of segment numbers

    • OkCache: An implementation already on github

  • Industrial implementation

    • Guava Cache

    • Caffenine

      • Window TinyLFU

      • High concurrent RingBuffer

How to design a high-performant large volume persistent ConcurrentHashmap

  • BigCache

  • Store all sessionId to memory. Session value could be persistent to disk

    • SessioId: Fixed length 8B

    • SessionValue: On average 10KB

  • Industrial implementation

    • Yahoo HaloDB

Reference:

In Chinese 四种Session方式
Session Server
Problme
Possible approaches
Replicate session across servers
Store session data in cookie
Sticky session
Shared storage
Architecture
Sesssion server internal design
How to design a high performant memory based LRU cache
How to design a high-performant large volume persistent ConcurrentHashmap
Problem
replicate session across
cookie session
sticky session
shared storage