Skip to content

Commit d8c3530

Browse files
ericallamTrigger.dev RepoOps
authored andcommitted
fix(webapp): separate the webhook replication database connection
Add `WEBHOOK_DELIVERIES_REPLICATION_DATABASE_URL` so webhook delivery replication to ClickHouse can use a direct PostgreSQL connection with its own credentials while application queries use a pooler. When unset, replication continues to use `WEBHOOK_DATABASE_URL`, falling back to `DATABASE_URL`. Mono-RevId: 9991ab7c7dd7df8f00e3a93a94ca2b8ad02bf4cf
1 parent 0d3e54d commit d8c3530

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎apps/webapp/app/env.server.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,6 +2154,12 @@ const EnvironmentSchema = z
21542154
// slot and publication so the two consume independently. The source table is
21552155
// a partitioned parent, so the publication is created with
21562156
// publish_via_partition_root.
2157+
// Direct PostgreSQL connection with replication privileges. When unset, use the webhook
2158+
// writer URL, then DATABASE_URL; those fallbacks must also support logical replication.
2159+
WEBHOOK_DELIVERIES_REPLICATION_DATABASE_URL: z
2160+
.string()
2161+
.refine(isValidDatabaseUrl, "WEBHOOK_DELIVERIES_REPLICATION_DATABASE_URL is invalid")
2162+
.optional(),
21572163
WEBHOOK_DELIVERIES_REPLICATION_CLICKHOUSE_URL: z.string().optional(),
21582164
WEBHOOK_DELIVERIES_REPLICATION_ENABLED: z.string().default("0"),
21592165
WEBHOOK_DELIVERIES_REPLICATION_SLOT_NAME: z

‎apps/webapp/app/services/webhookDeliveriesReplicationInstance.server.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ function initializeWebhookDeliveriesReplicationInstance() {
2424

2525
const service = new WebhookDeliveriesReplicationService({
2626
clickhouseFactory,
27-
// Follows the webhook writer DB (where WebhookDelivery physically lives once split).
28-
pgConnectionUrl: env.WEBHOOK_DATABASE_URL ?? DATABASE_URL,
27+
// Replication needs a direct connection even when webhook queries use a pooler.
28+
pgConnectionUrl:
29+
env.WEBHOOK_DELIVERIES_REPLICATION_DATABASE_URL ?? env.WEBHOOK_DATABASE_URL ?? DATABASE_URL,
2930
serviceName: "webhook-deliveries-replication",
3031
slotName: env.WEBHOOK_DELIVERIES_REPLICATION_SLOT_NAME,
3132
publicationName: env.WEBHOOK_DELIVERIES_REPLICATION_PUBLICATION_NAME,

‎docs/self-hosting/env/webapp.mdx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mode: "wide"
2323
| **Postgres** | | | |
2424
| `DATABASE_URL` | Yes | — | PostgreSQL connection string. |
2525
| `DIRECT_URL` | Yes | — | Direct DB connection string used for migrations etc. |
26+
| `WEBHOOK_DELIVERIES_REPLICATION_DATABASE_URL` | No | `WEBHOOK_DATABASE_URL`, then `DATABASE_URL` | Direct PostgreSQL connection for webhook delivery replication to ClickHouse. Must target the database containing `WebhookDelivery` and use credentials with replication privileges. Set this when the webhook runtime connection uses a pooler. |
2627
| `DATABASE_CONNECTION_LIMIT` | No | 10 | Max DB connections. |
2728
| `DATABASE_POOL_TIMEOUT` | No | 60 | DB pool timeout (s). |
2829
| `DATABASE_CONNECTION_TIMEOUT` | No | 20 | DB connect timeout (s). |

0 commit comments

Comments
 (0)