a month ago
## Subject
Private networking (RAILWAY_PRIVATE_DOMAIN) not resolving - causing egress charges
## Issue Description
I'm experiencing issues with Railway's private networking between services in the same project and region. The RAILWAY_PRIVATE_DOMAIN variable is not resolving correctly, forcing me to use the TCP proxy which incurs egress fees.
### Environment
- **Project:** i3atlas
- **Services affected:**
- Web application service (Next.js app)
- MongoDB database service
- **Region:** Both services deployed in the same region
- **Issue:** Private networking hostname does not resolve
### What I'm Trying to Achieve
Connect my web application to MongoDB using Railway's private networking to avoid egress fees, as recommended in Railway's documentation.
### Current Setup
**MongoDB Service Variables:**
```
MONGO_INITDB_ROOT_USERNAME=mongo
MONGO_INITDB_ROOT_PASSWORD=[password]
RAILWAY_PRIVATE_DOMAIN=[should resolve to private hostname]
MONGO_URL=mongodb://${{MONGO_INITDB_ROOT_USERNAME}}:${{MONGO_INITDB_ROOT_PASSWORD}}@${{RAILWAY_PRIVATE_DOMAIN}}:27017/i3atlas?authSource=admin
```
**App Service Variable:**
```
MONGO_URL=${{MongoDB.MONGO_URL}}
```
When MONGO_URL resolves, it becomes:
```
mongodb://mongo:[password]@mongodb.railway.internal:27017/i3atlas?authSource=admin
```
### The Problem
**Error in application logs:**
```
MongoServerSelectionError: getaddrinfo ENOTFOUND mongodb.railway.internal
at async s (.next/server/app/api/cron/update-trajectory/route.js:1:861)
code: undefined,
[cause]: MongoNetworkError: getaddrinfo ENOTFOUND mongodb.railway.internal
errorLabelSet: Set(1) { 'ResetPool' },
beforeHandshake: false,
[cause]: Error: getaddrinfo ENOTFOUND mongodb.railway.internal
errno: -3007,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'mongodb.railway.internal'
```
The hostname mongodb.railway.internal (resolved from RAILWAY_PRIVATE_DOMAIN) cannot be found via DNS lookup from my application service.
### Troubleshooting Already Done
I have verified the following:
1.
**Both services are in the same Railway project**
2.
**Both services are deployed in the same region**
3.
**MongoDB service is running and healthy**
4.
**Connection string format is correct** (works with TCP proxy)
5.
**Tried both mongodb.railway.internal and MongoDB.railway.internal** (service name with capital M)
6.
**App service has been redeployed multiple times** to pick up new variables
7.
**No duplicate environment variables**
### Current Workaround
I'm currently using the TCP proxy as a workaround:
**MongoDB Service:**
```
MONGO_URL=mongodb://${{MONGO_INITDB_ROOT_USERNAME}}:${{MONGO_INITDB_ROOT_PASSWORD}}@${{RAILWAY_TCP_PROXY_DOMAIN}}:${{RAILWAY_TCP_PROXY_PORT}}/i3atlas?authSource=admin
```
This resolves to:
```
mongodb://mongo:[password]@maglev.proxy.rlwy.net:28191/i3atlas?authSource=admin
```
**This works**, but Railway warns:
```
This variable references a public endpoint through this variable:
MONGO_URL -> MongoDB.MONGO_URL -> MongoDB.RAILWAY_TCP_PROXY_DOMAIN
Connecting to a public endpoint will incur egress fees.
```
### What I Need Help With
1. **Why is RAILWAY_PRIVATE_DOMAIN / mongodb.railway.internal not resolving** between my services?
2. **How can I enable proper private networking** to avoid egress fees?
3. **Is there a configuration or migration step required** for my project to use Railway's private networking?
4. **Is this related to Railway's V2 networking migration?** Does my project need to be migrated?
### Expected Behavior
According to Railway's documentation, services in the same project should be able to communicate via private networking using RAILWAY_PRIVATE_DOMAIN or <service-name>.railway.internal, which should not incur egress fees.
### Actual Behavior
Private networking hostnames do not resolve via DNS, resulting in ENOTFOUND errors. I'm forced to use the TCP proxy which incurs egress charges.
### Additional Context
- I previously had a working setup using the TCP proxy with MONGODB_URI
- I recently migrated to MONGO_URL to clean up variable naming
- The connection works perfectly with the TCP proxy endpoint
- Only the private networking hostname resolution is failing
### Request
Please investigate why private networking is not working for my project and provide guidance on how to enable it properly to avoid egress fees.
Thank you for your help!
5 Replies
a month ago
Hey there! We've found the following might help you get unblocked faster:
If you find the answer from one of these, please let us know by solving the thread!
a month ago
This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.
Status changed to Open brody • about 1 month ago
a month ago
Can you confirm you are using the built in MongoDB template that shows up when you right click and click Database?
samgordon
Can you confirm you are using the built in MongoDB template that shows up when you right click and click Database?
a month ago
Yes, I'm using the built-in MongoDB template. By the way, I have another railway project where I did this setup and it's working fine. However, in this project I'm having these issues.
17 days ago
Did you ever resolve this? I'm having a similar issue and, hilariously, the bot referenced this thread even though it's unresolved.
17 days ago
@jpcarreira FYI I figured it out, I had to hard code the port for the private domain. It was defaulting to 80 for whatever reason instead of the port 3000 my API was listening on. I'm not sure why the public URL automatically redirects and the private one doesn't but that fixed it for me.
