Skip to content

Commit 164ada9

Browse files
authored
Merge pull request #328 from FalkorDB/add-durability-docs
Add comprehensive durability documentation
2 parents c29e4af + c7882c1 commit 164ada9

File tree

4 files changed

+280
-5
lines changed

4 files changed

+280
-5
lines changed

.wordlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,3 +752,6 @@ FDB
752752
xlarge
753753
SaaS
754754
GCP's
755+
fsync
756+
cron
757+
everysec

operations/durability.md

Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
1+
---
2+
title: "Durability"
3+
nav_order: 2
4+
description: "Understanding Data Durability Options in FalkorDB"
5+
parent: "Operations"
6+
has_children: true
7+
---
8+
9+
# Data Durability in FalkorDB
10+
11+
FalkorDB, built on Redis, provides multiple mechanisms for data durability to ensure your graph data persists across restarts and survives system failures. Understanding these options helps you balance performance requirements with data safety needs.
12+
13+
## Overview
14+
15+
FalkorDB supports two primary persistence mechanisms:
16+
17+
1. **RDB (Redis Database)** - Point-in-time snapshots
18+
2. **AOF (Append-Only File)** - Operation logging
19+
20+
You can use either mechanism independently or combine both for enhanced durability.
21+
22+
## RDB Snapshots
23+
24+
### How RDB Works
25+
26+
RDB creates point-in-time snapshots of your entire dataset and writes them to a compact `.rdb` file on disk. This approach provides:
27+
28+
- Compact, single-file backups ideal for disaster recovery
29+
- Fast restart times (faster than AOF for large datasets)
30+
- Easy versioning and cloning of datasets
31+
32+
### RDB Configuration
33+
34+
Configure RDB through `redis.conf` or via `redis-cli`:
35+
36+
```conf
37+
# Save the dataset every 60 seconds if at least 1000 keys changed
38+
save 60 1000
39+
40+
# Save every 5 minutes if at least 100 keys changed
41+
save 300 100
42+
43+
# Save every 15 minutes if at least 1 key changed
44+
save 900 1
45+
46+
# Configure RDB file location and name
47+
dir /var/lib/falkordb/data
48+
dbfilename dump.rdb
49+
```
50+
51+
### RDB Considerations
52+
53+
**Advantages:**
54+
- Excellent for backups and disaster recovery
55+
- Minimal impact on performance during normal operations
56+
- Compact file format
57+
- Fast data loading on restart
58+
59+
**Limitations:**
60+
- Potential data loss between snapshots
61+
- Forking can be time-consuming for large datasets
62+
- May cause brief performance degradation (milliseconds to 1 second) during snapshot creation on very large datasets
63+
- Requires significant disk I/O during snapshot operations
64+
65+
**Best for:** Use cases where losing a few minutes of data is acceptable, or as a backup mechanism alongside AOF.
66+
67+
## AOF (Append-Only File)
68+
69+
### How AOF Works
70+
71+
AOF logs every write operation as it happens, creating an append-only log that can replay all operations to reconstruct the dataset. This provides greater durability than RDB snapshots.
72+
73+
### AOF Configuration
74+
75+
```conf
76+
# Enable AOF
77+
appendonly yes
78+
79+
# AOF file location
80+
appendfilename "appendonly.aof"
81+
82+
# fsync policy - choose one:
83+
appendfsync always # Safest but slowest
84+
appendfsync everysec # Good balance (default)
85+
appendfsync no # Fastest but less durable
86+
```
87+
88+
### AOF fsync Policies
89+
90+
#### 1. `appendfsync always`
91+
- **Durability:** Maximum - virtually no data loss
92+
- **Performance:** Lowest - synchronous disk writes
93+
- **Data Loss Risk:** Only the latest command in case of disaster
94+
- **Best for:** Mission-critical data where no data loss is acceptable
95+
96+
#### 2. `appendfsync everysec` (Recommended)
97+
- **Durability:** High - fsync performed asynchronously every second
98+
- **Performance:** High - background thread handles disk writes
99+
- **Data Loss Risk:** Up to 1 second of writes
100+
- **Best for:** Most production use cases balancing performance and durability
101+
102+
#### 3. `appendfsync no`
103+
- **Durability:** Depends on OS (typically 30 seconds on Linux)
104+
- **Performance:** Highest - OS decides when to flush
105+
- **Data Loss Risk:** Several seconds of data in case of crashes
106+
- **Best for:** High-performance scenarios where some data loss is acceptable
107+
108+
### AOF Rewrite
109+
110+
Over time, AOF files can grow large. AOF rewrite creates a compact version:
111+
112+
```conf
113+
# Automatically trigger rewrite when file grows 100% larger
114+
auto-aof-rewrite-percentage 100
115+
auto-aof-rewrite-min-size 64mb
116+
```
117+
118+
Manual rewrite:
119+
```bash
120+
redis-cli BGREWRITEAOF
121+
```
122+
123+
## Combining RDB and AOF
124+
125+
For maximum durability, enable both mechanisms:
126+
127+
```conf
128+
# Enable both persistence methods
129+
save 900 1
130+
save 300 10
131+
save 60 10000
132+
appendonly yes
133+
appendfsync everysec
134+
```
135+
136+
On restart, FalkorDB will use the AOF file (if available) since it provides better durability guarantees.
137+
138+
## Graph-Specific Operations: DUMP and RESTORE
139+
140+
For graph-specific backup and migration scenarios, FalkorDB supports Redis's DUMP and RESTORE commands for individual keys (graphs).
141+
142+
### DUMP Command
143+
144+
Serialize a graph to a portable format:
145+
146+
```bash
147+
redis-cli DUMP mygraph > mygraph.dump
148+
```
149+
150+
The DUMP command:
151+
- Returns a serialized representation of the value at the specified key
152+
- The serialization format is opaque and specific to Redis/FalkorDB
153+
- Contains the graph structure and all its data
154+
- Does not include TTL information by default
155+
156+
Learn more: [Redis DUMP Documentation](https://redis.io/docs/latest/commands/dump/)
157+
158+
### RESTORE Command
159+
160+
Restore a serialized graph:
161+
162+
```bash
163+
redis-cli --pipe < mygraph.dump
164+
# Or directly:
165+
redis-cli RESTORE mygraph 0 "<serialized-value>"
166+
```
167+
168+
RESTORE options:
169+
- `REPLACE` - Overwrite existing key (available since Redis 3.0.0)
170+
- `ABSTTL` - TTL represents absolute Unix timestamp (since Redis 5.0.0)
171+
- `IDLETIME` - Set the idle time for the object
172+
173+
Learn more: [Redis RESTORE Documentation](https://redis.io/docs/latest/commands/restore/)
174+
175+
### Use Cases for DUMP/RESTORE
176+
177+
- **Selective backup:** Back up specific graphs rather than entire database
178+
- **Migration:** Move specific graphs between FalkorDB instances
179+
- **Testing:** Clone production graphs to test environments
180+
- **Archival:** Export graphs for long-term storage
181+
182+
**Note:** For full database backup, RDB snapshots are more efficient than individual DUMP operations.
183+
184+
## Choosing the Right Strategy
185+
186+
### High Performance, Some Data Loss Acceptable
187+
```conf
188+
save 900 1
189+
save 300 10
190+
appendonly no
191+
```
192+
193+
### Balanced Performance and Durability (Recommended)
194+
```conf
195+
save 900 1
196+
save 300 10
197+
save 60 1000
198+
appendonly yes
199+
appendfsync everysec
200+
```
201+
202+
### Maximum Durability
203+
```conf
204+
save 60 1
205+
appendonly yes
206+
appendfsync always
207+
```
208+
209+
### Development/Testing
210+
```conf
211+
save ""
212+
appendonly no
213+
```
214+
215+
## Docker Environment Persistence
216+
217+
When running FalkorDB in Docker, proper volume configuration is essential for durability. See the [Persistence on Docker](/operations/persistence) guide for detailed instructions on:
218+
219+
- Creating persistent volumes
220+
- Mounting data directories
221+
- Verifying persistence configuration
222+
- Best practices for Docker deployments
223+
224+
## Monitoring and Maintenance
225+
226+
### Check Persistence Status
227+
228+
```bash
229+
redis-cli INFO persistence
230+
```
231+
232+
### Manual Save Operations
233+
234+
```bash
235+
# Create RDB snapshot immediately (blocking)
236+
redis-cli SAVE
237+
238+
# Create RDB snapshot in background (non-blocking)
239+
redis-cli BGSAVE
240+
241+
# Rewrite AOF file
242+
redis-cli BGREWRITEAOF
243+
```
244+
245+
### Backup Best Practices
246+
247+
1. **Regular Snapshots:** Schedule periodic RDB snapshots using cron or similar
248+
2. **Off-site Backups:** Store backups in separate locations or cloud storage
249+
3. **Test Restores:** Regularly verify backups can be restored successfully
250+
4. **Monitor Disk Space:** Ensure sufficient space for both RDB and AOF files
251+
5. **Automate:** Use scripts to automate backup, verification, and rotation
252+
253+
## Performance Considerations
254+
255+
- **RDB:** Brief CPU spike and memory overhead during fork; negligible impact between snapshots
256+
- **AOF (everysec):** Minimal performance impact, ~1-2% overhead
257+
- **AOF (always):** Significant performance impact due to synchronous disk I/O
258+
- **Both RDB + AOF:** Cumulative overhead but maximum durability
259+
260+
## Further Reading
261+
262+
- [Persistence Options in Redis](https://redis.io/tutorials/operate/redis-at-scale/persistence-and-durability/persistence-options-in-redis/)
263+
- [Redis Persistence Documentation](https://redis.io/docs/management/persistence/)
264+
- [FalkorDB Docker Persistence Setup](/operations/persistence)
265+
- [FalkorDB Replication](/operations/replication)

operations/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ Table of Contents
1919

2020
Learn how to run FalkorDB using Docker and Docker Compose, with examples for development and production environments including persistence, networking, and configuration options.
2121

22-
## 2. [Configuring Persistence](/operations/persistence)
22+
## 2. [Data Durability](/operations/durability)
2323

24-
Learn how to set up FalkorDB with data persistence, ensuring that your data remains intact even after server restarts.
24+
Understand FalkorDB's durability mechanisms including RDB snapshots, AOF logging, and graph-specific backup options to balance performance and data safety.
2525

2626
## 3. [Configuring Replication](/operations/replication)
2727

operations/persistence.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
2-
title: "Persistence"
3-
nav_order: 2
2+
title: "Persistence on Docker"
3+
nav_order: 1
44
description: "Configuring FalkorDB Docker for Persistence"
5-
parent: "Operations"
5+
parent: "Durability"
6+
grand_parent: "Operations"
67
---
78

89
# Configuring FalkorDB Docker for Persistence
@@ -83,6 +84,12 @@ redis-cli GRAPH.QUERY mygraph "MATCH (n) RETURN n"
8384
- **Monitor Disk Space:** Ensure sufficient disk space is available for the volume
8485
- **Use Named Volumes:** Named volumes are easier to manage than bind mounts
8586

87+
## Understanding Durability Options
88+
89+
Docker volume configuration ensures your data persists across container restarts, but FalkorDB also provides multiple durability mechanisms (RDB snapshots, AOF logging) to protect against data loss and optimize for different use cases.
90+
91+
For a comprehensive guide on configuring RDB, AOF, and graph-specific backup options, see [Data Durability](/operations/durability).
92+
8693
## Next Steps
8794

8895
With persistence configured, FalkorDB is now set up for reliable data storage that remains intact across container restarts.

0 commit comments

Comments
 (0)