Skip to content

Commit 64eb22c

Browse files
darorakiwicopplecharislam
authored
chore: additional Read Replica updates (supabase#22661)
* chore: additional Read Replica updates * small suggestions * fix: editing and rearrangements * fix: minor corrections --------- Co-authored-by: Copple <10214025+kiwicopple@users.noreply.github.com> Co-authored-by: Charis Lam <26616127+charislam@users.noreply.github.com>
1 parent 1ca7cc3 commit 64eb22c

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

apps/docs/content/guides/platform/read-replicas.mdx

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
---
22
title: 'Read Replicas'
3-
description: 'Deploy additional read-only databases in multiple regions for your project.'
4-
subtitle: 'Deploy additional read-only databases in multiple regions for your project'
3+
description: 'Deploy read-only databases across multiple regions, for lower latency.'
4+
subtitle: 'Deploy read-only databases across multiple regions, for lower latency and better resource management.'
55
---
66

7-
<Admonition type="note" label="Read Replicas are available to Pro, Team, and Enterprise organizations who have signed up for early access.">
7+
Read Replicas are additional databases that are kept in sync with your Primary database. You can read your data from a Read Replica, which helps with:
88

9-
[Request early access](https://forms.supabase.com/read-replica) and you'll be notified once Read Replicas are available to your organization.
10-
11-
</Admonition>
9+
- **Load balancing:** Read Replicas reduce load on the Primary database. For example, you can use a Read Replica for complex analytical queries and reserve the Primary for user-facing create, update, and delete operations.
10+
- **Improved latency:** For projects with a global user base, additional databases can be deployed closer to users to reduce latency.
11+
- **Redundancy:** Read Replicas provide data redundancy.
1212

1313
<figure className="max-w-[700px] mx-auto">
14+
1415
<Image
1516
className="hidden dark:block"
1617
alt="Map view of all project databases"
@@ -25,57 +26,74 @@ subtitle: 'Deploy additional read-only databases in multiple regions for your pr
2526

2627
</figure>
2728

28-
Read Replicas are Postgres databases that are continuously synced to a Supabase project's Primary database. You can both read from and write to a Primary database, but you can _only_ read from a Read Replica, such as using `select` statements.
29+
## About Read Replicas
30+
31+
The database you start with when launching a Supabase project is your Primary database. Read Replicas are kept in sync with the Primary through a process called "replication." Replication is asynchronous to ensure that transactions on the Primary aren't blocked. There is a delay between an update on the Primary and the time that a Read Replica receives the change. This delay is called "replication lag."
32+
33+
You can only read data from a Read Replica. This is in contrast to a Primary database, where you can both read and write:
2934

3035
| | select | insert | update | delete |
3136
| ------------ | ------ | ------ | ------ | ------ |
3237
| Primary |||||
3338
| Read Replica || - | - | - |
3439

35-
A database is spun up automatically with every Supabase project. This database is the Primary database. You can choose to add Read Replicas to your project and those Replicas will receive and synchronize data from the Primary database.
40+
## Prerequisites
3641

37-
Replication is asynchronous and happens in the background so transactions on the Primary aren't blocked. The time delay between writing data to the Primary and the Read Replica receiving the change is replication lag.
42+
<Admonition type="note" label="Read Replicas are available on the Team and Enterprise plans">
3843

39-
Read Replicas have many applications:
44+
Read replicas are available to projects created on the Teams and Enterprise plans after 2024 March 20. They will be progressively rolled out to older projects, and eventually available on the Pro plan.
4045

41-
- They reduce read load on the Primary database.
42-
- For example, you can use a Read Replica for complex analytical queries and reserve the Primary for user-facing create, update, and delete operations.
43-
- For projects that need to cover a global audience, additional databases can be deployed closer to users in any of our twelve supported regions to reduce latency.
44-
- Read Replicas provide data redundancy.
46+
If your project doesn't meet these criteria, you can join the [early access queue](https://forms.supabase.com/read-replica).
4547

46-
## Prerequisites
48+
</Admonition>
4749

48-
A project needs to satisfy these requirements to deploy a Read Replica:
50+
Projects must meet these requirements to use Read Replicas:
4951

5052
1. Running on AWS.
5153
- Support for projects on Fly.io is coming.
5254
1. Running on at least a [Small compute add-on](/docs/guides/platform/compute-add-ons).
53-
- Read Replicas are currently placed on the same compute instance as the database to make sure they can keep up with the Primary's activities.
54-
1. Running on Postgres 15.
55-
- For projects running on older versions of PostgreSQL, you will need to [upgrade to the latest platform version](/docs/guides/platform/migrating-and-upgrading-projects#pgupgrade).
55+
- Read Replicas are started on the same compute instance as the Primary to keep up with changes.
56+
1. Running on Postgres 15+.
57+
- For projects running on older versions of Postgres, you will need to [upgrade to the latest platform version](/docs/guides/platform/migrating-and-upgrading-projects#pgupgrade).
5658
1. Using [physical backups](/docs/guides/platform/backups#point-in-time-recovery)
5759
- Physical backups are automatically enabled if using [PITR](/docs/guides/platform/backups#point-in-time-recovery)
5860
- If you're not using PITR, you'll be able to switch to physical backups as part of the Read Replica setup process. Note that physical backups can't be downloaded from the dashboard in the way logical backups can.
5961

6062
## Getting started
6163

62-
Read Replicas can be managed from the [infrastructure settings page](https://supabase.com/dashboard/project/_/settings/infrastructure). For now, each project can only deploy up to two Read Replicas and all Read Replicas inherit the compute size of their Primary database.
64+
To add a Read Replica, go to the [Infrastructure Settings page](/dashboard/project/_/settings/infrastructure) in your dashboard. Each project can deploy up to two Read Replicas and all Read Replicas inherit the compute size of their Primary database.
65+
66+
## Features
6367

6468
Read Replicas offer the following features:
6569

6670
### Dedicated endpoints
6771

68-
Each Read Replica has its own dedicated database and API endpoints. The database endpoint can be found in your [dashboard database settings](https://supabase.com/dashboard/project/_/settings/database) under **Connection info**. The API endpoint can be found in [dashboard API settings](https://supabase.com/dashboard/project/_/settings/api) under **Project URL**.
72+
Each Read Replica has its own dedicated database and API endpoints.
73+
74+
- Find the database endpoint on the [Database Settings page](/dashboard/project/_/settings/database) under **Connection Info**
75+
- Find the API endpoint on the [API Settings page](/dashboard/project/_/settings/api) under **Project URL**
6976

70-
A Read Replica's API endpoint only supports `GET` requests to the [REST API](https://supabase.com/docs/guides/api). Requests towards other Supabase products, such as Auth, Storage, and Realtime, are not able to utilize a Read Replica nor its API endpoint for now. We are working on adding Read Replica support for them.
77+
Read Replicas only support `GET` requests and the [REST API](/docs/guides/api). Requests to other Supabase products, such as Auth, Storage, and Realtime, aren't able to use a Read Replica or its API endpoint. Support for more products will be added in the future.
7178

72-
### Dedicated connection pool
79+
## Dedicated connection pool
7380

74-
A connection pool through Supavisor is also available for each Read Replica. Its unique connection string can be found in your [dashboard database settings](https://supabase.com/dashboard/project/_/settings/database) under **Connection string**.
81+
A connection pool through Supavisor is also available for each Read Replica. Find the connection string on the [Database Settings page](/dashboard/project/_/settings/database) under **Connection String**.
82+
83+
## API load balancer
84+
85+
A load balancer is deployed to balance requests between your Primary database and Read Replicas. Find its endpoint on the [API Settings page](/dashboard/project/_/settings/api).
86+
87+
The load balancer uses a round-robin strategy to route `GET` requests to all available API endpoints, including the Primary database. Non-`GET` requests can also be sent through this endpoint, and will be routed to the Primary database. Read-only Postgres functions can be called using a [`GET` request](https://github.com/supabase/supabase-js/blob/v2.42.3/src/SupabaseClient.ts#L176-L177) as well.
88+
89+
If you remove all Read Replicas from your project, the load balancer and its endpoint are removed as well. Make sure to redirect requests back to your Primary database before removal.
7590

7691
### Querying through the SQL editor
7792

93+
In the SQL editor, you can choose if you want to run the query on a particular Read Replica.
94+
7895
<figure className="max-w-[700px] mx-auto">
96+
7997
<Image
8098
className="hidden dark:block"
8199
alt="SQL editor view."
@@ -90,23 +108,28 @@ A connection pool through Supavisor is also available for each Read Replica. Its
90108

91109
</figure>
92110

93-
In the SQL editor, you can choose if you want to run the query on the Primary or one of the Replicas.
111+
### Metrics
94112

95-
### API load balancer
113+
Observability and metrics for Read Replicas are not currently available in the Supabase Dashboard.
96114

97-
When Read Replicas are deployed, an API load balancer becomes available for the project. An endpoint for it is provisioned and can be found [here](https://supabase.com/dashboard/project/_/settings/api).
115+
If you're ingesting your [project's metrics](/docs/guides/platform/metrics#accessing-the-metrics-endpoint) into your own environment, you can update [your scraping setup](https://github.com/supabase/supabase-grafana?tab=readme-ov-file#read-replica-support) to additionally ingest metrics from your Read Replicas.
98116

99-
The load balancer uses a round-robin strategy to route `GET` requests to any of the API endpoints available, including that of the Primary database. Non-`GET` requests can also be sent through this endpoint. They are immediately redirected to the Primary database.
117+
### Centralized configuration management
100118

101-
Similar to the Read Replica API endpoints, only requests to the REST API are available for now. Support for other Supabase products will become available once Read Replica support has been completed for them.
119+
All settings configured through the dashboard will be propagated across all databases of a project. This ensures that no Read Replica get out of sync with the Primary database or with other Read Replicas.
102120

103-
When a project no longer has any Read Replicas, the load balancer and its endpoint are brought down as well.
121+
## Operations blocked by Read Replicas
104122

105-
### Centralized configuration management
123+
### Project upgrades and data restorations
106124

107-
All settings made through the dashboard will be propagated across all databases of a project. This ensures that no Read Replica get out of sync with its Primary database or with other Read Replicas.
125+
The following procedures require all Read Replicas for a project to be brought down before they can be performed:
108126

109-
## How are Read Replicas made?
127+
1. [Project upgrades](/docs/guides/platform/migrating-and-upgrading-projects#pgupgrade)
128+
1. [Data restorations](/docs/guides/platform/backups#pitr-restoration-process)
129+
130+
These operations need to be completed before Read Replicas can be re-deployed.
131+
132+
## About replication
110133

111134
We use a hybrid approach to replicate data from a Primary to its Read Replicas, combining the native methods of streaming replication and file-based log shipping.
112135

@@ -135,14 +158,3 @@ In this replication method, the Primary continuously buffers WAL changes to a lo
135158
We bring these two methods together to achieve quick, stable, and reliable replication. Each method addresses the limitations of the other. Streaming replication minimizes replication lag, while file-based log shipping provides a fallback. For file-based log shipping, we use our existing Point In Time Recovery (PITR) infrastructure. We regularly archive files from the Primary using [WAL-G](https://github.com/wal-g/wal-g), an open source archival and restoration tool, and ship the WAL files to S3.
136159

137160
We combine it with streaming replication to reduce replication lag. Once WAL-G files have been synced from S3, Read Replicas connect to the Primary and stream the WAL directly.
138-
139-
## Operations blocked by Read Replicas
140-
141-
### Project upgrades and data restorations
142-
143-
The following procedures require all Read Replicas for a project to be brought down before they can be performed:
144-
145-
1. [Project upgrades](/docs/guides/platform/migrating-and-upgrading-projects#pgupgrade)
146-
1. [Data restorations](/docs/guides/platform/backups#pitr-restoration-process)
147-
148-
These operations need to be completed before Read Replicas can be re-deployed.

0 commit comments

Comments
 (0)