InfraCityOpen editor

Database replication

One primary takes the writes, replicas serve the reads, and a manager promotes one if the primary dies.

Database replication, drawn as an isometric city

The CityScript

This is all there is to it. Change it in the editor and the city redraws.

%% D · Database replication
%% Writes go to the primary, reads to replicas, a pooler hides the topology, Patroni handles failover.
city 48x32

district clients "Application" 3,3..13,12
district data "Database tier" 18,3..45,19

building app factory in clients "App servers"
  floor app.f "App"
    room app.rw service "Writes" port=8080
    room app.ro service "Reads" port=8080
building pool tower in data "Connection pooler"
  floor pool.f "Pooling"
    room pool.bouncer proxy "PgBouncer" port=6432
building primary warehouse in data "Primary"
  floor primary.f "Postgres"
    room primary.pg database "Primary" port=5432
    room primary.wal queue "WAL stream"
building replica-a warehouse in data "Replica A"
  floor replica-a.f "Postgres"
    room replica-a.pg database "Replica, sync" port=5432
building replica-b warehouse in data "Replica B"
  floor replica-b.f "Postgres"
    room replica-b.pg database "Replica, async" port=5432
building patroni tower in data "Failover manager"
  floor patroni.f "Patroni"
    room patroni.agent config "Patroni"
    room patroni.etcd config "etcd" port=2379

link app.rw -> pool.bouncer -> primary.pg "writes" variant=emphasis
link app.ro -> pool.bouncer -> replica-a.pg "reads"
link primary.wal -> replica-a.pg "WAL, sync"
link primary.wal -> replica-b.pg "WAL, async" variant=dashed
link patroni.agent -> primary.pg "failover"
link patroni.etcd -> patroni.agent "leader lease"