リードレプリカ
読み取りに答えます。書き込みには遅れるので、一部のAPI読み取りは古い値を返します。
このページはまだ日本語に翻訳されていません。
The Read Replica stands for a PostgreSQL or MySQL streaming replica: a copy of the primary that answers reads.
When to place it#
Place it to add read capacity the Database cannot add without a restart. A resize restarts the Database and it comes back cold. A replica joins the Design and takes its share of reads while the primary keeps serving.
Place it to move reports off the primary. A report is a scan: it cannot be cached, and it evicts the Database's buffer cache. With a replica linked, scans go to the replica and the primary's other queries keep their cache.
Place it when the Database CPU is high from reads and a Cache cannot hold the hot data. A Cache answers repeated reads of hot rows; a replica answers any read, so it takes the long tail the Cache misses. Link the primary and the replicas to an L4 Load Balancer, which needs the L4 load balancer Research, and reads spread across them by its algorithm. Writes go to the primary only. With a Connection Pooler in front, link the pooler into the Load Balancer, because the pooler takes one link out.
Skip it when the mix is write-heavy. That needs a bigger primary, not more replicas.
Skip it when every read must be fresh and you have no Read-your-writes routing. A replica always lags, so some reads fail as
stale.
| Need | Use |
|---|---|
| More writes | A bigger Database, or shards |
| Fewer reads that hit hot rows | A Cache, the cheapest fix while the hot data fits |
| More reads of any row, or reports | A Read Replica |
The Stale Checkout and Missed Write Sandboxes show stale reads.
サンドボックス古いデータのチェックアウトApdexを0.9以上に90秒間保ってください。How it works#
Link the Database into the replica: that link ships the write log, and it is the only way a replica copies anything. It carries no queries. A replica with no Database linked to it takes no reads, and its Copies row is red until you link one. A replica copies one Database, so it follows that Database's engine. The App Servers, or an L4 Load Balancer, link to the replica to send it reads.
It uses the same capacity model as the Database, with an instance type and size, and it has its own connection limit. Only read queries and report scans reach it, and no Component sits downstream of it. It runs its primary's engine, so the connection limit follows the primary. Writes still go to the primary. The Database linked into it also decides its Data Group: the replica belongs to that Database's group wherever it is drawn, so the group's rows and capacity read against it.
A replica costs less than a Database. It is cheaper to place, and its box bills 30% less than a Database of the same size, because it has no backups, no provisioned IOPS tier, and no write path to size for.
Replicas lag behind the primary, and the lag grows with the write rate: 20 ms plus 2 ms for each write per second. A quarter of the reads in that window ask for a row a write just changed, so that share of reads comes back stale, up to 15%. The card shows the lag. A stale answer fails an API read and a checkout that reads its own write, though page views accept it. See replication lag.
When the primary is gone, promote one: the replica becomes the primary and the old primary becomes its replica, fenced so writes never split. A synchronous replica has no writes in flight, so nothing is lost; an asynchronous one still held writes the primary had not shipped, so promotion loses them. The new primary starts cold. See Failover.
Options#
| 設定項目 | 設定値 | 表示条件 |
|---|---|---|
| エンジン | PostgreSQL / MySQL | 常時 |
| レプリケーション | 非同期 / 同期 | 常時 |
Replication: Synchronous makes every write on the primary wait for this replica. It then serves no stale read, and while it is down every write times out. Asynchronous is the default and can lag, which is what read-your-writes routing answers. See Replication strategies.
Engine: the replica runs its primary's engine; there is nothing to pick here. Connection limits, query costs, and lag all follow the primary.
Promote: the replica becomes the primary and the old primary becomes its replica. A synchronous replica loses nothing; an asynchronous one loses writes still in flight.
How it fails#
Like every Database, it refuses connections past its limit.
Replication lag#
Signs: A burst of writes leaves the replicas seconds behind, and reads after a write come back as
staleerrors.Do now: On the App Servers that serve the reads, set the picker to Read your writes, so they send those reads to the primary. It needs Read-your-writes routing.
Prevent: Research Read-your-writes routing and turn on Read your writes on the App Servers that serve checkouts. A Synchronous replica also keeps up, with Synchronous replication.
Instance failure#
Signs: The replica's card goes grey, its Inspector reads "The host under this VM died. It still bills.", and its share of reads fails.
Do now: Press Replace in its Inspector and pay the price. It comes back cold.
Prevent: Run a second copy: Load balancing puts the copies behind a Load Balancer, and Health checks skip the dead host.
Zone outage#
Signs: Every Node in one zone goes grey at once.
Do now: Nothing brings the zone back sooner. Fail over promotes a Standby, and this Component keeps none, so it ends on its own after at most 120 s.
Prevent: Research Multiple zones, then put copies in different zones with the Zone setting.
Region outage#
Signs: Every Node in one region goes grey at once, and that region's board goes grey with them.
Do now: Nothing speeds it up. Fail over moves only Nodes that hold no data, so this one stays down until the incident ends: 180 sim seconds in the catalog, 60 once the error budget counts. A store spread across regions needs nothing from you.
Prevent: Research Multiple regions and GeoDNS, then run a copy of it in a second region.
Tips#
Turn on read-your-writes on App Servers that serve checkouts.
Link a replica from the App Servers, and reports leave the primary at once.
Buy a bigger primary, not more replicas, for a write-heavy mix.
ルール#
- 追加のコピーは 1 つ前より 25% 高くなります。
- 売却すると、最後のコピーの価格の 50% が戻ります。
- インスタンス種別がサイズと支出を決めます。サイズを 1 段上げるとリソースと支出が倍になります。
- 新しいコピーはコールドスタートで、温まるまで遅いままです。
一緒に使えるもの#
次に取るリサーチ#
リードレプリカを手に入れると、次のリサーチがそれを土台に進みます。