DBDB.io The Encyclopedia of Database Systems · Est. 2017
Database of Databases

Database Entry

GUN


Gun is an open-source and realtime, decentralized, offline-first, graph database engine written in JavaScript. [02]

Source Code
https://github.com/amark/gun[02]
Developer
Country of Origin
US
Start Year
2014 [10]
Project Types
Commercial, Open Source
Written in
JavaScript
Supported Languages
JavaScript
Operating System
Linux
License
Apache v2

It is designed to be small and simple for fast data synchronization which runs everywhere JavaScript is supported. Gun is a fully distributed database aiming at scaling web application and correctly synchronizing data among devices with offline-first feature.

Database Entry

GUN


Gun is an open-source and realtime, decentralized, offline-first, graph database engine written in JavaScript.

It is designed to be small and simple for fast data synchronization which runs everywhere JavaScript is supported. Gun is a fully distributed database aiming at scaling web application and correctly synchronizing data among devices with offline-first feature.[02]

History[02]


Gun was built by Mark Nadal in 2014.

He spent 4 years researching scaling up his web application, and eventually he found out it was hard with traditional databases or Master-Slave databases because of one big bottleneck, and decided to create the P2P database which can run on any browsers.

Checkpoints[04]


Gun does not support for checkpoints by default. But users may use third party adapters as the persistent layer like Amazon S3 to achieve checkpointing.

Compression[05]


Gun uses radix tree to store user data in memory, and the Radisk is what the project team have designed for it to persist storage in Radix Tree by default. Gun also supports self-implemented or third-party persistent storage like Amazon S3, so data compression can be done outside of Gun.

Concurrency Control[06]


Gun is a offline-first database engine and uses eventual consistency. It allows users to view and update data when it is offline, and data will be synchronized when it is online. Gun uses a self-designed conflict resolution algorithm, Hypothetical Amnesia Machine (HAM), which combines timestamps and vector clocks to resolve conflicts and order data.

Data Model[07]


Gun uses graph to represent data and data relations. A logical graph in Gun is denormalized into a subset of JSON files.

Foreign Keys


Gun is a NoSQL database without foreign keys support.

Indexes[08][04]


By default, Gun uses the Radisk Storage Engine as an in-memory and on-disk radix tree to store user data. Gun supports some existing persistent storage services like Amazon S3 to be plugged in, and also offers interfaces for developers to build persistent layer for it, so indexing can be flexible.

Isolation Levels


Gun allows offline usage and synchronizes data when online with eventual consistency. Each user has their own copy of data when using. Conflicts are handled by Hypothetical Amnesia Machine (HAM) when presented during synchronization.

Joins


Gun is a NoSQL database without join operations support.

Logging


Not supported

Query Interface[09]


Gun provides custom API for query interfaces. Some other choices are also available including GraphQL and SPARQL.

Storage Architecture[04]


Gun supports both the disk-oriented and in-memory mode. It is offline-first database where browser asks peers for data to use in memory and browser local storage the most often as cache. By default, Gun has a built-in persistent storage layer called Radix and there are some other available third-party persistent service options suggested by Gun.

  • Amazon S3
  • Level
  • MongoDB
  • Cassandra

Storage Model[04]


Gun stores records in JSON files. Data and relations are represented as a graph. Records are connected by references, called “souls” internally in Gun. Some official and simple queries similar in SQL are implemented with paths traversing. Complex operations among relations can be easily extended on graph.

Stored Procedures


Gun is a NoSQL database without stored procedures support.

System Architecture


In Gun, every node utilizes its own memory space and shares the persistent storage with the other peers. Gun implements its own transport layer protocol for P2P networking, Daisy-chain Ad-hoc Mesh-network (DAM). The ad hoc mesh network is used to coordinate with peers by messaging without producing too many duplicate rebroadcasting messages.

Views


Gun is a NoSQL database without views support.

Citations

10 sources
  1. Decentralized Database js.org
  2. GitHub - amark/gun: An open source cybersecurity protocol for syncing decentralized graph data. · GitHub github.com
  3. GUN — the database for freedom fighters - Docs v2.0 gun.eco
  4. GUN — the database for freedom fighters - Docs v2.0 gun.eco
  5. GUN — the database for freedom fighters - Docs v2.0 gun.eco
  6. Conflict Resolution with Guns · amark/gun Wiki · GitHub github.com
  7. GUN — the database for freedom fighters - Docs v2.0 gun.eco Dead — Check Archive
  8. Radisk · amark/gun Wiki · GitHub github.com
  9. GUN — the database for freedom fighters - Docs v2.0 gun.eco
  10. hmm github.com
Revision #10 Last Updated: