Under the hood, Redis handles persistence using OS-level abstractions like fork() system calls, Copy-on-Write (CoW) memory management, and file system synchronization (fsync) policies.

Comparison Matrix

Architectural Feature RDB (Snapshot) AOF (Command Log) Hybrid (RDB + AOF Suffix)
Disk File Format Compressed Binary RESP Plain Text Protocol Mixed (Binary Header + Text Tail)
Disk I/O Profile Heavy, infrequent batch sequential writes. Continuous small writes (throttled via fsync). Balanced (Batch binary dump + continuous increments).
Primary OS Systems Calls fork(), write(), rename() write(), fsync() fork(), write(), fsync(), rename()
RAM Footprint (During Save) Doubles modified pages via Copy-on-Write. Low overhead (uses a minor log rewrite buffer). Doubles modified pages during binary preamble generation.
Data Loss Window Any data written since the last snapshot interval. Configurable (Typically limited to ~1 second). Configurable (Typically limited to ~1 second).
Restart Speed Extremely Fast Slow (CPU bound by single-threaded command evaluation) Fast (Near-RDB speeds)

Kubernetes Profile Setup

RDB (Snapshotting)

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-rdb-config
data:
  redis.conf: |
    # --- RDB CORE PARAMETERS ---
    # Disable AOF entirely to stop the text-logging thread
    appendonly no

    # Save snapshots based on time/change thresholds:
    # save <seconds> <changes>
    save 3600 1      # Save if 1 key changes in 1 hour
    save 300 100     # Save if 100 keys change in 5 minutes
    save 60 10000    # Save if 10,000 keys change in 1 minute

    # Binary file properties
    dbfilename dump.rdb
    dir /data

    # --- UNDER THE HOOD TUNING ---
    # Compress string objects using LZF compression inside the binary file.
    # Saves disk space but costs minor CPU cycles during the snapshot process.
    rdbcompression yes

    # Append a CRC64 checksum to the end of the file.
    # Ensures data integrity on restart but increases saving/loading time by ~10%.
    rdbchecksum yes

    # If background saving fails (e.g., disk full), stop accepting writes.
    # Protects against silent data loss notifications.
    stop-writes-on-bgsave-error yes

AOF (Append-Only File)

An AOF Rewrite is an optimization process that shrinks a bloated AOF file by removing redundant history.

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-aof-config
data:
  redis.conf: |
    # --- AOF CORE PARAMETERS ---
    # Enable the Append Only File mechanism
    appendonly yes
    appendfilename "appendonly.aof"
    dir /data

    # --- OS FSYNC TUNING ---
    # Controls how the OS forces data out of the kernel page cache to physical disk.
    # Options: **always (slowest/safest)**, **everysec (balanced default)**, **no (OS decides)**.
    appendfsync everysec

    # Prevent the main thread from calling fsync() while a background AOF rewrite 
    # (BGSAVE/BGREWRITEAOF) is heavily taxing disk I/O. Prevents performance spikes.
    no-appendfsync-on-rewrite yes

    # --- AUTOMATIC REWRITE TRIGGER METRICS ---
    # Trigger an automatic AOF rewrite when the file size grows by 100% 
    # compared to its size at the last startup/rewrite...
    auto-aof-rewrite-percentage 100
    # ...but only if the total AOF file size has surpassed 64 megabytes.
    auto-aof-rewrite-min-size 64mb

    # If the tail of the AOF file is truncated during a system crash,
    # allow Redis to load the valid prefix and log a warning instead of crashing.
    aof-load-truncated yes

Hybrid

apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-hybrid-config
data:
  redis.conf: |
    # --- HYBRID CONFIGURATION ---
    # Step 1: Ensure AOF is activated
    appendonly yes
    appendfilename "appendonly.aof"
    dir /data

    # Step 2: Instruct the background rewriter to inject the RDB binary preamble
    # When triggered, Redis dumps memory as **binary data** into the start of the AOF file,
    # then appends incoming changes as standard RESP text commands.
    aof-use-rdb-preamble yes

    # --- SYSTEM PERFORMANCE OPTIMIZATIONS ---
    # Keep the safety net at 1-second boundaries
    appendfsync everysec
    no-appendfsync-on-rewrite yes

    # Standard rewrite metrics apply here too
    auto-aof-rewrite-percentage 100
    auto-aof-rewrite-min-size 64mb

    # Active defragmentation (helps free memory layout after intense Copy-on-Write)
    activedefrag yes