Skip to main content

RADisk Storage Adapter

RADisk is GUN’s default storage adapter for Node.js environments. It stores data as files on the file system using an efficient Radix tree structure for fast queries and range lookups.

Installation

RADisk is included with GUN and automatically enabled in Node.js environments:

Configuration Options

RADisk accepts the following configuration options:

Key Options

file (string)

Base directory or file name for storing data. Default: 'radata'

until / wait (number)

Time in milliseconds to wait before writing batched data to disk. This allows multiple writes to be grouped together. Default: 250

batch (number)

Maximum number of write operations to batch before forcing a disk write. Default: 10000

chunk (number)

Maximum size (in bytes) for a single data file before it’s automatically split. Default: 1048576 (1MB)

max (number)

Maximum size for individual data values. Default: 90000000 (90MB)

jsonify (boolean)

Whether to use JSON format for storage. When true, data is stored as JSON objects. When false, uses the legacy RAD encoding format. Default: true

How RADisk Works

File Organization

RADisk creates a directory structure to store your data:
File names are URL-encoded to handle special characters:
  • %1C - Character code 28 (directory file)
  • %1B - The escape character separating soul and key
  • %21 - Exclamation mark (’!’)

Radix Tree Storage

RADisk uses a Radix tree to efficiently organize keys:

Automatic File Splitting

When a data file exceeds the chunk size, RADisk automatically splits it:
  1. Creates a new file for the second half of the keys
  2. Updates the original file to contain only the first half
  3. Updates the directory index to track both files
This keeps file sizes manageable and improves read performance.

Write Batching

RADisk batches writes to improve performance:
Benefits:
  • Reduces disk I/O operations
  • Improves write performance
  • Reduces risk of corruption from partial writes

Storage Interface

RADisk requires a storage interface with get and put methods:

Read and Write Operations

Writing Data

Reading Data

Performance Tuning

High-Throughput Scenarios

For applications with high write volume:

Large Data Sets

For applications storing large amounts of data:

Low Latency Requirements

For applications requiring fast writes:

Data Format

JSON Format (Default)

With jsonify: true, data is stored as JSON:

RAD Format (Legacy)

With jsonify: false, data uses the RAD encoding:
The RAD format uses special encoding:
  • ! - Field separator (ASCII 31)
  • # - Prefix length indicator
  • " - String value
  • + - Number value
  • : - Value separator

File System Considerations

Directory Structure

Ensure the storage directory exists and has proper permissions:

Backup and Recovery

To backup RADisk data:
To restore:

Cleaning Up

RADisk automatically manages file lifecycle, but you can manually clean up if needed:

Troubleshooting

Error: “Radisk needs opt.store interface”

You must provide a storage interface:

Error: “Data too big!”

Increase the max option:

Corrupt File Recovery

RADisk automatically detects and removes corrupt files:

Best Practices

  1. Use appropriate chunk sizes: Smaller chunks for many small writes, larger chunks for fewer large writes
  2. Enable batching: Keep until at 250ms or higher for better performance
  3. Backup regularly: Use file system snapshots or regular backups
  4. Monitor disk space: RADisk can grow based on your data
  5. Use JSON format: The default JSON format is more debuggable than RAD format

Next Steps

Rindexed Adapter

Browser storage with IndexedDB

S3 Adapter

Cloud storage with Amazon S3

Custom Adapters

Build your own storage adapter

Performance

Optimize GUN performance