Operations & Security
Production Deployment
Production topology, Docker, systemd, reverse proxy configuration, graceful shutdown, and upgrades.
Production Deployment Guide
This guide covers operational best practices for deploying HTTP PostgreSQL Gateway as a long-running, resilient service.
Recommended Topology
flowchart TD
CLIENT["Public Internet / Serverless Edge"] -->|HTTPS TLS 1.3| LB["Reverse Proxy / Ingress Load Balancer\n(Nginx, Caddy, Cloudflare, AWS ALB)"]
subgraph IngressRules["Ingress Functions"]
direction TB
IR1["Terminates TLS"]
IR2["Restricts /admin/* to Private/VPN"]
IR3["Forwards X-Forwarded-For"]
end
LB -.-> IngressRules
LB -->|Private HTTP| GW["Gateway Replicas (Node.js 22+)"]
GW <-->|Distributed State| REDIS[("Shared Redis\n(Rate Limiting)")]
GW -->|Private TCP / Unix Socket| PG[("PostgreSQL Database Cluster")]
Rendering diagram...
Building the Deployment Artifact
Compile TypeScript and build the production distribution:
# 1. Install production dependencies with locked versions
npm ci
# 2. Compile TypeScript
npm run build
# 3. Start production server
npm startThe runtime artifact requires:
dist/(compiled JavaScript)node_modules/(production dependencies)package.jsongateway.yaml- Writable directories for
data/andlogs/
Systemd Service Configuration
For Linux hosts, create /etc/systemd/system/http-postgres.service:
[Unit]
Description=HTTP PostgreSQL Gateway
After=network.target redis.service postgresql.service
[Service]
Type=simple
User=http-postgres
Group=http-postgres
WorkingDirectory=/opt/http-postgres
EnvironmentFile=/etc/http-postgres/gateway.env
ExecStart=/usr/bin/node dist/index.js
Restart=always
RestartSec=5
TimeoutStopSec=65
# Security sandbox
ProtectSystem=strict
ProtectHome=true
ReadWritePaths=/opt/http-postgres/data /opt/http-postgres/logs
PrivateTmp=true
NoNewPrivileges=true
[Install]
WantedBy=multi-user.targetReload and start:
sudo systemctl daemon-reload
sudo systemctl enable --now http-postgresReverse Proxy Configuration (Nginx)
# Upstream gateway cluster
upstream gateway_cluster {
server 127.0.0.1:8080;
keepalive 32;
}
server {
listen 443 ssl http2;
server_name pg-gw.internal.example.com;
ssl_certificate /etc/ssl/certs/gateway.crt;
ssl_certificate_key /etc/ssl/private/gateway.key;
# Protect administrative endpoints
location /admin/ {
allow 10.0.0.0/8; # Allow internal corporate VPN only
deny all;
proxy_pass http://gateway_cluster;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
# Public / Serverless query endpoints
location / {
proxy_pass http://gateway_cluster;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# Timeouts: Must exceed the gateway's 35-second immediate query deadline
proxy_connect_timeout 10s;
proxy_read_timeout 45s;
proxy_send_timeout 45s;
# Disable automatic POST retries!
proxy_next_upstream error timeout invalid_header;
proxy_next_upstream_tries 1;
}
}Graceful Shutdown
When receiving SIGINT or SIGTERM:
- The gateway immediately stops accepting new HTTP connections.
- Active immediate queries and in-flight transactions are granted a drain window to finish executing and committing.
- Pending role cleanup routines run.
- Active query connection pools are cleanly closed.
- A second signal forces an immediate exit.
Configure your orchestrator (Kubernetes
terminationGracePeriodSeconds or systemd TimeoutStopSec) to at least 65 seconds to allow in-flight transactions (60s max deadline) to finish committing cleanly.Backup & Disaster Recovery
| Component | Backup Procedure |
|---|---|
Key Metadata (data/data.json) | Back up on every key creation or scope edit. Encrypt at rest. |
PostgreSQL Schema (http_postgres_gateway) | Included automatically in standard PostgreSQL backups (pg_dump). |
Analytics (data/analytics/) | Ephemeral observability metrics; backup optional. |
Restore Procedure:
- Restore PostgreSQL database and confirm database identity bindings.
- Restore
data/data.jsonto the gateway host. - Start one gateway instance and verify authenticated health via
GET /admin/health. - Test a read-only query before routing write traffic.
