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
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
| Engine | What replica.lag_seconds means |
|---|---|
| PostgreSQL | 0 when everything received is applied, otherwise the age of the last applied transaction |
| MySQL, MariaDB | The lag reported by the engine |
| Valkey | 0 while the link is up (Valkey gives no lag in seconds), otherwise how long it has been down |
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.