What is the difference between SAVE and BGSAVE in Redis, and which one should you use in production?
Answer
SAVE writes an RDB snapshot synchronously on the main thread, so Redis serves no other client until the dump finishes. BGSAVE forks a child process that writes the snapshot while the parent keeps serving requests, relying on copy-on-write memory. In production you almost always use BGSAVE; SAVE is only for cases where blocking is acceptable or forking is impossible.
How BGSAVE works under the hood
Redis calls fork(). The child gets a copy of the parent's page table, so both share the same physical memory pages.
The child iterates over the dataset and writes a temporary RDB file.
Meanwhile, when the parent modifies a page, the kernel copies that page first (copy-on-write), so the child still sees the dataset exactly as it was at fork time.
When the child finishes, it renames the temp file over dump.rdb atomically and exits. The parent logs success and updates LASTSAVE.
Because of the atomic rename, a crash during the dump never corrupts the previous good snapshot.
Side by side
SAVE
BGSAVE
Blocks clients
Yes, for the whole dump
Only during the fork call
Extra memory
None
Up to the size of pages modified during the dump
Process
Main thread
Forked child
Typical use
Shutdown, tests, last resort
Scheduled snapshots, backups, replication
The hidden costs of BGSAVE
Fork latency. Copying the page table takes time proportional to memory size. On a large instance this can pause Redis for tens or hundreds of milliseconds. Check latest_fork_usec in INFO stats.
Copy-on-write memory. A write-heavy workload during the dump can nearly double memory usage. That is why you leave headroom below physical RAM and disable Transparent Huge Pages, which make each copied page much larger.
Concurrency rules. Only one background save runs at a time. If an AOF rewrite is in progress, a plain BGSAVE returns an error; BGSAVE SCHEDULE queues it to run afterwards.
Write failures. With the default stop-writes-on-bgsave-error yes, Redis refuses writes after a failed background save, so a full disk becomes an outage you notice quickly.
When SAVE is actually used
SHUTDOWN performs a synchronous save when save points are configured, because the server is stopping anyway.
Small dev or CI instances where blocking for a few milliseconds does not matter.
Hosts where fork fails because of memory limits, as a last resort.
Automatic snapshots configured with the save directive (Redis 7 default: 3600 1 300 100 60 10000) use the background path. Check progress with INFO persistence: rdb_bgsave_in_progress, rdb_last_bgsave_status and rdb_changes_since_last_save.
What happens during BGSAVE. The parent keeps serving clients while the forked child writes the snapshot.
Client → Redis parent: BGSAVE
Redis parent → Child process: fork() with shared pages
Redis parent → Client: Background saving started
Child process → Disk: Write temp RDB file
Child process → Disk: Rename over dump.rdb
Child process → Redis parent: Exit with success status
Code examples
Triggering and monitoring a snapshot
# Start a background snapshot
redis-cli BGSAVE
# Background saving started
# Queue it if an AOF rewrite is currently running
redis-cli BGSAVE SCHEDULE
# Watch progress and result
redis-cli INFO persistence | grep -E 'rdb_bgsave_in_progress|rdb_last_bgsave_status|rdb_changes_since_last_save'
# How long did the last fork take (microseconds)?
redis-cli INFO stats | grep latest_fork_usec
# UNIX time of the last successful save
redis-cli LASTSAVE
rdb_bgsave_in_progress tells you a child is still writing. latest_fork_usec shows how long the main thread was paused by fork, which grows with dataset size.
Key points
SAVE blocks the main thread for the entire dump; BGSAVE only blocks during fork().
BGSAVE relies on copy-on-write, so write-heavy traffic during a dump increases memory use.
The RDB is written to a temp file and renamed atomically, so old snapshots stay intact on failure.
BGSAVE SCHEDULE waits for a running AOF rewrite instead of erroring.
Disable Transparent Huge Pages to keep copy-on-write overhead and fork latency low.
Common follow-up questions
Why can BGSAVE cause memory usage to nearly double?
What is latest_fork_usec and why does it grow with dataset size?
How does a replica full sync relate to BGSAVE?
What happens to writes if a background save fails?
Interview tips
Explain fork plus copy-on-write; that is the core of the answer, not just "one blocks and one does not".
Mention the real production costs: fork pause and extra memory. Interviewers love candidates who know BGSAVE is not free.
Name the INFO fields you would check; it signals hands-on experience.