Self-host gun
0.2019.413P2P graph database with realtime sync
docker run -p 8765:8765 gundb/gun- Stars
- 19 161
- Port
- 8765 (GUN relay peer HTTP/WebSocket server (serves the examples and the /gun endpoint))
gundb/gunWhat 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
AppwriteThe open-source cloud for agents & devs. Including Auth, Databases, Storage, Functions, Messaging, Hosting, Realtime, WAF and moreCompareAppwrite with gun
mainSelf-hosted pastebin alternative with browser encryption, VS Code–like editor, file sharing, whiteboard drawings, and peer connections.Comparemain with gun
folderhostA self-hosted, open-source cloud platform offering file sharing, real-time collaboration, and user management in a ~19MB binary as a lightweight Nextcloud alternativeComparefolderhost with gun
cinnyOpen-source Matrix client (AGPL-3.0) for self-hosted federated chat with end-to-end encryption, served as a static web app via Docker or tarball.Comparecinny with gun
guptSelf-hosted, end-to-end encrypted messenger and privacy suite with no phone number or central server — runs in the browser on a decentralized Nostr relay network.Comparegupt with gun
nethermind-ethereumSelf-hosted Ethereum execution client on .NET featuring rapid snap sync, plugin architecture, and configurable history storage. Compatible with Linux, Windows, and macOS.Comparenethermind-ethereum with gun
CondensationDBAn open-source distributed data system: build apps with its client libraries and run a self-hosted store server, with semilattice merging and end-to-end encryption.CompareCondensationDB with gun
FideliusSelf-hosted, open-source web app for one-time secret sharing with end-to-end browser encryption. Server never sees plaintext; secrets deleted after one view.CompareFidelius with gun
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
GUN is an ecosystem of tools that let you build community run and encrypted applications - like an Open Source Firebase or a Decentralized Dropbox.
The Internet Archive and 100s of other apps run GUN in-production.
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
helixdbA Rust-based graph database that unifies vector similarity and keyword search on object storage for AI memory workloads.
influxdbOpen-source, single-node time series database you self-host for real-time metrics and events, querying Parquet-backed data with SQL or InfluxQL.
instantSelf-hosted, open-source backend-as-a-service: relational queries, realtime sync, offline caching, auth, storage and permission rules on PostgreSQL.
KeyDBA Multithreaded Fork of Redis
Manticore SearchSelf-hosted, open-source search database that speaks SQL and HTTP JSON, with full-text, vector, hybrid and conversational search pitched as an Elasticsearch alternative.
minikvA self-hosted, open-source distributed key-value and object store written in Rust that achieves strong consistency through Raft consensus and two-phase commit.
mongoSelf-hosted MongoDB Community Server: the source-available document database with replica sets, sharding, ACID transactions, and built-in search.
MyDuck ServerMyDuck Server is a self-hosted, open-source analytics server with MySQL/PostgreSQL wire protocols and DuckDB's OLAP engine for 1000x faster queries.
MySQL 5.7Open-source SQL database server you can self-host as MySQL Community via Docker or Oracle packages, with InnoDB ACID transactions, JSON and replication.
neo4jSelf-hosted, open-source graph database: query connected data with Cypher under ACID transactions. Run the free GPLv3 Community Edition via Docker, packages, or Helm.
oceanbaseSelf-hosted, open-source distributed SQL database that is MySQL compatible and handles OLTP plus real-time HTAP analytics, vector and full-text search in one engine.
OmniDBOpen-source, self-hosted web tool for database management: query editor, database tree, monitoring, explain visualizer, LDAP login and an optional PostgreSQL backend.

0 comments