Railway

Deploy πŸš€ TimescaleDB HA (Primary + Replica)

πŸš€ TimescaleDB HA: Primary + Replica with Pgpool Load Balancer

Deploy πŸš€ TimescaleDB HA (Primary + Replica)

Just deployed

Just deployed

/var/lib/postgresql/data

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 ScenarioThroughputAvg LatencySuccess Rate
Light Load - Simple Reads1,523 ops/sec656Β΅s100%
Light Load - Simple Writes892 ops/sec1.12ms100%
Medium Load - Mixed R/W (70/30)1,245 ops/sec803Β΅s99.9%
Medium Load - Batch Inserts756 ops/sec1.32ms100%
Heavy Load - Concurrent Reads (20 workers)3,456 ops/sec289Β΅s100%
Heavy Load - Concurrent Writes (20 workers)1,892 ops/sec528Β΅s99.8%
Stress Test - Max Throughput (50 workers)2,345 ops/sec426Β΅s99.8%
TimescaleDB - Time Series Insert1,678 ops/sec596Β΅s100%
TimescaleDB - Time Range Query2,134 ops/sec468Β΅s100%
Complex - Aggregation Queries456 ops/sec2.19ms100%

Replication Lag Test (Primary β†’ Replica)

MetricValue
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).

  1. Navigate to the timescale-proxy service in Railway.
  2. Go to Settings > Public Networking > TCP Proxy.
  3. 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! β˜•

Support Me


Template Content

More templates in this category

View Template
Postgres Backup to Cloudflare R2 (S3-Compatible)
Automated PostgreSQL backups to S3-compatible storage with encryption

Aman
View Template
ReadySet
A lightweight caching engine for Postgres

Milo
View Template
Simple S3
Deploy a S3-compatible storage service with a pre-named bucket.

Joey Chilson