Help for owners
My Google Cloud Run service is slow after idle time or times out
Short answer
Cloud Run removes idle instances, so the first request after a quiet spell waits for a new one to start. Keeping a minimum number of instances warm avoids that but is billed. A request that runs past the service's timeout, 5 minutes by default, is closed with a 504 even if the work carries on.
Does this sound like your situation?
- The first click after a quiet period takes many seconds.
- Later requests are quick.
- Some pages or reports end with a 504 error.
- A scheduled job or webhook from another service reports a timeout.
- The bill rose after someone set a minimum instance count.
Why does this happen?
Idle instances are removed
An instance that is not handling requests is idle, and Cloud Run removes idle instances unless a minimum instance setting keeps them. With none running, the next request must wait for a container to start, which is the slow first load.
Confirmed by docs.cloud.google.com
Minimum instances fix it but are billed
Minimum instances keep a set number of containers ready, which Google says helps avoid slow container start times. Those instances are billed, at a lower rate when idle under request-based billing, and always at the default rate under instance-based billing. Google describes it as a best-effort target.
Confirmed by docs.cloud.google.com
The request ran longer than the timeout
The default request timeout is 5 minutes and the maximum is 60 minutes. When it is exceeded Cloud Run closes the connection and returns HTTP 504, while the container may keep working on the aborted request.
Confirmed by docs.cloud.google.com
Another timeout is shorter than yours
Google notes that the framework inside the container and the client calling the service can have stricter limits, and services such as Pub/Sub push, Cloud Scheduler, Cloud Tasks and Workflows apply their own timeouts.
Confirmed by docs.cloud.google.com
The container itself starts slowly
Large images, heavy start-up code and slow database connections make every cold start longer. If the container fails to start at all, the technical page on listening on the right port applies.
Technical detail: Cloud Run says the container failed to start or the startup probe failed on port 8080
What can I do about it today?
- Confirm it is a cold startTry the page after ten idle minutes and again right after. If only the first is slow, it is the cold start.
- Look at the service settings in the consoleOpen the service in the Google Cloud console and note the minimum instances, the request timeout and the billing mode. Write them down before changing anything.
- Do not raise the minimum without checking the billA higher minimum keeps instances billed around the clock. Ask how many are needed and what it changes before you approve it.
- Write down which requests time outNote the page or job, how long it ran, and who called it. Long work often belongs in a background job.
- Do not delete the service or revisionsLeave revisions and settings in place so a developer can compare and roll back.
When should I bring someone in?
- Customers or partners see 504 errors or webhook failures.
- Raising the minimum instances is being considered for a service that has to stay cheap.
- Long reports or imports run inside a web request.
How do I handle it?
- Measure cold start separately from slow codeI time container start, app boot and the first request so I know which part to cut.
- Trim start-up workImage size, lazy loading, and connection set-up are reduced before any warm instances are paid for.
- Decide the minimum with the numbersI show the cost side of a warm instance next to the delay it removes, and you choose.
- Move long work off the requestReports and imports are handed to a queue or job and the page polls or emails the result, with timeouts set above the real runtime where it must stay in the request.
- Check the chainI confirm every timeout between the caller and the container, not only Cloud Run's.
The price depends on what I find, so I quote in writing after a short discovery call. Tell me what is happening and I reply within 24 hours.
What do owners ask about this?
Is a cold start a fault in my code?
Not by itself. It is what happens when no instance is running. Slow start-up code only makes it longer.
Does a 504 mean the job did not run?
Not always. Google notes the container may keep processing the aborted request, so check before retrying anything that sends money or messages.
Can I just set the timeout to the maximum?
It can hide a design problem and clients or other services may still cut the request earlier. Long work is usually better done in the background.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Found a mistake? Tell me.
For your developer: the technical fixes
Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.Cloud Run says the container failed to start or the startup probe failed on port 808014 UNAVAILABLEgRPC call to a Cloud Run service fails with 14 UNAVAILABLERoute handler stops after a fixed number of seconds on production but not locallyA Next.js route handler is cut off after a fixed time