selfhost.directory

The index of self-hostable projects — ranked, categorized and served with live updates.
Own your data and stop giving it to big tech.

gun logo

Self-host gun

0.2019.413

P2P graph database with realtime sync

BetaOpen SourceOther
docker run -p 8765:8765 gundb/gun
Updated4 months ago
LanguageJavaScript
Setup difficultyEasy
Stars
19 161
Port
8765 (GUN relay peer HTTP/WebSocket server (serves the examples and the /gun endpoint))
Docker
gundb/gun
gun screenshot 1

What is gun?

GUN is an open-source graph data engine and synchronization protocol: a lightweight embedded database (roughly 9KB gzipped, with a claimed 20M+ API ops/sec) that keeps data replicated between peers in realtime, works offline-first, and stores one graph you can read as key/value, documents, tables or circular references. Its SEA crypto layer gives apps user accounts plus optional end-to-end encryption, signing and key exchange. You embed it with the gun npm package, a CDN script tag, or a Node require, and it also runs in React Native. For your own infrastructure you run relay peers - Node processes that persist data and hand it to clients - via the community gundb/gun container image, a curl-based installer that sets up a systemd relay service, a one-click Heroku deploy, or the repo's own start script; on the server data is written to disk with the RAD radix storage engine, and other backends include browser storage, plain files, Amazon S3 and IPFS. Caveats stated by the project: the container image is community maintained and may be outdated, some of its own server docs are flagged as out of date, releases use date-based 0.x versioning, and encryption is opt-in rather than automatic.

gun alternatives

All self-hosted alternatives to Dropbox → All self-hosted alternatives to Firebase →

Should you self-host gun?

gun scores 67/100 on selfhost.directory (how scoring works) and ranks #17 of 38 in Databases. It has 19 161 GitHub stars, +17 in the last 30 days.

There was no stable release in the past 12 months, so check the repository's recent activity before you rely on it.

Setup is easy: most people get it running in one sitting. An official Docker image is available. It is Other-licensed and written mostly in JavaScript.

Its closest alternative on selfhost.directory is supabase (90/100, 114 660 stars). It scores higher overall, so compare the two before you pick. See gun vs supabase side by side.

Features

  • Browser, Node.js and mobile support
  • CRDT conflict resolution
  • End-to-end encryptionEncryption is supported but not automatic - data under a user is signed and must be encrypted by the app developer.
  • Lightweight embedded engine
  • Mesh networking and routing
  • Multi-model graph data
  • No master / no single source of truth
  • Offline-first local data
  • Pluggable storage backends
  • Reactive subscriptions
  • Realtime peer-to-peer sync
  • Relay peer server
  • User Accounts

gun README

How to install gun

Install gun with Docker

Environment variables
PORT, PEERS, HTTPS_KEY, HTTPS_CERT
docker run -p 8765:8765 gundb/gun

Community contributed image; README warns it may be old with missing security updates, so check version numbers.

How to configure gun

  • peersConstructor/API option: one URL or an array of peer URLs the instance syncs with
  • fileConstructor option: simple bundled JSON persistence file path (not meant for production)
  • radisktrueConstructor option: enable the radix disk storage

    values: true / false

  • s3Constructor option: bundled Amazon S3 storage with key, secret and bucket
  • PORT8765Port the relay peer example listens on (defaults to 8765; set to 443 when HTTPS keys are given)

gun releases & version history

@ Every self-hosted release, weekly

One Monday email with the week's stable releases across the directory.

FAQ

Can I use GUN inside a Web Worker?

Yes, by faking the window object and importScripts()-ing the GUN modules; since workers have no localStorage you need the indexedDB RAD adapter to persist.

Can a lost password be recovered?

No, because there is no server storing the password, unless the app implements its own recovery design such as a separate recovery server or 3-friend-factor sharing.

How can I change a user password (SEA)?

Authenticate with a change option containing the new pass value: user.auth(alias, passphrase, callback, { change: 'new-pass-value' }).

Can you use SQL like queries, what about pagination and aggregation?

No - querying is not provided out of the box, and graph pagination works differently; you traverse with .map() and .on()/.once() and design indices yourself to keep query sets small.

What is a soul?

A soul is gun's term for the generated unique identifier (UUID) that GUN stores as metadata for each node in the graph.

What is the difference between Relay Peer and other Peers?

Browsers persist only their localStorage, while the Node.js relay peer saves data to files on disk and dispatches it to subscribing clients; any client can also serve data to others once it has it.

How do I delete data?

You must tombstone it by putting null (gun.get('data').put(null)); otherwise an offline peer can later overwrite the deletion.

Is GUN a distributed database?

Yes - data is kept and shared between peers across the network, so a peer can receive records from peers it is not directly connected to.

More in Databases

Rate this project

Click to rate — no account needed.

0 comments

Posting as guest
Loading comments…