RDB configuration (save intervals) in Redis - Time & Space Complexity
We want to understand how the time Redis takes to save data changes as the amount of data grows.
Specifically, how the save intervals in RDB configuration affect this time.
Analyze the time complexity of Redis saving snapshots based on configured save intervals.
# Example Redis config snippet for RDB save intervals
save 900 1
save 300 10
save 60 10000
# This means:
# Save after 900 seconds if at least 1 key changed
# Save after 300 seconds if at least 10 keys changed
# Save after 60 seconds if at least 10000 keys changed
This configuration controls when Redis creates a snapshot of the database based on time and number of changes.
Redis periodically checks if conditions to save are met.
- Primary operation: Copying all keys to create a snapshot (RDB save)
- How many times: Depends on how often save conditions trigger, but each save copies all keys once
When Redis saves, it copies all keys to disk. The time depends on total keys.
| Input Size (n keys) | Approx. Operations (copy keys) |
|---|---|
| 10 | 10 copies |
| 100 | 100 copies |
| 1000 | 1000 copies |
Pattern observation: The time to save grows linearly with the number of keys.
Time Complexity: O(n)
This means saving takes longer as the number of keys grows, roughly proportional to the total keys.
[X] Wrong: "Saving time depends only on the number of changed keys."
[OK] Correct: Redis saves the entire dataset snapshot, so time depends on total keys, not just changed ones.
Understanding how save intervals affect performance helps you explain trade-offs in data durability and speed.
What if Redis used incremental saving instead of full snapshots? How would the time complexity change?