RDB vs AOF for Valkey: What Persistence Actually Buys a Rebuildable Cache

For a rebuildable cache, evaluating RDB vs AOF for Valkey is an operational decision about restart recovery speed and memory overhead. If your application queries an origin database to repopulate missing keys, persistence exists to protect downstream services from cold-start query spikes after a process reboot. Understanding how RDB vs AOF for Valkey behaves under memory constraints helps backend engineers avoid unexpected evictions, copy-on-write latency spikes, and storage saturation on bounded instances.

When selecting a persistence strategy for transient workloads, the first question is whether data loss on restart causes an application error or merely degraded latency. Steada is for cache, sessions, rate limiting, and low-risk metadata that can roll back—not source-of-truth data without an independent recovery path. Choosing between snapshotting, append logs, or turning off persistence entirely requires looking closely at memory consumption, disk I/O, and the operational boundaries of your hosting environment.

The decision comes before the format: can your application rebuild this data?

Engineers often treat persistence as an automatic default when deploying key-value stores. In a cache layer, persistence changes how a system behaves during maintenance cycles, restarts, or crashes, but it does not remove the need for resilient origin queries. Group data into three distinct operational classes:

  • Rebuildable cache: Data stored here originates from an underlying database, API response, or compute job. If a key is missing, the application fetches it from the origin and writes it back to Valkey. Restarting with an empty database creates a temporary origin latency spike, but data is safely repopulated.
  • Application sessions: Storing authentication tokens or user sessions in memory means an unexpected wipe logs active users out. For many consumer tools, this is an acceptable tradeoff during a scheduled migration; for operational B2B SaaS workflows, forcing active accounts to reauthenticate at once creates customer support load.
  • Rate-limit counters: Sliding-window or token-bucket counters track usage over short periods, such as sixty seconds or an hour. If the database restarts without saved state, client quotas reset to zero, allowing a brief burst of traffic past nominal limits before counters re-accumulate.

If you cannot name the application code path that repopulates a key, persistence will not protect you; an independent recovery path will. When data cannot be recovered from another store or recalculated safely, Valkey is the wrong tool for that specific dataset.

RDB vs AOF for Valkey: how the two mechanisms differ

The Valkey engine inherits two core persistence mechanisms originally developed within the Redis ecosystem: Valkey Database (RDB) snapshots and the Append-Only File (AOF). As detailed in the Valkey persistence documentation, these mechanisms work through fundamentally different system calls and runtime models.

RDB snapshots

RDB persistence produces compact, point-in-time image files of your dataset on disk at specified intervals. To create an RDB file without stopping command processing, Valkey invokes the fork() system call. This creates a child process with a duplicate virtual memory address space. The child process writes the serialized database state to a temporary file on disk, replaces the old snapshot file, and terminates.

Because the snapshot file contains only the serialized dataset at the exact moment of the fork, it is compact and optimized for rapid recovery. When a Valkey process starts up and loads an RDB file, it reads raw records directly into memory. However, any writes processed between the moment of the fork and an unexpected shutdown are lost entirely.

AOF logging

AOF persistence takes a transaction-log approach. Instead of snapshotting memory contents periodically, Valkey logs write commands received over the wire to an append-only file on disk. When the server restarts, it replays this log line by line to reconstruct the state of the keyspace.

Writing every command introduces disk overhead, so Valkey provides a background rewrite mechanism (BGREWRITEAOF). The rewrite process forks a child worker that scans memory and constructs the smallest set of commands required to recreate the current dataset. In modern Valkey releases, this rewrite can output a hybrid preamble: the start of the AOF file consists of a compact RDB snapshot, followed by raw append-log commands for subsequent writes. This provides both fast restart loading and incremental logging.

Fork mechanics and copy-on-write memory

The shared risk across both RDB saves and AOF rewrites is operating-system memory management. When Valkey calls fork(), the operating system uses copy-on-write (COW) page allocation. The parent Valkey process and child process share identical physical memory pages until the parent modifies a page to satisfy a new write command.

Under a write-heavy workload, incoming updates cause the Linux kernel to allocate private physical pages for modified memory. As documented in a technical analysis by Oneuptime on fork memory overhead, write traffic during a background save can inflate Resident Set Size (RSS) significantly. A system holding 1.5 GiB of keys on a 2 GiB machine can trigger out-of-memory kernel termination if write operations alter a large fraction of memory pages while the child process writes to disk.

When both RDB and AOF are enabled simultaneously, Valkey loads the AOF file on startup because its append-log structure contains a more complete record of past writes.

Valkey persistence settings that actually change behavior

Tuning Valkey persistence settings requires balancing I/O overhead, memory limits, and worst-case recovery windows. The engine exposes several core directives that control whether background tasks run and how data flushes to disk.

Snapshot triggers: save

The save directive configures snapshot thresholds based on elapsed seconds and accumulated write operations. For example, save 300 10 tells Valkey to fork a snapshot if at least 10 keys changed over 300 seconds. Setting save "" disables RDB snapshot generation entirely. Disabling snapshots prevents background forks from consuming transient COW memory.

The fsync spectrum: appendfsync

Writing commands to an append log does not ensure physical persistence on disk; operating systems buffer file writes in page cache. As explained in the Linux manual page for fsync(2), a flush transfers modified core data and metadata to the underlying storage device. The appendfsync parameter controls how often Valkey calls this routine:

  • appendfsync often : Valkey calls fsync() after every write command before sending a success reply. This slows command throughput by bounding operations to disk write latency.
  • appendfsync everysec: Valkey delegates fsync() to a background thread once per second. This is the standard operational default, offering microsecond command execution while limiting the unwritten buffer window to roughly one to two seconds of data.
  • appendfsync no: Valkey writes data to the OS buffer and leaves the flush timing to the operating system kernel. This reduces CPU and disk contention, but shifts the loss window to OS flush intervals, typically up to thirty seconds under Linux.

Failure thresholds: stop-writes-on-bgsave-error

By default, Valkey sets stop-writes-on-bgsave-error yes. If an RDB snapshot fork fails from memory allocation errors, full disk volumes, or permission faults, Valkey rejects incoming write commands with an error. For an application using Valkey as a session store or cache, this transforms a silent background snapshot issue into an immediate application-level write outage. In pure caching layers, administrators running unmanaged instances often turn this off, but doing so masks underlying disk starvation.

Log rewriting directives

The directives auto-aof-rewrite-percentage 100 and auto-aof-rewrite-min-size 64mb determine when Valkey triggers an automated AOF compaction. A percentage of 100 instructs the engine to fork an AOF rewrite whenever the file doubles in size relative to the previous rewrite, provided it exceeds 64 MiB. Compression can also be toggled with rdbcompression yes, trading minor CPU overhead for a smaller disk footprint.

Valkey data durability is not a binary status. It is a spectrum spanning from zero local persistence to sub-second transactional logs, as summarized below.

Persistence Mode Worst-Case Loss Window Memory Overhead (COW) Restart Loading Speed
Pure In-Memory (Disabled) All data lost on shutdown None Instant (starts empty)
RDB Snapshots (e.g., 15 min) Up to 15 minutes of writes Medium to High during save Fast (raw memory mapping)
AOF (appendfsync everysec) 1 to 2 seconds of writes Medium to High during rewrite Moderate (requires replay)
AOF Hybrid Preamble 1 to 2 seconds of writes Medium to High during rewrite Fast (RDB base + log delta)
AOF (appendfsync always) 0 seconds (disk-bounded) Severe I/O bottleneck Moderate

What persistence costs on a 256 MiB–2 GiB instance

On small instances, persistence overhead competes directly with your active dataset. Memory limits are rigid boundaries. If your keyspace consumes most available memory, invoking a snapshot pushes total allocations past the instance limit.

Consider a Valkey instance with 512 MiB of allocated memory running a high-throughput workload. The dataset contains 400 MiB of active cached records, leaving 112 MiB of free headroom. A scheduled snapshot triggers a fork(). If client applications update 150 MiB of random keys while the child process writes data to disk, copy-on-write page faults force the Linux kernel to allocate new physical memory. The total allocation exceeds 512 MiB. At this point, the host enters memory paging or the out-of-memory killer terminates the Valkey process.

Disk space presents a similar constraint. An AOF file grows steadily with every write command until a compaction rewrite runs. A 1 GiB dataset undergoing frequent updates can generate a 3 GiB raw append log before the rewrite conditions trigger. If the host disk runs out of free blocks during this process, both the rewrite and ongoing writes fail.

Steada provides managed Valkey instances across predictable tiers: Starter (256 MiB) at $49/month, Growth (512 MiB) at $89/month, Scale (1 GiB) at $149/month, and Scale+ (2 GiB) at $249/month. Check our pricing page before quoting any price. While there is no per-command surcharge on these plans, memory, connection, and compute limits still apply. When persistence is active, memory overhead must be calculated into sizing so snapshots do not trigger evictions.

Resizing an instance on a managed platform may restart the database process. Because dynamic adjustments carry this operational cost, plan memory headroom well before reaching capacity limits.

Restart behavior by workload: cache, sessions, and rate limiters

The operational cost of a restart varies depending on how the application handles an empty keyspace. When evaluating RDB vs AOF for Valkey, map the failure mode directly to the workload.

Rebuildable cache workloads

If Valkey acts as a read-through or lookaside cache for database records, a cold restart means the next wave of read requests misses the cache. This triggers a thundering herd against PostgreSQL, MySQL, or downstream microservices. Persistence mitigates this spike by repopulating keys from local disk before Valkey begins accepting network requests.

Loading a multi-gigabyte RDB or AOF log from disk takes time. During loading, Valkey returns LOADING Redis is loading the dataset in memory errors to connected clients. If your application handles LOADING errors by falling back to the database, persistence does not prevent origin load; it merely changes the error response. Cache warm-up scripts or staggered TTL patterns often provide cleaner protection than relying entirely on disk snapshots.

Session stores

For applications using Valkey for session management, an unpersisted restart logs out active users whose tokens resided only in memory. If a service restarts during peak traffic, web sessions dissolve. Enabling RDB snapshots bounded to ten-minute intervals limits this exposure to recent sessions, while AOF with appendfsync everysec limits the exposure to the last second of logins.

Even with persistence enabled, applications should handle unexpected downtime gracefully. A restart can still result in data loss if a disk error occurs or an instance experiences hardware replacement. User interfaces should handle expired or dropped session tokens by redirecting to authentication pages without throwing unhandled exceptions.

Rate limiting counters

When running a rate-limiting implementation, data loss resets counter windows. A client limited to 100 requests per minute whose counter resets to zero mid-window can send an extra burst of requests to the backend.

In most API environments, an occasional counter reset following an instance reboot is an acceptable tradeoff. Forcing continuous AOF writes for transient rate-limit keys adds disk I/O latency to API requests. Running rate-limiting databases entirely in memory absorbs minor counter resets during maintenance and avoids continuous disk write overhead.

Steada runs one Valkey instance per database without automatic replica failover. Because single-node systems undergo occasional restarts for underlying maintenance and patches, understanding your application restart behavior is an operational necessity.

The managed-service question: who operates persistence for you?

The Valkey open-source engine supports both RDB snapshots and AOF logs out of the box. However, whether those capabilities are exposed, monitored, and safely backed up depends on the hosting provider's data plane architecture. A provider that runs Valkey on a raw block storage volume without automated snapshot management leaves disaster recovery entirely in the hands of your application developers.

Durability upgrades on Steada require operator assistance; there is no instant self-service dashboard toggle. An optional durability add-on is advertised, but billing, persistence configuration, backup coverage, and restore evidence must be confirmed for the specific database before activation. Steada does not promise point-in-time recovery, zero data loss, automated restore, or an RPO/RTO.

Before moving any workload to a managed key-value provider, backend teams should ask four structural questions:

  1. Where are snapshots written? If snapshots are stored on the same ephemeral root volume as the running container, a host failure destroys both the live data and the snapshot files simultaneously.
  2. Does the persistence configuration cause write throttling? On shared disks, high-frequency AOF logging can saturate IOPS quotas, causing the managed database to delay client acknowledgments.
  3. How does the platform handle out-of-memory situations during forks? If the host enforces strict memory limits without swap, copy-on-write page allocations can cause container orchestrators to terminate the process without warning.
  4. What guarantees exist for service continuity? Steada does not offer a formal SLA or uptime guarantee. Workloads requiring multi-node consensus belong on dedicated distributed clusters, not on single-node caching tiers.

Choosing a configuration: three worked scenarios

The operational rules above translate into clear patterns across typical backend architectures.

Scenario A: rebuildable product cache (512 MiB dataset)

An e-commerce team caches serialized catalog entries, product pricing, and navigation trees. The raw data lives in PostgreSQL. All cache keys carry a TTL between one hour and one day.

Configuration: Persistence disabled entirely (save "" and appendonly no). The instance runs on Steada Growth (512 MiB) at $89/month. All 512 MiB of available instance memory holds active keys and eviction buffers without copy-on-write overhead.

Failure mode accepted: If the Valkey instance restarts, the application experiences a five-minute increase in PostgreSQL CPU usage while application workers fetch missing keys. Circuit breakers and connection pooling protect PostgreSQL from collapsing under the cold-start stampede.

Scenario B: SaaS session store (1 GiB dataset)

A B2B SaaS platform uses Valkey to store user session tokens, permissions metadata, and UI preferences. An unexpected logout of the customer base during business hours disrupts operations and generates support tickets.

Configuration: RDB snapshots enabled at conservative intervals (for example, save 900 1 and save 300 10), paired with an application fallback that re-authenticates users against a database table if a token is missing. The instance runs on Steada Scale (1 GiB) at $149/month, with the working dataset capped at 600 MiB to preserve 400 MiB for fork COW allocations.

Failure mode accepted: An unexpected host restart loses at most fifteen minutes of recently issued session tokens. Users with dropped tokens must log in again. Historical sessions and permissions load immediately from disk upon restart, preserving system stability for active users.

Scenario C: high-volume rate limiter (25