Read replicas for MySQL, MariaDB and Valkey

A MySQL replica up to date in 12 seconds without loading its database, that catches up by itself after long downtime without losing or duplicating a row, and a Valkey replica that gets its source's users. What to know before sending your reads elsewhere.

A database linked to two smaller copies; a padlock on each link; next to the copies, lines being read

A read replica is a copy of a database, kept up to date continuously, that only serves reads. You send it reports, exports and heavy queries, through its own host name, so the database that takes the writes is not loaded. PostgreSQL has had it since late November; MySQL, MariaDB and Valkey have it since December 1, 2026, with the same API.

This article explains what a replica does for you, engine by engine, and what happens when it falls behind. The measurements come from a test bench that reproduces our production, with small databases: the timings are therefore those of a small database. The real outages, in production, are in MySQL, MariaDB, Valkey: failover in under 40 seconds.

1. What a replica changes

bash
curl -s -X POST https://api.ffxf.net/v1/databases/7/replicas \
     -H "Authorization: Bearer $FFXF_TOKEN" \
     -H "Idempotency-Key: $(uuidgen)" \
     -H "Content-Type: application/json" \
     -d '{"name": "shop-read"}'

The replica is one more database, of the same size, in the same private network, placed on other hardware whenever possible. It is billed like a database of its size (0.020 CAD an hour for 1 GB), two at most per database. It has the same users and passwords as its source, refuses every write, and has no backups of its own. replica.status goes from seeding (first copy) to streaming; replica.lag_seconds tells how far behind it is. POST …/promote turns it into an independent database, for good.

2. MySQL and MariaDB: starting from the backups

The usual way to create a MySQL replica is to copy the database live, which loads it for the whole copy. We start from what already exists instead: its backups. The replica starts from the latest backup of its source, catches up with what was written since through the write log (the binlogs), archived continuously, then follows the database directly, over TLS. During the copy, the database sees nothing more than one replication connection.

On the bench, a MySQL database of 1,000 rows, 500 of them written after its backup, gave an up-to-date replica in 12 seconds, the 500 recent rows coming from the archived log. MariaDB: 9 seconds. A large database takes longer, in proportion to its size.

3. When the replica falls behind

A replica stopped for a long time, during maintenance of its hardware for instance, no longer finds everything it missed on its source. It takes it back from the archived log, then reconnects to the database. Nothing to do on your side.

On the bench: replica stopped, 300 rows written on the source meanwhile, and the source no longer holding the matching writes. On restart, the replica caught up from the archived log and had exactly the source's 1,400 rows, no duplicates. Same result with MariaDB.

4. Valkey: the engine's own replication

Valkey replicates differently: the replica asks its source for a full copy, which comes over the network, then follows every command. On the bench, a Valkey replica was following its source within 5 to 6 seconds.

Users, on the other hand, do not go through Valkey replication: a replica delivered as is would not have its source's users, and your applications could not connect to it. So we set up the users of the followed database on the replica, with their passwords and its eviction policy, and keep them up to date.

The replication link runs over TLS, and the replica checks its source's certificate. A Valkey replica or standby can therefore be requested once the database's Let's Encrypt certificate is in place, within minutes of its creation.

5. Reading the lag

Replication is asynchronous: a read on the replica can be a moment behind the latest write. For a page that reads back what the user just saved, read from the database; for yesterday's report, the replica is fine.

6. Promoting a replica

POST …/promote cuts the link and makes the replica independent and writable. First, it applies everything it has already received: a row that reached the replica is not lost at promotion. On the bench, a MySQL replica was promoted in 3 seconds, a MariaDB one in 9. The promoted database starts its own backups right away.

7. When the followed database fails over

If the followed database has high availability and its standby takes its place, its read replicas must follow the new machine. Valkey resynchronises with the new database. PostgreSQL follows the new database, unless the replica had already received writes the standby did not have: it must then be recreated. With MySQL and MariaDB, the replica copies itself again from the first full backup of the new database, taken right after the failover. Allow a few minutes without reads on that replica; on the bench, the new copy took 10 seconds, and the size of the database sets that time.

8. Takeaways

  • A read replica exists for all four engines, two at most per database, at the price of a database of its size.
  • MySQL and MariaDB start from the backups, without loading the database; a replica that fell behind catches up by itself.
  • Valkey copies over the network, and we add the users, which its replication does not carry. The database needs its certificate before you ask for a replica.
  • Read from the replica what can be a moment behind, and from the database what the user just wrote.
  • After a failover of the followed database, a MySQL or MariaDB replica copies itself again: a few minutes without reads.

The calls are detailed in the databases documentation.

A dashed, crossed-out database on the left; an arrow to a lit database on the right; below, a timeline of writes with a short gap

MySQL, MariaDB, Valkey: failover in under 40 seconds

One database per engine, 1,500 witness rows, and the database machine stopped at once: failover in 31 to 40 seconds, no row lost. Then planned failovers of 5 to 15 seconds, and the two defects the test made us fix first.

Read the article 7 min read

An application reads a memory block marked with a lightning bolt first, over a short path; a slow database with a clock is only reached at the end of a dotted path

Managed Valkey: a Redis-compatible cache, measured

A 1 GB Valkey database and a Nano on the same private network. A 214 ms SQLite read drops to 0.17 ms once cached, a GET costs 0.1 ms over TLS, and a full database refuses writes until it moves to allkeys-lru. Numbers, clients and limits.

Read the article 8 min read

Support & discussions

Technical questions, incident reports, or infrastructure discussions, the team is reachable on Discord, Telegram, X, Instagram, Reddit, and IRC.