Guida

Failover multi-regione con una mesh WireGuard

AvanzatoLettura di 40 minAggiornato 8 luglio 2026
Risposta breve

Tre istanze in tre paesi, collegate in mesh tramite WireGuard, con l'applicazione legata solo alla mesh e un record DNS con health check davanti, offre una vera tolleranza ai guasti per meno di $110 al mese. Il vincolo di progettazione è la replica del database: sincrona all'interno di una regione, asincrona tra le regioni.

01 Scegli tre domini di guasto indipendenti

Different countries, ideally different transit mixes. Amsterdam, Ashburn and Singapore is the classic triangle. Three is the minimum for quorum — two gives you a split-brain problem rather than redundancy.

02 Costruisci la mesh

Each node gets a stable private address. Every node peers with every other node; with three nodes that is three tunnels.

# node A — /etc/wireguard/mesh.conf
[Interface]
Address = 10.10.0.1/24
ListenPort = 51821
PrivateKey = <A private>

[Peer]                       # node B
PublicKey = <B public>
Endpoint = b.example.net:51821
AllowedIPs = 10.10.0.2/32
PersistentKeepalive = 25

[Peer]                       # node C
PublicKey = <C public>
Endpoint = c.example.net:51821
AllowedIPs = 10.10.0.3/32
PersistentKeepalive = 25

03 Collega i servizi solo alla mesh

The database, the cache and the internal API should listen on 10.10.0.x, never on the public address. This removes an entire class of exposure without a single firewall rule.

04 Replica il database in modo appropriato

Synchronous replication across regions is impractical — a 160 ms round trip becomes the floor for every write. Use asynchronous replication across regions and know your recovery point objective.

05 Health check a livello DNS

Short TTLs plus health-checked failover records, or anycast if your regions support it. Then run a failure drill: kill a region deliberately, on a weekday, while you are watching.

Domande frequenti

Perché non comprare semplicemente un server più grande?

Un server più grande ha lo stesso numero di domini di guasto di uno piccolo: uno. La disponibilità deriva dall'indipendenza, non dalla capacità.

Quanto distanti possono essere le repliche sincrone di etcd o Postgres?

Mantieni le repliche sincrone entro circa 100 ms l'una dall'altra. Oltre, la latenza di scrittura diventa il costo dominante di ogni transazione.