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.goStart the API server:
./distributed-cache --port=8080It 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/...