Deploy π TimescaleDB HA (Primary + Replica)
π TimescaleDB HA: Primary + Replica with Pgpool Load Balancer
timescale-proxy
Just deployed
timescale-primary
Just deployed
/var/lib/postgresql/data
timescale-replica
Just deployed
/var/lib/postgresql/data
Deploy and Host TimescaleDB Replica (PostgreSQL) on Railway
TimescaleDB Replica is an enterprise-grade time-series database solution built on PostgreSQL 17. It combines the power of SQL with high-availability (HA) architecture, featuring a primary-replica pair and a centralized proxy for intelligent connection management, ensuring your time-series workloads are always fast, stable, and resilient.
About Hosting TimescaleDB Replica (PostgreSQL)
Deploying this TimescaleDB cluster on Railway provides an out-of-the-box production environment without the operational overhead. This template utilizes a robust 3-node architecture: a Primary node for write operations, a Replica node for real-time data synchronization and heavy reads, and a Pgpool-II Proxy that acts as the intelligent gateway. The system includes an automated setup that handles replication slots, credential synchronization, and health monitoring. It also features a zero-config "Auto-Tuning" mechanism that optimizes your database parameters based on your assigned Railway resources, guaranteeing peak performance from the moment of deployment.
π Performance Benchmarks
Load Test Results (Internal Network)
| Test Scenario | Throughput | Avg Latency | Success Rate |
|---|---|---|---|
| Light Load - Simple Reads | 1,523 ops/sec | 656Β΅s | 100% |
| Light Load - Simple Writes | 892 ops/sec | 1.12ms | 100% |
| Medium Load - Mixed R/W (70/30) | 1,245 ops/sec | 803Β΅s | 99.9% |
| Medium Load - Batch Inserts | 756 ops/sec | 1.32ms | 100% |
| Heavy Load - Concurrent Reads (20 workers) | 3,456 ops/sec | 289Β΅s | 100% |
| Heavy Load - Concurrent Writes (20 workers) | 1,892 ops/sec | 528Β΅s | 99.8% |
| Stress Test - Max Throughput (50 workers) | 2,345 ops/sec | 426Β΅s | 99.8% |
| TimescaleDB - Time Series Insert | 1,678 ops/sec | 596Β΅s | 100% |
| TimescaleDB - Time Range Query | 2,134 ops/sec | 468Β΅s | 100% |
| Complex - Aggregation Queries | 456 ops/sec | 2.19ms | 100% |
Replication Lag Test (Primary β Replica)
| Metric | Value |
|---|---|
| Average Replication Lag | < 10ms |
| Minimum Replication Lag | ~2ms |
| Maximum Replication Lag | ~15ms |
| P50 (Median) Lag | ~5ms |
| P95 Lag | ~12ms |
| P99 Lag | ~14ms |
| Rating | β EXCELLENT - Replication is very fast! |
> Note: Benchmarks conducted on Railway internal network. External network performance may vary due to network latency.
Common Use Cases
- IoT & Industrial Telemetry: Ingest and analyze millions of data points per second from global sensor networks.
- Financial Market Data: Store and query high-frequency trading data, crypto prices, or transaction history with millisecond precision.
- Application Monitoring: Efficiently manage logs, metrics, and user behavior events with 10-100x better performance than standard SQL.
Dependencies for TimescaleDB Replica (PostgreSQL) Hosting
- PostgreSQL 17 Engine: The bedrock of the cluster, providing modern SQL features and security.
- TimescaleDB 2.24.0 Extension: Optimized hypertables for time-series data management.
- Pgpool-II: High-performance proxy for connection pooling and Read/Write splitting.
Deployment Dependencies
Implementation Details
To get started, you only need to configure the POSTGRES_PASSWORD environment variable. Once deployed, the cluster handles all internal communication automatically. Always connect through the Proxy node to utilize the high-availability and load-balancing features.
π°οΈ Internal / Private Connection (Recommended)
Use this for applications running within the same Railway project.
- Host:
timescale-proxy.railway.internal - Port:
5432 - User:
postgres - Password: Your
${POSTGRES_PASSWORD}
π External / Public Connection
For local development or database management tools (DBeaver/TablePlus).
- Navigate to the timescale-proxy service in Railway.
- Go to Settings > Public Networking > TCP Proxy.
- Use the generated Public Domain and Port (e.g.,
monorail.proxy.rlwy.net:12345).
Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Railway Project β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β βββββββββββββββββββ βββββββββββββββββββ β
β β timescale- β β timescale- β β
β β primary β βββββββΊ β replica β β
β β β Streamingβ β β
β β (Read/Write) β Replication (Read-Only) β β
β ββββββββββ¬βββββββββ ββββββββββ¬βββββββββ β
β β β β
β βββββββββββββ¬ββββββββββββββββ β
β β β
β ββββββββββΌβββββββββ β
β β timescale- β β
β β proxy ββββββ Your Application β
β β (Pgpool-II) β β
β β β β
β β β’ Connection β β
β β Pooling β β
β β β’ R/W Split β β
β β β’ Load Balance β β
β βββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Why Deploy TimescaleDB Replica (PostgreSQL) on Railway?
Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.
By deploying TimescaleDB Replica (PostgreSQL) on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.
π§ͺ Load Test Tool (Included)
This template includes a built-in load testing tool (loadtest-db/) that you can deploy to benchmark your cluster:
# Environment Variables
DB_HOST=timescale-proxy.railway.internal
DB_PORT=5432
DB_USER=postgres
DB_PASSWORD=${POSTGRES_PASSWORD}
# For Replication Lag Test
REPLICA_HOST=timescale-replica.railway.internal
ENABLE_REPLICATION_TEST=true
Features:
- 10 different load test scenarios
- Replication lag measurement with P50/P95/P99 statistics
- Railway-friendly logging (auto-disable colors)
Support This Project
If this template saves you time and money, consider supporting its development! β
Template Content
timescale-proxy
icueth/railsway-timescaledb-replicatimescale-primary
icueth/railsway-timescaledb-replicatimescale-replica
icueth/railsway-timescaledb-replica