MicroPanda Intermediate 53m ago 380 views 5 likes 3 min read

Cloud Run’s new always-on instances can host a 24/7 agent for $5.70/month — here’s the catch

We tried it last quarter to replace our old polling cron job that scraped a handful of RSS feeds and dumped summaries into Slack. The previous setup lived on a t3.micro EC2 ($7.20/month on a good day), but it was a pain to patch and always needed a manual kick after a reboot. Google’s new Cloud Run instances (not the normal scale-to-zero services) looked too cheap to ignore at $5.70/month for a shared-CPU always-on container.

The tradeoff we hit first

Standard Cloud Run services are perfect for request-driven APIs, but they scale to zero when idle — nuking any background loop. That’s fine for serving a REST endpoint, but not for an agent that needs to wake up every 30 minutes and keep state between runs. We also learned the hard way that spinning up multiple instances on a traffic spike can clobber shared state files. Their docs explicitly warn against SQLite on Cloud Run volume mounts, so we switched to JSON state files stored on a mounted Cloud Storage bucket via gcs-fuse. It’s slower than local disk, but it survives restarts.

---

How we wired it

# Mount GCS bucket as local disk
gcloud run services replace service.yaml \
  --set-env-vars="STATE_BUCKET=my-agent-state" \
  --add-volume="type=gcs,storage_class=STANDARD,name=state"

The agent itself is a Python loop:

---

import time, json
from google.cloud import storage

def load_state():
    ...

It wakes, pulls the latest headlines from Hacker News and a couple of curated AI newsletters, filters out paywalled junk with a lightweight regex + readability pass, then sends the cleaned text to Gemini 2.5 Flash for summarization. We picked 2.5 Flash because the per-million-token price is $0.30 — 5x cheaper than the newer 3.5/3.6 Flash models. For our daily digest of ~10 articles, that’s under a cent of model cost per run.

---

Real-time alerts come in via POST /api/webhook. We use it for GitHub release notifications and a few Slack slash commands. The webhook handler appends payloads to the same JSON state file, and the main loop picks them up on the next cycle.

What actually got faster

  • No more babysitting the VM. The old EC2 box needed monthly security patches and a restart script. Cloud Run instances handle OS-level updates transparently.
  • Instant HTTPS endpoint. We used to front the EC2 box with a separate nginx reverse proxy for TLS. Cloud Run gives us that for free.
  • Cheaper than idle compute. At $5.70/month vs $7.20/month for the EC2 micro, the savings are modest — but the operational savings are real.
---

The pushback we got

Our security team flagged the inbound webhook as a potential SSRF vector. We mitigated it by enforcing a strict allowlist of source IPs and validating all incoming JSON against a Pydantic schema. The other complaint: gcs-fuse adds ~200ms of latency per read/write. Acceptable for our 30-minute polling cadence, but not for sub-second APIs.

Bottom line

If you need a persistent background agent and don’t mind trading raw I/O performance for zero-ops hosting, the $5.70/month Cloud Run instance is a legit option. Just remember to design your state layer for eventual consistency and keep your polling interval long enough to absorb storage latency. We’re now running three of these for different teams, and the only maintenance task is occasionally checking the monthly spend — which hasn’t budged from that $5.70 figure.


The repo we forked from Google’s devrel demos is internal, but the core pattern is public: https://github.com/GoogleCloudPlatform/devrel-demos/tree/main/ai-ml/tech-briefing-agent

WorkflowAI Implementationgooglecloud

All Replies (4)

J
JamieCrafter Advanced 50m ago
Used this for our IoT data collector — scaled down to zero during off-hours, then spun back up seamlessly when devices woke up. Saved us 60% on compute costs last month.
0 Reply
D
DrewCoder Novice 50m ago
Switched our Slack bot to Cloud Run, cut costs half and it's been rock solid.
0 Reply
I
IndieFounder Intermediate 45m ago
Nice win. Did you guys use the second gen runtimes or stick to the basics?
0 Reply
J
Jamie5 Advanced 44m ago
Ran a 24/7 agent on it for a week — concurrency tuning was the real gotcha.
0 Reply

Write a Reply

Markdown supported