The app logs "Connection timed out" when connecting to the database. How do you troubleshoot?

IntermediateTroubleshootingDatabase connections in apps
Answer

Short answer

A timeout means packets are being dropped somewhere between the app and the database — almost always a network or firewall issue: security group / NSG rules, a Kubernetes NetworkPolicy, wrong subnet routing, a private endpoint/DNS mismatch, or the database not being reachable from that network at all.

Step by step (from inside the pod or app server)

nslookup db.prod.internal            # 1. resolves to the IP you expect? (private vs public!)
nc -zv db.prod.internal 5432         # 2. times out? → network path blocked

Then check, in order:

  1. Database firewall — RDS security group / Azure DB firewall / NSG allows 5432 from the app's security group or subnet.
  2. App-side egress — outbound rules, NAT, egress firewall.
  3. Kubernetes NetworkPolicy — is egress from the namespace to the DB allowed?
  4. Routing — app and DB in different VPCs/VNets? Peering or Transit Gateway routes and DNS for private endpoints.
  5. DNS — does the name resolve to a public IP while public access is disabled?

Timeout vs refused

Error Meaning
timed out Packets dropped → firewall/routing
connection refused Reached the host, nothing listening on that port → DB down / wrong port
password authentication failed Network fine → credentials

What to say in the interview

"Timeout points at the network layer. From inside the pod I check DNS resolution and nc to the port, then work through the DB's security group, NetworkPolicies, routing or peering and private DNS. A refused connection would instead mean the port isn't listening."

All Build Tools (Java, Node.js, Python, .NET) questions Roadmap: Connecting apps to databases

More on Database connections in apps