Why is our Country Codes Directory tool showing a '504 Gateway Timeout' error after recent updates?

Author
Hana Park Author
|
6 days ago Asked
|
29 Views
|
2 Replies
0

hey guys, we've been running our 'Country Codes Directory' web tool for a while now, itโ€™s basically a comprehensive resource for international phone, calling, dialing & ISO codes. recently, we pushed some updates, mostly backend stuff and a database migration, which we thought would improve things.

but instead, we're seeing these super annoying intermittent '504 Gateway Timeout' errors. it's not constant, but during peak usage or when users hit specific search queries, especially ones that might be a bit broader, the tool just becomes unresponsive for like 30-60 seconds before timing out.

the biggest change we made was migrating our main database from MySQL to PostgreSQL. we also updated our backend framework (imagine like, an older Laravel to a newer version, or Node.js to a newer express setup). we were really hoping for a performance boost with PostgreSQL, but it seems to have introduced some new headaches for our directory.

we've tried a bunch of things already:

  • reviewed Nginx and application logs for specific errors, but often it just shows the 504.

  • gone through our database queries, added a few indexes on common search fields for the directory, and tried optimizing some of the slower ones.

  • bumped up PHP-FPM worker processes and memory limits, also checked Node.js if that was the case.

  • adjusted Nginx's proxy_read_timeout to something really high, like 120s, just to see if it was strictly an Nginx timeout.

  • monitored server ressources (CPU, RAM, and I/O) like a hawk, and honestly, they don't seem to be maxed out when these timeouts happen, which is weird.

despite all these efforts, the timeouts keep happening, especially when someone tries to query a larger dataset or apply complex filters on the country codes directory. sometimes, the logs do hint at a specific slow database call, but it's not consistent across all timeouts.

2023/10/26 14:35:12 [error] 12345#0: *6789 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 192.168.1.1, server: countrycodes.example.com, request: "GET /api/search?country=united HTTP/1.1", upstream: "http://127.0.0.1:8000/api/search?country=united"

so yeah, we're a bit stumped. has anyone here dealt with similar 504s after a database migration or framework update? any specific debugging strategies, database optimization techniques for large directory tools like ours, or even obscure server configuration tweaks that might help us get past these timeouts? help a brother out please...

2 Answers

0
MD Alamgir Hossain Nahid
Answered 5 days ago

Hey there, looks like you've been monitoring your server 'resources' (a tiny typo, but a big headache when they're not enough!).

Given the database migration to PostgreSQL and framework update, your intermittent 504 Gateway Timeouts during complex queries often point to deeper PostgreSQL performance tuning issues, not just raw server load. Focus on running EXPLAIN ANALYZE on your slowest queries to uncover inefficient query plans or missing indexes specific to your new setup, and check pg_stat_activity for active locks or long-running transactions.

Did you re-evaluate your ORM's data fetching strategy after the framework update, as an inefficient approach there can cause significant database optimization challenges?

0
Hana Park
Answered 5 days ago

MD Alamgir Hossain Nahid, YES! This is exactly the kind of direction I needed, seriously. That EXPLAIN ANALYZE on the new PostgreSQL queries... totally a facepalm moment, I genuinely overlooked doing a proper deep dive there. And the ORM strategy too, that's another big one for us to check. Appreciate you chiming in after a long day!

Your Answer

You must Log In to post an answer and earn reputation.