Distributed Cache is a scalable caching solution that distributes data across multiple nodes using consistent hashing. It ensures efficient storage, fast retrieval, and fault tolerance, making it ideal for high-performance distributed applications.
- ✅ Consistent Hashing → Efficient load distribution among nodes
- ✅ Pub/Sub Communication → Nodes synchronize using a publish-subscribe system
- ✅ API Support → RESTful API for managing cache operations (GET, SET)
- ✅ Fault-Tolerant & Scalable → Nodes can dynamically join or leave the cache ring
distributed-cache/
│── internal/
│ ├── node/ # Handles individual cache nodes
│ ├── cache/ # Implements caching
│ ├── communication/ # Manages Pub/Sub messaging
│ ├── consistent/ # Implements consistent hashing
│── api/ # REST API server
│── cmd/ # Entry point for running the application
│── README.md # Project documentation
✅ Go 1.18+ → Install from golang.org
git clone https://github.com/its-saeed/distributed-cache.git
cd distributed-cache
go mod tidy
go build -o distributed-cache cmd/main.go
Start the API server:
./distributed-cache --port=8080
It starts the API server on port 8080. It also starts three caching nodes, node1
, node2
, and node3
, which are responsible for storing and retrieving data.
curl -X POST "http://localhost:8080/set?key=foo&value=bar"
Response:
{
"message": "Value set successfully",
"key": "foo",
"node": "node-1"
}
curl -X GET "http://localhost:8080/get?key=foo"
Response:
{
"key": "foo",
"value": "bar",
"node": "node-1"
}
go test -v ./internal/...