A live demo comparing the latency of connecting colocated services on Railway with private networking versus the public internet.
🌐 Live Demo: use-the-private-network.up.railway.app
This project demonstrates the performance benefits of using Railway's private networking feature. When you colocate services on Railway, you can connect them using private networking, which is:
- Faster - Lower latency by avoiding the public internet
- More Secure - Services communicate over an isolated private network
- Cost-Effective - No egress fees for data transfer between services
This is a full-stack TanStack Start application that:
- Runs a series of database queries (10 iterations) using both private and public network connections
- Measures latency metrics for each connection type:
- Server ↔ Database query latency
- Total round-trip time
- Calculates and displays statistical comparisons:
- Average latency
- Median latency
- 95th percentile (p95) latency
- Visualizes the results with interactive bar charts
Both the application and PostgreSQL database run in the same US-East (Virginia, USA) region on Railway.
- Framework: TanStack Start - Full-stack React framework
- Runtime: Bun
- Styling: Tailwind CSS
- Database: PostgreSQL
- Charts: Recharts
- State Management: TanStack Query
src/
├── routes/
│ ├── index.tsx # Main landing page with test UI
│ └── api/
│ ├── compare-latency.tsx # Private network endpoint
│ └── compare-latency-public.tsx # Public network endpoint
├── lib/
│ └── db/
│ └── index.ts # Database connection configs
└── components/ # UI components
The app uses two separate database connections:
- Private Network:
DATABASE_URL- Uses Railway's private networking (internal connection) - Public Network:
DATABASE_PUBLIC_URL- Uses the public internet connection
Both connections query the same PostgreSQL database but take different network paths.
- Bun installed
- A Railway account (sign up at railway.com)
- A PostgreSQL database on Railway
- Clone the repository:
git clone <repository-url>
cd use-the-private-network- Install dependencies:
bun install- Set up environment variables:
# Create a .env file with:
DATABASE_URL=postgresql://... # Private network connection string. As a workaround, you can use the public connection string here for testing purposes.
DATABASE_PUBLIC_URL=postgresql://... # Public connection string- Run the development server:
bun run dev- Open http://localhost:3000 in your browser
When you run the latency test, you'll see:
- Server ↔ Database: The time it takes for a query to execute on the database
- Round-Trip Time: The total time including network overhead and API processing
- Average: Mean latency across all queries
- Median: Middle value when all latencies are sorted
- p95: 95th percentile - 95% of queries are faster than this value
Typically, the private network connection will show:
- ✅ Lower latency (often 30-50% faster)
- ✅ More consistent performance (lower variance)
- ✅ Better p95 values
The public network connection may be affected by:
- Internet routing delays
- Geographic distance (even within the same region)
- Network congestion
- Additional security layers
Deployed on Railway 🚄