Skip to content

its-saeed/distributed-cache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Distributed Cache System

πŸ“– Overview

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.

✨ Features

  • βœ… 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

πŸ“Œ Project Structure

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

πŸ”§ Installation

Prerequisites

βœ… Go 1.18+ β†’ Install from golang.org

Steps

git clone https://github.com/its-saeed/distributed-cache.git
cd distributed-cache
go mod tidy
go build -o distributed-cache cmd/main.go

πŸš€ Running the Project

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.

πŸ”— API Usage

πŸ“₯ Set Key

curl -X POST "http://localhost:8080/set?key=foo&value=bar"

Response:

{
    "message": "Value set successfully",
    "key": "foo",
    "node": "node-1"
}

πŸ”Ž Get Key

curl -X GET "http://localhost:8080/get?key=foo"

Response:

{
    "key": "foo",
    "value": "bar",
    "node": "node-1"
}

πŸ§ͺ Running Tests

go test -v ./internal/... 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages