This page provides an overview of Append Only File (AOF) persistence for
Memorystore for Valkey.

Memorystore for Valkey also supports Redis Database (RDB) persistence, but you
must choose either the AOF or the RDB persistence mode, because you can't enable
both persistence modes at the same time. For more information about choosing
between the two modes, see [Persistence overview](https://docs.cloud.google.com/memorystore/docs/valkey/persistence-overview.md.txt).

To ensure that your instance remains resilient during [maintenance](https://docs.cloud.google.com/memorystore/docs/valkey/about-maintenance.md.txt) or unexpected failures, we recommend that in addition to
enabling AOF persistence for the instance, you use a [highly available instance](https://docs.cloud.google.com/memorystore/docs/valkey/ha-and-replicas.md.txt).

To learn how to enable, disable, and monitor AOF persistence, see [Manage persistence](https://docs.cloud.google.com/memorystore/docs/valkey/manage-persistence.md.txt).

## AOF persistence overview

The AOF persistence mode prioritizes data durability. It durably stores data by
recording every write command to a log file called the AOF file. If a system
failure or restart occurs, the server replays AOF file commands sequentially to
restore your data. Unlike RDB persistence, AOF persistence can't be paused.

If you [enable](https://docs.cloud.google.com/memorystore/docs/valkey/manage-persistence.md.txt#enable_aof_persistence_for_an_existing_instance) or [disable](https://docs.cloud.google.com/memorystore/docs/valkey/manage-persistence.md.txt#disable_aof_persistence)
AOF persistence for an instance, then you might need to perform maintenance on
the instance.

### Sync setting

The sync setting (`appendfsync`) for the AOF persistence mode determines how
often the cached data in memory is saved to durable storage. We recommend
keeping the sync setting at 1 second, which is the default. Syncing every second
provides the best compromise between the instance's performance and the
durability of the data.

Before the AOF logs are saved to durable storage, they are stored in memory by
the operating system, and if a system failure or restart occurs during this
time, the writes in memory can be lost. The sync setting lets you choose how
often data is saved to durable storage, and provides the following options:

- `always` - This option saves data to storage for every write.
- `everysec` - This option saves data to storage every second.
- `no` - This option relies on the operating system to flush data to storage on its own schedule, which typically happens every 30 seconds.

Choosing to sync for every write provides the best data durability, however this
comes with a performance tradeoff. We recommend syncing every second, which
provides both good data durability and performance.