Skip to main content

Storage Adapters Overview

GUN’s storage layer is built on a flexible adapter architecture that allows you to persist data across different storage backends. Storage adapters enable GUN to work seamlessly in browsers, Node.js servers, and cloud environments.

What are Storage Adapters?

Storage adapters are plugins that provide a consistent interface for GUN to read and write data to various storage systems. They abstract the underlying storage implementation, allowing GUN to use the same API regardless of whether data is stored on disk, in IndexedDB, or in cloud storage. All storage adapters implement a common interface:

Available Storage Adapters

GUN provides several built-in storage adapters for different environments:

RADisk (File System)

Use for: Node.js servers, local development
  • Stores data as files on the file system
  • Built on RAD (Radix) storage architecture
  • Optimized for high-performance read/write operations
  • Automatic file splitting and data organization
Learn more about RADisk →

Rindexed (IndexedDB)

Use for: Browser applications, Progressive Web Apps
  • Stores data in IndexedDB (browser database)
  • Automatic fallback to in-memory storage if IndexedDB unavailable
  • Handles connection resets to work around WebKit bugs
  • No file size limits (uses browser quota)
Learn more about Rindexed →

S3 Adapter

Use for: Cloud deployments, distributed systems, S3-compatible storage
  • Stores data in Amazon S3 or S3-compatible services
  • Supports bucket-based organization
  • Built-in caching layer for performance
  • Compatible with DigitalOcean Spaces, MinIO, and other S3-compatible services
Learn more about S3 →

How RAD (Radix) Storage Works

GUN’s default storage system is called RAD (Radix), which uses a Radix tree data structure for efficient key-value storage. The RAD system provides several key features:

Radix Tree Structure

A Radix tree (also called a radix trie or compressed trie) stores keys by their shared prefixes, enabling:
  • Fast lookups: O(k) where k is the key length
  • Efficient prefix searches: Find all keys starting with a prefix
  • Range queries: Retrieve data between two keys
  • Compact storage: Shared prefixes reduce memory usage

Batching and Performance

RAD implements intelligent batching to optimize disk I/O:
Key batching features:
  1. Write Delay: Batches writes for up to 250ms (configurable) to group multiple operations
  2. Batch Limits: Forces a write after reaching the batch size limit
  3. Automatic File Splitting: When files exceed the chunk size, RAD automatically splits them
  4. Corruption Protection: Batching reduces the risk of disk corruption

File Organization

RAD organizes data into multiple files based on key ranges:
  • Directory File: Special file tracking all data files
  • Data Files: Store actual key-value pairs, split by key range
  • Automatic Sharding: Large datasets are automatically distributed across files
  • Efficient Queries: Only relevant files are read for range queries

Data Format

RAD supports two storage formats: JSON Format (default):
RAD Format (legacy):

Choosing the Right Adapter

Storage Adapter Configuration

Storage adapters are configured when initializing GUN:

Custom Storage Adapters

You can build custom storage adapters for any storage backend:
  • PostgreSQL
  • MongoDB
  • Redis
  • Custom databases
  • Distributed file systems
Learn how to build custom adapters →

Next Steps

RADisk Adapter

File system storage for Node.js servers

Rindexed Adapter

IndexedDB storage for browser applications

S3 Adapter

Cloud storage with Amazon S3

Custom Adapters

Build your own storage adapter