Black Friday: 40% off the first year. Until Sunday 29 November, code BLACKFRIDAY40.
ZeroBehind

Home / Guides

MariaDB replication to a server behind NAT

A standby copy of a database does not have to live in a second data centre. An office server or a machine at home will do, if the two can talk. Usually they cannot: one of them sits behind a router that lets nothing in.

Why plain replication stops at the router

MariaDB replication is a connection the replica opens to the master on port 3306. That works when the master is reachable. It also means a database port open to the internet, or a VPN that somebody has to build and keep alive.

The harder case is the day the roles turn. After a switch the old master has to follow the new one, so the connection must work in the other direction too. A setup that only works one way is a standby you cannot switch to and back from.

What ZeroBehind does instead

Each server runs one agent. The agents build an encrypted WireGuard tunnel between the two servers, and replication, the control channel and the heartbeat all travel inside it.

There is no port forwarding to configure on the router and no separate VPN to maintain. Your data travels directly between your two servers; it does not pass through us.

What the link needs

Replication is asynchronous, so a slow or lossy link does not slow the master down. It only decides how far the replica can fall behind at a busy moment. The dashboard shows that gap in transactions, counted from GTID positions on both servers, together with the round trip time of the tunnel.

When the link drops, the replica reconnects by itself and continues from the transaction it stopped at. Nothing is copied again.

Measured, not promised

We run this ourselves: a public server and a home server behind NAT. Under continuous writes a planned role switch took 3.5 seconds from start to finish, the application saw a pause of under half a second, and no acknowledged write was lost. Copying 1.2 GiB to a new replica over the internet took about 30 seconds. Your numbers depend on your data and your link.

Limits worth knowing

Want to see it on your servers?

Tell us what you run. We answer with what is covered and what is not.

Talk to us

Read next