DEV Community

Alex Spinov
Alex Spinov

Posted on

Dragonfly Has a Free In-Memory Store — 25x Faster Than Redis With Less Memory

Redis uses 3x more memory than it needs to. Dragonfly stores the same data in 1/3 of the RAM — and handles 25x more operations.

What is Dragonfly?

Dragonfly is a modern in-memory data store compatible with Redis and Memcached APIs. Written in C++, it uses a shared-nothing architecture and novel data structures to dramatically reduce memory usage.

Why Dragonfly Is Special

1. Redis API Compatible

import redis
r = redis.Redis(host='localhost', port=6379)

# All Redis commands work
r.set('user:1', json.dumps({'name': 'Alice'}))
r.hset('stats', mapping={'views': 100, 'clicks': 42})
r.lpush('queue', 'task1', 'task2')
r.zadd('leaderboard', {'player1': 100, 'player2': 85})
Enter fullscreen mode Exit fullscreen mode

2. Dramatically Less Memory

Dataset Redis Memory Dragonfly Memory
1M strings 85MB 30MB
1M hashes 120MB 45MB
10M keys 1.2GB 400MB

Dragonfly uses a novel hash table (Dash) that's more memory-efficient than Redis's dictionaries.

3. Multi-Threaded (Shared-Nothing)

# Uses all CPU cores automatically
docker run --ulimit memlock=-1 -p 6379:6379 docker.dragonflydb.io/dragonflydb/dragonfly

# Benchmark: 4M ops/sec on a single instance (vs ~100K for Redis)
Enter fullscreen mode Exit fullscreen mode

Each thread owns its data slice. No locks, no contention.

4. Snapshotting Without Fork

Redis uses fork() to create snapshots — doubles memory during save. Dragonfly uses a novel algorithm that snapshots without forking:

# Redis: 8GB data → needs 16GB RAM during BGSAVE
# Dragonfly: 8GB data → needs ~8GB RAM during snapshot
Enter fullscreen mode Exit fullscreen mode

5. Tiered Storage

dragonfly --tiered_prefix=/mnt/nvme/dragonfly
Enter fullscreen mode Exit fullscreen mode

Automatically moves cold data to SSD while keeping hot data in RAM.

Performance

Benchmark Redis 7 Dragonfly
Throughput (SET) 100K/s 4M/s
Throughput (GET) 110K/s 4.2M/s
P99 latency 0.5ms 0.3ms
Memory efficiency Baseline 3x better
Snapshot overhead 2x memory ~0

Dragonfly vs Redis vs KeyDB

Dragonfly Redis KeyDB
Architecture Shared-nothing Single-threaded Multi-threaded
Memory efficiency 3x better Baseline Same as Redis
Snapshot No fork needed Fork (2x memory) Fork
License BSL 1.1 SSPL BSD
Memcached compat Yes No No

Getting Started

# Docker (simplest)
docker run --ulimit memlock=-1 -p 6379:6379 \
  docker.dragonflydb.io/dragonflydb/dragonfly

# Connect with redis-cli
redis-cli -p 6379
> SET hello "dragonfly"
> GET hello
Enter fullscreen mode Exit fullscreen mode

The Bottom Line

Dragonfly is what Redis would be if designed today. 25x throughput, 3x memory efficiency, no-fork snapshots, and full API compatibility. If your Redis costs are growing — Dragonfly cuts them by 70%.


Need data solutions? I build web scraping tools. Check my Apify actors or email spinov001@gmail.com.

Top comments (0)