Gun.js in JavaScript
Lately, I’ve been working on GUN.js and I’m sharing with you what I’ve learned so far. GUN is a database engine that runs everywhere JavaScript does browsers, mobile devices and servers, allowing you to build exactly the data system you want. GUN.JS aka GunDB is more than just a graph database

Distributed - Processing is shared across multiple nodes
GUN is fully decentralized (peer-to-peer or multi-master), meaning that changes are not controlled by a centralized server. A server can be just another peer (node or vertices) in the network, one that may have more reliable resources than a browser.
You save data on one machine, and it will sync it to other peers without needing a complex consensus protocol. And it just works.
Knowing a little bit about decentralized architecture we can understand the other features. Under the hood, GUN allows for data synchronization to happen seamlessly between all connected nodes by default. It’s offline first capabilities mean that if connectivity is lost to other nodes due to a network error or no availability, the application will store all changes locally and automatically synchronize as soon there is a connection.

But how does it work?
If you are feeling lost in buzzwords, the following description might give you a general idea about what’s going on.
The gun graph database is stored across all peers participating in the network. Most data distribution scenarios that one could think of are possible to occur: Every peer might possess the complete graph, or only a subset of the complete graph and may possess data that does not exist on any other node (yet). The whole database is considered to be the union of all peers’ graphs.
It appears there’s a fair amount of communication back & forth, negotiating what nodes need to be replicated, as well as connecting peers to each other — “relaying” along data that one peer needs that another one has.









