2 months ago
Both services are in Southeast Asia (Singapore), same project
(triumphant-commitment): service "web" (Django) and service "Postgres".
A bare TCP connect from web to postgres.railway.internal:5432 takes ~220ms.
I would expect sub-millisecond on the private network.
REPRODUCTION
Run in Railway -> web -> Console:
python -c "import socket,time; t=time.time(); s=socket.create_connection(('postgres.railway.internal',5432),5); print(round((time.time()-t)*1000,2)); s.close()"
Returns ~221ms every time, over many runs, at different times of day.
DNS
postgres.railway.internal resolves to fd12:b2b5:498a:1:d000:a1:ec3b:e6b2 (IPv6).
ALREADY TRIED
-
"Enable Outbound IPv6" turned on for the web service. No change.
-
Both services confirmed in the same region.
-
Django CONN_MAX_AGE=60 set, so this is not per-request connection churn
alone, but the underlying connect cost is still the floor.
IMPACT
Every Django query costs roughly 170ms. An unauthenticated endpoint that
touches no database responds in 103ms; an endpoint doing 4 queries responds
in 1,400ms. Query counts are already minimised (dashboard reduced 13 -> 4),
so application-side optimisation cannot go further.
QUESTION
Is this expected latency for the private network, or is something misrouted
for this project? Is there a way to connect over IPv4 internally, or to pin
both services to the same host/AZ?
Attachments
2 Replies
2 months ago
This thread has been opened as a bounty so the community can help solve it.
Status changed to Open Railway • about 2 months ago
2 months ago
Hi, could you try to check:
IPv4 vs IPv6: test both separately and compare latency.
TCP vs PostgreSQL: compare the raw TCP connection time with pg_isready / SELECT 1 to confirm the delay is actually connection/network overhead.
Route: run traceroute/tracepath over IPv6 if available.
If IPv4 is significantly faster, use the IPv4 private address/hostname if possible. If IPv6 is consistently ~220 ms while everything else is normal, just use the faster supported network path I guess.
2 months ago
Tested both stacks as suggested. They are the same:
DNS
IPv4 10.187.230.178
IPv6 fd12:b2b5:498a:1:d000:a1:ec3b:e6b2
Bare TCP connect, best of 5:
IPv4 248.08 ms
IPv6 239.79 ms
So this is not an IPv6 routing issue - switching stacks gains nothing, and
both are ~240ms where a same-region private connection should be under 1ms.
That points at the path itself rather than the protocol. Are the two services
actually on the same host/AZ despite both showing Southeast Asia? Is there a
way to see or influence that placement?