Cloudflare 524s that were never Cloudflare’s fault
The problem
Intermittent 524 gateway timeouts on a large catalogue, worst under bot traffic, with the CDN getting the blame.
A 524 means your origin did not answer in time. It is a symptom with a hundred possible causes, and here it had three at once.
What was actually wrong
- An N+1 query in the category logic, cheap on a small catalogue and quadratic on a large one.
- A translation plugin making an outbound curl request that could hang, holding a PHP-FPM worker open for the full timeout.
- A background job runner firing asynchronously often enough to exhaust the FPM pool, so ordinary page requests had no worker left to serve them.
Any one of those on its own would have been findable in an afternoon. Together they masked each other, because fixing one only moved the threshold at which the next one started timing out.
Holding the line at the edge
Bot traffic was amplifying all three. The fix was a set of WAF and rate-limiting rules built within the constraints of a Free Cloudflare plan, plus pagination clamped for crawlers so that a bot walking to page 900 of a catalogue could not do it repeatedly. Cache behaviour was also corrected: unique query strings were bypassing the cache entirely and sending every crawl straight to origin.
The move
The store outgrew that hosting soon afterwards and moved to a dedicated server, which is a separate story with its own lesson in it.
The outcome
Three separate root causes identified and fixed, WAF and rate-limiting rules built inside Free plan constraints, and the site later moved onto its own server without losing its mail.
