Skip to content

A lightweight, Go-based distributed in-memory cache. 15000 QPS with P99 latency under 2 ms.

Notifications You must be signed in to change notification settings

Hymeis/Distributed-Cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Distributed-Cache

A lightweight, Go-based distributed in-memory cache with consistent-hashing sharding, singleflight deduplication, size-bounded LRU, protobuf communication, and read-through replication

Architecture

Client β†’ Group.Add("🐺", "Hymeis")
        └─> Cache.Add("🐺", "Hymeis")
             β”œβ”€ insert into in-memory LRU
             └─ async fan-out to R-1 successors:
                  └─ for each replica in GetReplicas("🐺", R)[1:]:
                       HTTP POST /dcache/<group>/🐺  (SetRequest)

Client β†’ Group.Get("🐺")
        β”œβ”€ LRU hit? ──▢ return "Hymeis"
        └─ cache miss:
            └─ singleflight.Do("🐺", fn):
                └─ pickPeer("🐺") via consistent-hash
                    β”œβ”€ peer? ──▢ peerLoad (HTTP+Protobuf) ──▢ return "Hymeis"
                    └─ local?  ──▢ localLoad:
                         β”œβ”€ GetterFunc β†’ origin data
                         β”œβ”€ Replication() (see Add flow above)
                         └─ return "Hymeis"


wrk2 BenchMark Testing

Sustained a constant 15β€―000 QPS workload with wrk2, observing:

  • Throughput: 14β€―982 req/sec (β‰ˆ15β€―000 target)
  • Mean latency: 0.868β€―ms
  • P50 / P75 / P90: 0.86β€―ms / 1.15β€―ms / 1.44β€―ms
  • P99: 1.94β€―ms (well under 10β€―ms SLO)
  • P99.9 / P99.99: 2.40β€―ms / 2.86β€―ms
  • Max observed: 4.00β€―ms

Next Steps

  • Application side: Maybe make a Leetcode Top K ranking system?

How to run the project

Try

bash run.sh

and check the output shown

About

A lightweight, Go-based distributed in-memory cache. 15000 QPS with P99 latency under 2 ms.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published