Why this matters
Serverless on Google Cloud feels cheap at first because you pay only when code runs. The catch is that "only when code runs" has no ceiling by default. A retry loop, a misconfigured Pub/Sub subscription or a public endpoint that gets crawled can scale Cloud Run or Cloud Functions to hundreds of instances in minutes. The bill follows the traffic, not your forecast.
Predictability comes from deciding, ahead of time, how far each service is allowed to scale and how much each request is allowed to cost. Those are settings you choose, not things you measure after the invoice lands.
This guide is about the controls that sit on the services themselves: instance caps, concurrency, minimum instances, timeouts and request-level choices. Alerting and budget notifications are a separate topic, so we only touch them where they connect to these limits.
Before you start
List every serverless service you run: Cloud Run services and jobs, Cloud Functions (both generations), and anything triggered by Pub/Sub, Cloud Tasks, Eventarc or Cloud Scheduler. You can pull this from the console or with gcloud run services list and gcloud functions list. You can't cap what you haven't found.
For each one, write down three things: who owns it, what triggers it, and what it calls downstream. The downstream part matters most. A function that scales freely but writes to a database with a fixed connection limit will fail loudly or, worse, retry itself into a larger bill.
Also confirm that billing export to BigQuery is switched on for the billing account, and that your services carry labels such as team and environment. Without labels you'll see a cost spike but not know which service caused it. Adding labels later doesn't fix past data, so do it first.
How to do it
Work through the steps below one service at a time, starting with the one that has the least predictable traffic. Change one setting per deploy so you can tell which change moved the cost.
The common thread is that every knob trades money against latency or throughput. A lower instance cap is cheaper and safer, but it can queue or reject requests during a real spike. Decide per service which failure you'd rather have: a slow response or a surprise bill.
- Inventory every serverless service. List Cloud Run services and jobs and Cloud Functions in every project, with owner, trigger and downstream dependency. Anything without an owner gets one before you tune it.
- Set a maximum instance count. On Cloud Run, set max instances per service with the --max-instances flag or in the revision settings. For Cloud Functions, use the max instances option. Pick a number your database and downstream APIs can actually handle.
- Tune concurrency before raising caps. On Cloud Run, raise the concurrency setting so one instance serves many requests at once, then load test. Higher concurrency means fewer instances for the same traffic, which is usually the biggest compute saving.
- Right-size CPU, memory and timeout. Check peak memory in Monitoring and drop the allocation to just above it. Shorten the request timeout so a hung call can't bill for the full default window.
- Use minimum instances sparingly. Leave min instances at zero unless a user-facing path needs warm starts. If you do set one, note it and the reason in the service description.
- Bound retries and queues. Add a dead-letter topic and a max delivery attempts value to Pub/Sub subscriptions. Set Cloud Tasks queue rate limits and max concurrent dispatches so a backlog drains slowly instead of exploding.
- Restrict who can invoke. Remove public access with the allUsers invoker role where it isn't needed and require authentication. Put Cloud Armor or an API gateway in front of public endpoints to cut crawler and abuse traffic.
- Label and export billing data. Apply team, environment and service labels, and confirm billing export to BigQuery is running. Build one query that groups cost by label and SKU.
How to check it worked
After each change, watch the service for a full business cycle, at least a week if traffic is weekly. In Cloud Monitoring, chart container instance count, request latency and request count for the service. Your instance count should now flatten at the cap during busy periods instead of climbing past it.
Then go to the billing export in BigQuery and group cost by the service label and by SKU. Look at the Cloud Run CPU, memory and request SKUs separately. If CPU cost fell but request cost didn't, your change helped compute but the traffic itself is the driver, and you should look at caching or at who is calling the endpoint.
Run a deliberate load test against a non-production copy. Send more traffic than your cap can handle and confirm what happens: requests should queue briefly or return 429 or 503 errors, and instance count should stop at the limit. If it keeps climbing, the cap isn't applied to the revision that's actually serving.
Mistakes to avoid
The most common one is setting minimum instances "to avoid cold starts" on every service. Each minimum instance is billed for idle time. Keep it at zero for internal and low-traffic services, and use a minimum only where a user is waiting and cold starts are measurably hurting.
Another is capping instances without raising concurrency. If each instance handles one request at a time, a low cap throttles you hard. Many Node, Go and Java services handle dozens of simultaneous requests fine, so raise concurrency first and the cap can stay low.
Watch retries. Pub/Sub, Cloud Tasks and Eventarc will redeliver failed messages, and a bug can turn one bad message into a stream of paid invocations. Set a dead-letter topic and a maximum delivery attempts value so poison messages stop.
Finally, don't forget outbound traffic. A cheap function that pulls large files across regions or out to the internet can cost more in network egress than in compute. If you want a second pair of eyes on the whole bill, Cloudverg's Cloud cost audit is a read-only, two-week review at $4,500/month that ranks savings by dollars per month, though the checks above are worth doing yourself first.
Frequently asked questions
Does capping max instances break my app during a traffic spike?
It can slow it down. Once the cap is reached, Cloud Run queues requests for a short time and then returns errors if capacity doesn't free up. That's the trade for a bounded bill, so set the cap above your real peak and load test it.
Are minimum instances worth it on Cloud Run?
Only for latency-sensitive, user-facing services where cold starts are a measured problem. Idle minimum instances are billed, so for most internal or batch services, leaving the minimum at zero is cheaper and perfectly fine.
How do I find which function is driving my serverless bill?
Export billing data to BigQuery and group cost by service label and SKU. Without labels, group by project and resource name instead. Then compare instance count and request count in Cloud Monitoring for the top service.