[{"data":1,"prerenderedAt":485},["ShallowReactive",2],{"project-cachedist":3},{"id":4,"title":5,"body":6,"description":119,"extension":465,"meta":466,"navigation":480,"path":481,"seo":482,"stem":483,"__hash__":484},"content\u002Fprojects\u002Fcachedist.md","CacheDist",{"type":7,"value":8,"toc":449},"minimark",[9,14,55,59,69,89,93,100,106,110,120,175,179,256,260,295,299,302,307,335,340,344,388,392,411,415],[10,11,13],"h2",{"id":12},"project-at-a-glance","Project at a Glance",[15,16,17,25,43,49],"ul",{},[18,19,20,24],"li",{},[21,22,23],"strong",{},"Problem:"," Understanding how production distributed caches like Redis handle concurrency, horizontal key distribution, memory eviction, replication, and node failures requires going beyond using them as black-box dependencies.",[18,26,27,30,31,34,35,38,39,42],{},[21,28,29],{},"Deliverables:"," A distributed in-memory key-value cache engine built from scratch in ",[21,32,33],{},"Go 1.22+",", featuring 256-shard concurrent storage, consistent hashing with virtual nodes, O(1) LRU eviction, lazy + active TTL expiration, synchronous ",[21,36,37],{},"gRPC + Protobuf"," replication with write quorum, heartbeat health checks with auto-recovery, a Client SDK, HTTP\u002FJSON API, CLI, and ",[21,40,41],{},"Prometheus + Grafana"," observability running in a 3-node Docker Compose cluster.",[18,44,45,48],{},[21,46,47],{},"Core Stack:"," Go 1.22+, gRPC, Protobuf, HTTP\u002FJSON, Prometheus, Grafana, Docker \u002F Docker Compose.",[18,50,51,54],{},[21,52,53],{},"Practical Value:"," Built solo in 2026 as an open-source systems engineering study (explicitly scoped as a learning\u002Fportfolio project rather than production-ready software), validated with Go microbenchmarks, a 100,000-operation 3-node distributed load test, and a live node-failure chaos test.",[10,56,58],{"id":57},"project-overview","Project Overview",[60,61,62,64,65,68],"p",{},[21,63,5],{}," is a distributed in-memory key-value cache built from scratch in ",[21,66,67],{},"Go",", inspired by Redis internals. Its primary goal is hands-on mastery of core distributed systems primitives: partitioning keys across nodes without global reshuffling, eliminating single-mutex lock contention under parallel load, enforcing synchronous write durability via quorum, and recovering automatically when a cluster node drops offline.",[60,70,71,72,76,77,80,81,84,85,88],{},"The repository includes a multi-node cache server (",[73,74,75],"code",{},"cmd\u002Fserver","), a manual testing CLI (",[73,78,79],{},"cmd\u002Fcli","), a consistent-hashing Client SDK (",[73,82,83],{},"sdk\u002F","), Protobuf definitions (",[73,86,87],{},"proto\u002F","), and a ready-to-run 3-node Docker Compose stack bundled with Prometheus scraping and a pre-configured Grafana dashboard.",[10,90,92],{"id":91},"interface-specimen","Interface Specimen",[60,94,95],{},[96,97],"img",{"alt":98,"src":99},"CacheDist real-time Grafana monitoring dashboard showing cache hits, throughput, and metrics across 3 nodes during load testing","\u002Fimg\u002Fportfolio\u002Fcachedist-grafana.png",[60,101,102],{},[103,104,105],"em",{},"Pre-configured Grafana Dashboard: Real-time observability tracking cache hits, latency histograms, eviction counts, and memory usage across the 3-node cluster during distributed load testing.",[10,107,109],{"id":108},"system-architecture","System Architecture",[111,112,117],"pre",{"className":113,"code":115,"language":116},[114],"language-text","+-----------------------------------------------------+\n|                   CLIENT APP                        |\n+--------------------------+--------------------------+\n                           |\n                           v\n+-----------------------------------------------------+\n|              CACHE CLIENT SDK                       |\n|         Consistent Hash Ring Routing                |\n+----------+---------------+---------------+----------+\n           |               |               |\n           v               v               v\n     +-----------+   +-----------+   +-----------+\n     |   NodeA   |   |   NodeB   |   |   NodeC   |\n     |   :7001   |\u003C->|   :7002   |\u003C->|   :7003   |\n     | 256 shards|   | 256 shards|   | 256 shards|\n     +-----------+   +-----------+   +-----------+\n           ^               ^               ^\n           +---------------+---------------+\n             gRPC inter-node (port 800x)\n","text",[73,118,115],{"__ignoreMap":119},"",[15,121,122,154,163],{},[18,123,124,131,132,135,136,135,139,135,142,145,146,149,150,153],{},[21,125,126,127,130],{},"HTTP\u002FJSON Client API (",[73,128,129],{},":700x","):"," Exposes ",[73,133,134],{},"\u002Fget",", ",[73,137,138],{},"\u002Fset",[73,140,141],{},"\u002Fdelete",[73,143,144],{},"\u002Fstats",", and ",[73,147,148],{},"\u002Fmetrics"," for direct integration, ",[73,151,152],{},"curl"," inspection, and Prometheus scraping.",[18,155,156,162],{},[21,157,158,159,130],{},"gRPC + Protobuf Inter-Node Mesh (",[73,160,161],{},":800x"," Handles low-overhead binary RPCs for synchronous write replication and peer-to-peer cluster coordination.",[18,164,165,174],{},[21,166,167,168,171,172,130],{},"Consistent Hash Ring (",[73,169,170],{},"internal\u002Fcluster"," & ",[73,173,83],{}," Maps keys to nodes using FNV-1a hashing with virtual nodes so adding or removing a node only relocates a minimal subset of the keyspace.",[10,176,178],{"id":177},"core-storage-concurrency-engine","Core Storage & Concurrency Engine",[180,181,182,210,235],"ol",{},[18,183,184,190],{},[21,185,186,187,130],{},"256-Shard Parallel Storage (",[73,188,189],{},"internal\u002Fcache",[15,191,192,195],{},[18,193,194],{},"Early iterations with a single global mutex suffered from severe lock contention under concurrent goroutines.",[18,196,197,198,201,202,205,206,209],{},"Partitioning each node into ",[21,199,200],{},"256 internal shards"," (",[73,203,204],{},"h % numShards","), each guarded by its own ",[73,207,208],{},"sync.RWMutex",", allows concurrent reads and writes across different shards to execute in parallel without blocking one another.",[18,211,212,215],{},[21,213,214],{},"O(1) LRU Eviction:",[15,216,217,220],{},[18,218,219],{},"Implemented with a custom doubly linked list paired with a hashmap.",[18,221,222,223,226,227,230,231,234],{},"Every ",[73,224,225],{},"GET"," promotes the accessed entry to the ",[73,228,229],{},"HEAD",", while capacity overflow evicts directly from the ",[73,232,233],{},"TAIL"," in constant time.",[18,236,237,240],{},[21,238,239],{},"Dual-Strategy TTL Expiration:",[15,241,242],{},[18,243,244,245,248,249,251,252,255],{},"Supports per-key time-to-live (in seconds) using both ",[21,246,247],{},"lazy deletion"," on ",[73,250,225],{}," reads and an ",[21,253,254],{},"active background cleanup goroutine"," to reclaim expired keys even if never read again.",[10,257,259],{"id":258},"replication-quorum-fault-tolerance","Replication, Quorum & Fault Tolerance",[15,261,262,276,286],{},[18,263,264,267,268,271,272,275],{},[21,265,266],{},"Synchronous gRPC Replication & Write Quorum:"," Writes are synchronously replicated across peers (replication factor: ",[73,269,270],{},"2",") before returning an acknowledgement to the client. A write succeeds only when ",[73,273,274],{},"ceil(replication_factor \u002F 2) + 1"," nodes confirm (with replication factor 2, both primary and replica must ACK).",[18,277,278,281,282,285],{},[21,279,280],{},"Health Checks & Auto-Recovery:"," Cluster nodes exchange heartbeats every ",[21,283,284],{},"5 seconds",". Unresponsive nodes are automatically removed from the active hash ring and re-integrated once they recover.",[18,287,288,291,292,294],{},[21,289,290],{},"Prometheus & Grafana Observability:"," Every node exposes hit rate, latency histograms, eviction counts, and memory usage at ",[73,293,148],{},", giving direct visibility into bottlenecks and failover behavior.",[10,296,298],{"id":297},"benchmarks-chaos-testing","Benchmarks & Chaos Testing",[60,300,301],{},"All measurements below are recorded directly from the repository's benchmark and test suites:",[303,304,306],"h3",{"id":305},"single-node-in-process-microbenchmarks","Single-Node In-Process Microbenchmarks",[15,308,309,318,326],{},[18,310,311,317],{},[21,312,313,316],{},[73,314,315],{},"Get"," (Parallel):"," ~7.3M ops\u002Fs (165.6 ns\u002Fop, 16 B\u002Fop)",[18,319,320,325],{},[21,321,322,316],{},[73,323,324],{},"Set"," ~8.4M ops\u002Fs (153.7 ns\u002Fop, 111 B\u002Fop)",[18,327,328,334],{},[21,329,330,333],{},[73,331,332],{},"Mixed (80\u002F20)",":"," ~12.0M ops\u002Fs (100.5 ns\u002Fop, 34 B\u002Fop)",[60,336,337],{},[103,338,339],{},"(Note: Single-node figures measure in-process engine performance without network syscalls or serialization overhead; real-world networked throughput is captured in the distributed cluster load test below.)",[303,341,343],{"id":342},"_3-node-docker-distributed-load-test","3-Node Docker Distributed Load Test",[15,345,346,355,372],{},[18,347,348,351,352,354],{},[21,349,350],{},"Configuration:"," 3-node Docker cluster, replication factor ",[73,353,270],{},", Client SDK with 10 concurrent goroutines.",[18,356,357,360,361,363,364,367,368,371],{},[21,358,359],{},"Workload:"," 100,000 total operations (70% ",[73,362,225],{},", 20% ",[73,365,366],{},"SET",", 10% ",[73,369,370],{},"DELETE",").",[18,373,374,377,378,135,381,135,384,387],{},[21,375,376],{},"Results:"," ",[21,379,380],{},"1,163.47 ops\u002Fsec",[21,382,383],{},"0.00% error rate",[21,385,386],{},"~8.6ms"," average latency per request (including inter-node gRPC replication).",[303,389,391],{"id":390},"chaos-test-node-failure-resilience","Chaos Test (Node Failure Resilience)",[15,393,394,404],{},[18,395,396,399,400,403],{},[21,397,398],{},"Scenario:"," Active background traffic from 5 concurrent workers (4,756 total operations) while abruptly terminating a live node via ",[73,401,402],{},"docker stop node2",".",[18,405,406,377,408,410],{},[21,407,376],{},[21,409,383],{}," while the node was down as the SDK automatically failed over to replicas, followed by automatic node re-join and resynchronization upon restart without manual intervention.",[10,412,414],{"id":413},"key-engineering-takeaways","Key Engineering Takeaways",[15,416,417,427,433,439],{},[18,418,419,422,423,426],{},[21,420,421],{},"Lock Contention Profiling:"," Moving from a single mutex to 256 sharded ",[73,424,425],{},"RWMutex"," locks demonstrated firsthand how concurrency bottlenecks hide until tested under parallel load.",[18,428,429,432],{},[21,430,431],{},"Consistency vs. Latency Trade-Off:"," Enforcing synchronous write quorum guarantees replica durability before ACK, at the measurable cost of inter-node network round-trip latency on every write.",[18,434,435,438],{},[21,436,437],{},"Observability First:"," Instrumenting Prometheus histograms and Grafana dashboards turned opaque cluster stalls and failover timing into concrete, debuggable telemetry.",[18,440,441,444,445,448],{},[21,442,443],{},"Container Networking Realities:"," Running a multi-node cluster inside Docker exposed ",[73,446,447],{},"127.0.0.1"," vs. container-hostname advertisement pitfalls, leading to cleaner peer discovery and address advertisement configuration.",{"title":119,"searchDepth":450,"depth":450,"links":451},2,[452,453,454,455,456,457,458,464],{"id":12,"depth":450,"text":13},{"id":57,"depth":450,"text":58},{"id":91,"depth":450,"text":92},{"id":108,"depth":450,"text":109},{"id":177,"depth":450,"text":178},{"id":258,"depth":450,"text":259},{"id":297,"depth":450,"text":298,"children":459},[460,462,463],{"id":305,"depth":461,"text":306},3,{"id":342,"depth":461,"text":343},{"id":390,"depth":461,"text":391},{"id":413,"depth":450,"text":414},"md",{"subtitle":467,"slug":468,"client":469,"year":470,"role":471,"category":472,"technologies":473},"Distributed In-Memory Key-Value Cache Engine in Go","cachedist","Personal Open Source (Learning Project)",2026,"Solo Developer","Experiments & Technical Exploration",[67,474,475,476,477,478,479],"gRPC","Protobuf","Prometheus","Grafana","Docker","Distributed Systems",true,"\u002Fprojects\u002Fcachedist",{"title":5,"description":119},"projects\u002Fcachedist","GJSM0GghZTP2NsOLEnL_zXJi_LF5XSzFC_suHV0H_lw",1796006983827]