Gossip-Cache is a project that focuses on implementing a cache synchronization mechanism for distributed systems. It utilizes the Gossip Protocol to ensure that all nodes within a network maintain a synchronized cache state, and works together to provide Eventual Consistency . This approach helps in enhancing the overall performance and reliability of distributed systems by ensuring that cached data remains consistent across all nodes, thereby reducing latency and improving data access times. Additionally, it allows nodes to function as a disconnected cache, operating independently from the gossip network as a normal cache.
Table of Contents
Gossip-Cache-Demo.mp4
The above demo illustrates some of the Key features of Gossip-Cache. It begins by simulating the addition of nodes, each initialized with a cache, to the server. Two clients are then introduced to showcase how their caches are shared. The server serves as a gateway for the nodes, facilitating their entry into the network. This demonstration effectively highlights the concept of eventual consistency, as the data may not be immediately available to all nodes but is eventually synchronized across the network. The synchronization time is directly influenced by the number of nodes in the network.It also provides you to connect as a disconnected node incase you dont want to connect as a gossip peer node and want to use it just as a normal cache. It also unlocks a new route of /delete/:key which allows you to delete the cache item directly.
- Distributed Systems : The project is fundamentally a distributed system since it involves multiple nodes (clients) that coordinate and communicate to achieve a common goal.
- Gossip Protocol : Gossip protocols are used for information dissemination in distributed systems, ensuring eventual consistency by spreading information in a manner similar to how gossip spreads in social networks.
- Eventual Consistency : The system aims for eventual consistency, meaning that all nodes will converge to the same state over time, even though they may be temporarily inconsistent.
- Distributed Caching : The use of caches in each node and the management of these caches using TTL (time-to-live) values and exchange protocols is a classic problem in distributed caching.
- Node Registration: Each node connecting to the server is registered and stored, creating a robust network map.
- Neighbor Discovery: New nodes dynamically discover and record their neighbors, fostering a resilient network structure.
- Cache Exchange: Nodes use the gossip protocol to exchange cache information, promoting widespread data consistency.
- TTL Management: Cache items are managed with a time-to-live (TTL) mechanism, ensuring outdated entries are purged.
- Eventual Consistency: Designed for environments where eventual consistency is acceptable, Gossip-Cache excels in maintaining a balanced cache state.
To get started with your Golang application, follow these steps:
-
Install Golang: Download and install Golang from the official website.
-
Set Up Your Workspace: Create a new directory for your project and set your
GOPATH
environment variable to point to this directory. -
Initialize Your Project: Inside your project directory, run the following command to initialize a new Go module:
go mod init github.com/your-username/project-name
After installing Golang, you can start running your Go project.
-
Run without Debugging: In your terminal, navigate to the directory containing your main Go file (usually named
main.go
). Then, run the following command to build and execute your Go application:go run main.go
This command will compile and execute your Go program without generating a binary file.
-
Create an image from the docker file:
docker build -t gossipcache .
-
Run this on your terminal (needs docker to be preinstalled):
docker run -p 3000:3000 -it gossipcache
-
Get "/"
- Connects to the gateway server and stay connected.
- Response as :
{ "data": null, "message": "Successfully connected to server.", "success": true }
-
Get "/get/:key"
- Response as :
{ "data": { "key": "test", "value": "data", "ttl": 1718998692919380103 }, "message": "Successfully data retrieved", "success": true }
- Response as :
-
POST "/set"
- Request as (only etherium/bitcoin are possible values currently):
- key : The unique string which will be used to fetch this data.
- value : Can be anything (string ,int, array...) whose value is to be stored.
- ttl : TTL is the time after which the system should delete this data (in seconds).
{ "key":"hello", "value":["there","yoii"], "ttl":500 }
- Response as:
- Sucess : True/False
- Message: Success message, Update message(if data was already present), Error message
- Data: Respective data
{ "data": { "key": "hello", "value": [ "there", "yoii" ], "ttl": 1718998846229906412 }, "message": "New value successfully added", "success": true }
- Request as (only etherium/bitcoin are possible values currently):
-
GET "/disconnect"
- Disconnects from the peer network and allows you to use it as a normal cache. The data will be shared only when you connect again to the server.
-
GET "/localcache"
- Connects to the gateway server and work as a normal cache.
- Response as :
{ "data": null, "message": "Successfully connected to server.", "success": true }
-
GET "/delete/:key"
- Available only when not connected to the network i.e. as normal cache.
- Use /disconnect if already connected as a node to the network or /localcache if want to connect as a disconnected node.
- Response as :
{ "data": { "key": "hello", "value": [ "there", "yoii" ], "ttl": 1719127788523315000 }, "message": "Connected to the server successfully!!", "success": true }
![](https://private-user-images.githubusercontent.com/106571927/341883548-1534f7e3-afc4-47ca-9643-e3bef4d3dd79.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsIm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GczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgyMFQwNDM5MzZaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1hNmJjZGI0ZjRlMjA2NzI2YzA4ZTg1YjdlZDk3ZWViMzY4NTk4MTMwMTc5MjY3NjZmOTBlMzdiN2Y4NzRjZDUwJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.HKxnMbn445lch_TT4d59JjSv72vbBtvMaLJDbvFVObQ)
Contributions are what make the open source community such an amazing place to learn, inspire ,and create.Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Uttkarsh Raj - https://github.com/Uttkarsh-raj