Cloud Run + Firestore is the go-to stack for modern SaaS backends. Serverless, fully managed, and with a generous free tier, it scales from solo projects to production SaaS. This article walks through everything from multi-tenant design to billing with practical implementation examples.
Web/Mobile (React/Flutter)
|
Firebase Auth (認証)
|
Firebase Hosting (フロント CDN) → Cloud Run (API)
|
v
Firestore (主 DB)
Cloud Storage (ファイル)
Pub/Sub (非同期処理)
Cloud Tasks (遅延処理)
Stripe Webhook → Cloud Run
SendGrid (メール)
Cloud Scheduler (定期バッチ)// 構造
/tenants/{tenant_id}
/users/{user_id}
/subscriptions/{sub_id}
/resources/{resource_id}
// または
/tenants/{tenant_id}/{collection}/{doc}
// Security Rules (例)
match /tenants/{tenant_id}/{document=**} {
allow read, write: if request.auth.token.tenant_id == tenant_id;
}import express from "express";
import { initializeApp, applicationDefault } from "firebase-admin/app";
import { getAuth } from "firebase-admin/auth";
import { getFirestore } from "firebase-admin/firestore";
initializeApp({ credential: applicationDefault() });
const app = express();
app.use(express.json());
// Firebase Auth 検証 Middleware
app.use(async (req, res, next) => {
const idToken = req.headers.authorization?.split("Bearer ")[1];
if (!idToken) return res.status(401).send("Unauthorized");
try {
const decoded = await getAuth().verifyIdToken(idToken);
req.user = decoded;
next();
} catch (e) {
res.status(401).send("Invalid token");
}
});
app.post("/api/posts", async (req, res) => {
const db = getFirestore();
const ref = await db.collection(`tenants/${req.user.tenant_id}/posts`).add({
title: req.body.title,
authorId: req.user.uid,
createdAt: new Date(),
});
res.json({ id: ref.id });
});
app.listen(process.env.PORT || 8080);import Stripe from "stripe";
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY!);
// Checkout Session 作成
app.post("/api/checkout", async (req, res) => {
const session = await stripe.checkout.sessions.create({
mode: "subscription",
customer_email: req.user.email,
line_items: [{ price: "price_xxx", quantity: 1 }],
success_url: "https://app.example.com/success",
cancel_url: "https://app.example.com/cancel",
client_reference_id: req.user.tenant_id,
});
res.json({ url: session.url });
});
// Webhook 受信
app.post("/webhooks/stripe", express.raw({ type: "application/json" }),
async (req, res) => {
const event = stripe.webhooks.constructEvent(
req.body,
req.headers["stripe-signature"]!,
process.env.STRIPE_WEBHOOK_SECRET!
);
if (event.type === "checkout.session.completed") {
const session = event.data.object;
await getFirestore()
.collection(`tenants/${session.client_reference_id}/subscriptions`)
.doc("current")
.set({ status: "active", stripeCustomerId: session.customer });
}
res.json({ received: true });
}
);# Cloud Scheduler → Cloud Run Job 起動 gcloud scheduler jobs create http daily-backup \ --schedule="0 3 * * *" \ --uri="https://my-api.run.app/jobs/backup" \ --http-method=POST \ --oidc-service-account-email=scheduler-sa@PROJECT.iam.gserviceaccount.com
# Cloud Scheduler → Cloud Functions → Firestore Export
gcloud firestore export gs://my-backup-bucket/${TIMESTAMP} \
--collection-ids=tenants
# Lifecycle Rule で 90 日後に Archive、365 日後に削除| Service | Monthly cost |
|---|---|
| Cloud Run (~5M req/month) | ~$15 |
| Firestore (~2M read + 500K write) | ~$5 |
| Cloud Storage (10 GB) | ~$0.20 |
| Firebase Auth (10K MAU) | Free |
| Firebase Hosting | ~$0 (within free tier) |
| Cloud Logging (10 GB) | Free |
| Cloud Scheduler (1 job) | Free |
| Total | ~$20/month |
Can you build a SaaS on Cloud Run + Firestore?
Yes. With auto-scaling, fully managed services, a real-time database, and a generous free tier, you can run a SaaS serving thousands of users per month for just a few thousand yen.
What should I use for authentication?
Firebase Authentication (Google / Email / Apple / SAML, etc.) is the standard choice. You can also place IAP in front of Cloud Run for additional protection.
How should I design multi-tenancy?
Partition Firestore collections by tenant_id and enforce IAM via Security Rules. Cloud Run can stay as a single service with logical tenant isolation.
How far does it scale?
Cloud Run auto-scales to 1000 instances, Firestore handles 10K writes/s per collection, and Cloud Storage is unlimited. This stack typically handles SaaS workloads up to 100K MAU.
How do I handle subscription billing?
Stripe, Pay.jp, or Paddle are the standard options. Receive webhooks in Cloud Run and sync subscription state into Firestore.
How do I send transactional email?
SendGrid, Postmark, Resend, or Amazon SES are the standard SaaS options. Firebase Extensions also ships a SendGrid integration template.
What about backups?
For Firestore, run Managed Export daily via Cloud Scheduler and export to GCS. Point-in-time Recovery (7 days) is also enabled automatically.
How does this compare to Vercel / Netlify?
A modern setup is Vercel/Netlify for the frontend + Cloud Run for the backend + Firestore for the database. Firebase Hosting (with built-in CDN) is also a valid frontend choice.
Related articles: SaaS development
Cloud Scheduler + Cloud Functions/Run で定期バッチ自動化チュートリアル (GCP)
Google Cloud Scheduler と Cloud Functions / Cloud Run Job で定期バッチ自動化。cron 形式、OIDC 認証、リトライ、Dead Letter、Workflows 連携、Cloud Run Job 並列実行を 2026 年最新版で解説。
GCP Professional Cloud Developer (PCD) 完全ガイド|Cloud Run・GKE・CI/CD・APM
Google Cloud Professional Cloud Developer の試験範囲、Cloud Run / GKE / Cloud Build / Cloud Trace、AWS DVA / Azure AZ-204 比較、学習ロードマップを徹底解説。
Cloud Deploy 完全ガイド|Canary・Blue-Green・GKE/Cloud Run プログレッシブデプロイ (GCP)
Google Cloud Cloud Deploy の全機能解説。Delivery Pipeline、Canary / Blue-Green、Approval Gate、Verify、Skaffold 統合、GKE / Cloud Run / Anthos 対応、AWS CodeDeploy / ArgoCD 比較を網羅。
GCP Professional Cloud Network Engineer (PCNE) 完全ガイド|VPC・Interconnect・Load Balancing
Google Cloud Professional Cloud Network Engineer の試験範囲、VPC / Cloud Interconnect / Cloud Load Balancing / Cloud Armor、AWS ANS・Azure AZ-700 比較を詳解。
* Google Cloud and Firebase are trademarks of Google LLC. Stripe is a trademark of Stripe, Inc.
Practice with certification-focused question sets
View GCP exam prepNicheeLab Editorial Team
NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.
Google Cloud Certification Roadmap (2026)
Choose your GCP certification path — Foundational, Associate...
CDL Cloud Digital Leader: Complete Exam Guide (2026)
Pass the Cloud Digital Leader exam — cloud business value, G...
GAIL Generative AI Leader: Complete Exam Guide (2026)
Pass the Generative AI Leader exam — Gemini, Vertex AI, Work...
Vertex AI Fundamentals for GCP Certs (2026)
Vertex AI basics every cert candidate needs — Workbench, Pip...
Associate Cloud Engineer (ACE): Complete Guide (2026)
Pass the Associate Cloud Engineer exam — Console, gcloud, pr...