🐝
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

Was this helpful?

  1. Cache
  2. Typical topics

Hot key

PreviousBig keyNextDistributed lock

Last updated 1 year ago

Was this helpful?

  • Note: All 1-4 bullet points could be used separately.

  • Detect hot key (step2/3)

    • The one showed in the flowchart is a dynamic approach. There are several ways to decide hot keys:

      • Within proxy layer

      • Within client

      • Use redis shipped commands ./redis-cli --hotkeys

  • Randomly hash to multiple nodes instead of only one (step4)

  • Enable local cache for hot keys (step5)

  • Circuit breaker kicks in if detecting cache failure (step6)

  • References:

   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                                                    
   β”‚               β”‚                                                                                    
   β”‚    Client     β”‚                                                                                    
   β”‚               β”‚                                                                                    
   β”‚               β”‚                                                                                    
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                                    
     β”‚    β”‚     β”‚                                                                                       
     β”‚    β”‚     β”‚                                                                                       
     β”‚    β”‚     β”‚                                                               β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚    β”‚     β”‚                                                               β”‚ Configuration center β”‚
     β”‚    β”‚     β”‚    ─ ─ ─ ─ ─ ─ ─ step0. subscribe to hot key changes ─ ─ ─ ─ β–Άβ”‚                      β”‚
     β”‚    β”‚     β”‚   β”‚                                                           β”‚   (e.g. Zookeeper)   β”‚
     β”‚  Step1:  β”‚                                                               β””β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
     β”‚ Requests β”‚   β”‚                                                            β”‚          β–²           
     β”‚ come in  β”‚                                                                β”‚          β”‚           
     β”‚    β”‚     β”‚   β”‚                                                            β”‚          β”‚           
     β”‚    β”‚     β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€Step3. Hot key change is publishedβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚           
     β”‚    β”‚     β”‚   β”‚                                                                       β”‚           
     β”‚    β”‚     β”‚   β”‚                                                                       β”‚           
     β”‚    β”‚     β”‚   β”‚                                                                     Yes           
     β”‚    β”‚     β”‚   β”‚                                                                       β”‚           
     β–Ό    β–Ό     β–Ό   β–Ό                                                                       β”‚           
   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                      β”‚           
   β”‚           App Cluster           β”‚                                                      β”‚           
   β”‚                                 β”‚    step 2:    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”       .─────────.      
   β”‚ β”Œ ─ ─ ─ ┐  β”Œ ─ ─ ─ ┐  β”Œ ─ ─ ─ ┐ β”‚   aggregate   β”‚    Stream processing    β”‚      β•±           β•²     
   β”‚   local      local      local   β”œβ”€β”€β”€to detect ─▢│                         │────▢(Is it hot key)    
   β”‚ β”‚ cache β”‚  β”‚ cache β”‚  β”‚ cache β”‚ β”‚    hot keys   β”‚      (e.g. Flink)       β”‚      `.         ,'     
   β”‚  ─ ─ ─ ─    ─ ─ ─ ─    ─ ─ ─ ─  β”‚               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜        `───────'       
   β”‚     β–²                           β”‚                                                                  
   β”‚ β”Œ ─ ╬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ β”‚                                                                  
   β”‚     β•‘  step 6. circuit breaker  β”‚                                                                  
   β”‚ β”‚   β•‘                         β”‚ β”‚                                                                  
   β”‚  ─ ─║─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─  β”‚                                                                  
   β””β”€β”€β”€β”€β”€β•¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                  
         β•‘          β”‚                  step4. For the same hot key,                                     
         β•‘          β”‚                 randomly map to multiple nodes                                    
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚                        instead of only 1                                          
β”‚ Step5. Cache β”‚    └───────────────┬──────────────────────────────────────┐                            
β”‚hot key withinβ”‚                    β”‚                                      β”‚                            
β”‚ local cache  β”‚                    β”‚                                      β”‚                            
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                 
                         β”‚  β”Œ ─ ─ ─ ─ ─ ─ ─     β”Œ ─ ─ ─ ─ ─ ─ ─    β”Œ ─ ─ ─ ─ ─ ─ ─    β”‚                 
                         β”‚    distributed  β”‚      distributed  β”‚     distributed  β”‚   β”‚                 
                         β”‚  β”‚ cache node A      β”‚ cache node B     β”‚ cache node C     β”‚                 
                         β”‚   ─ ─ ─ ─ ─ ─ ─ β”˜     ─ ─ ─ ─ ─ ─ ─ β”˜    ─ ─ ─ ─ ─ ─ ─ β”˜   β”‚                 
                         β”‚                                                            β”‚                 
                         β”‚                       Cache Cluster                        β”‚                 
                         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
https://juejin.im/post/6844903765733015559