Architecture
Faq

Frequently Asked Questions

Common questions about the AltSportsLeagues.ai architecture, deployment, and operational decisions answered clearly and concisely.

🎯 Architecture Questions

Q: Why do we use different patterns for frontend vs backend URLs?

A: Frontend keeps /api/ in the path for namespace clarity in code, while backend removes it to avoid redundancy since the api. subdomain already indicates it's an API.

Frontend: altsportsleagues.ai/api/v1/leagues - Clear it's an API call
Backend: api.altsportsleagues.ai/v1/leagues - Clean, matches industry standards

Vercel's rewrite connects them invisibly!


Q: Why not host everything on one platform (all Vercel or all Google Cloud)?

A: We use each platform's strengths:

  • Vercel - Best for static/SSR frontends (global edge, zero config for Next.js)
  • Cloud Run - Best for Python backends (containers, auto-scale to zero, long-running tasks)

Benefits:

  • Better performance (edge for static, centralized for compute)
  • Lower cost (right tool for each job)
  • Platform-specific features (Vercel previews, Cloud Run scale-to-zero)
  • Flexibility (can move services independently)

Trade-off: Slight complexity in managing two platforms, but deployment scripts handle it.


Q: What happens when the backend scales to zero?

A: Cloud Run automatically scales down to 0 instances after 5 minutes of inactivity to save costs.

First request after idle:

  • Cold start: ~1-2 seconds (our optimized Docker image)
  • Container spins up automatically
  • Request completes normally (slight delay)

Subsequent requests:

  • No cold start (container is warm)
  • Response time: ~300ms (normal)

Cost savings: You pay $0 when no one is using the API!

To disable scale-to-zero (if cold starts are an issue):

gcloud run services update altsportsleagues-backend \
  --min-instances 1 \
  --region us-central1

Q: Why use Cloudflare if Vercel and Cloud Run already have CDN/security?

A: Cloudflare provides a unified security layer across all services:

  • Single DNS management - One place to configure all subdomains
  • Extra DDoS protection - 100+ Tbps network (much larger than platform defaults)
  • WAF - Block malicious requests before they hit your infrastructure
  • Analytics - Unified view of all traffic
  • Cost: Free tier handles massive traffic

It's defense in depth - Multiple security layers protect better than one.


πŸš€ Deployment Questions

Q: How long does a typical deployment take?

Deployment times:

  • Backend (Cloud Run): 4-8 minutes (Docker build + deploy)
  • Frontend (Vercel): 2-5 minutes (Next.js build)
  • Docs (Vercel): 3-5 minutes (Nextra build + schema sync)
  • Domain mapping: 5-30 minutes (DNS propagation + SSL)

Total first-time setup: ~45-60 minutes

After first deploy:

  • Parallel deploy (backend + frontend): ~10 minutes
  • Backend only: ~8 minutes
  • Frontend only: ~5 minutes

Q: Can I deploy one service without affecting others?

A: Yes! Services are completely independent:

# Deploy only backend
./deploy-all.sh  # Option 2
 
# Deploy only frontend
./deploy-all.sh  # Option 3
 
# Deploy docs
cd apps/docs-site && vercel --prod

Frontend and docs auto-deploy on Git push (if Vercel Git integration is enabled)

Backend requires manual deployment (controlled releases)


Q: What if I need to rollback a deployment?

A: Rollback is quick and easy:

Backend (Cloud Run):

# Instant traffic switch to previous revision
gcloud run services update-traffic altsportsleagues-backend \
  --to-revisions PREVIOUS_REVISION=100 \
  --region us-central1

Frontend/Docs (Vercel):

# One command rollback
vercel rollback
 
# Or via dashboard (click "Promote to Production" on old deploy)

Zero downtime - Traffic switches instantly to previous version.


πŸ’° Cost Questions

Q: How much does this architecture cost to run?

A: Very affordable, especially early on:

Low traffic (< 10K requests/day):

  • Cloud Run: $5-20/month
  • Vercel: $0 (free tier)
  • Cloudflare: $0 (free tier)
  • Databases: $0-25/month
  • Total: $5-45/month

Medium traffic (100K requests/day):

  • Cloud Run: $20-50/month
  • Vercel: $20/month (Pro)
  • Cloudflare: $0
  • Databases: $50-100/month
  • Total: $90-170/month

High traffic (1M+ requests/day):

  • Cloud Run: $100-200/month
  • Vercel: $20/month
  • Cloudflare: $0-20/month
  • Databases: $100-300/month
  • Total: $220-540/month

Key factor: Scales with usage (pay only for what you use)


Q: Can I reduce costs further?

A: Yes! Optimization strategies:

  1. Use Cloud Run scale-to-zero (already enabled)
  2. Aggressive caching (Cloudflare + Redis)
  3. Optimize database queries (indexes, batching)
  4. Image optimization (Next.js Image component)
  5. Committed use discounts (Google Cloud, 37-55% off)
  6. Vercel free tier (100GB bandwidth is generous)

At 10K requests/day, you'll likely stay under $50/month total.


πŸ”§ Technical Questions

Q: Why FastAPI instead of Node.js/Express for the backend?

A: FastAPI is ideal for AI/ML workloads:

  • βœ… Python ecosystem - Best AI/ML libraries (OpenAI, Anthropic, transformers)
  • βœ… Async native - Handles concurrent requests efficiently
  • βœ… Auto documentation - OpenAPI/Swagger out of the box
  • βœ… Type safety - Pydantic validation
  • βœ… Performance - As fast as Node.js (async + uvloop)

Node.js would require:

  • Python interop for AI libraries (slow)
  • Manual API documentation
  • Less robust type validation

Result: FastAPI gives us Python's AI ecosystem + Node.js-like performance.


Q: Why separate docs site instead of /docs route in main app?

A: Separation provides benefits:

  • βœ… Independent deployment - Update docs without touching main app
  • βœ… Different theme - Nextra optimized for documentation
  • βœ… Performance - Static generation for all docs (fast!)
  • βœ… SEO - docs. subdomain is recognized pattern
  • βœ… Caching - Can cache docs aggressively (rarely changes)

Cost: $0 extra (Vercel free tier covers both projects)

Link between them: Main site redirects /documentation/* to docs site


Q: Do I need Neo4j AND Supabase? Why two databases?

A: Yes, each serves different purposes:

Neo4j (Graph Database):

  • Complex relationship queries (teams β†’ players β†’ leagues)
  • Path finding (player career across teams)
  • Relationship-heavy data (perfect for sports)
  • Example: "Find all players who played for 3+ teams in this league"

Supabase (PostgreSQL):

  • Structured tabular data (schedules, stats)
  • Fast indexed queries
  • Transactions and ACID guarantees
  • Example: "Get all games on 2025-11-15"

Together: Best of both worlds (graph relationships + relational efficiency)

Alternative: Could use just PostgreSQL, but graph queries would be complex and slow.


Q: What's the data_layer and why is it shared?

A: data_layer/ is our single source of truth for:

  • Schema definitions (Python + TypeScript)
  • Data models and validation
  • Shared utilities
  • Type definitions

Shared by all services:

  • Backend imports Python schemas
  • Frontend imports TypeScript types
  • Docs injects schemas into pages
  • n8n uses for validation

Benefit: Change schema once, all services stay in sync!

Example:

# In data_layer/schemas/league.py
class League(BaseModel):
    id: str
    name: str
    tier: int
// Auto-generated in TypeScript
interface League {
  id: string;
  name: string;
  tier: number;
}

Both stay synchronized automatically.


πŸ”„ Operational Questions

Q: How do I know if my deployment was successful?

A: Check these indicators:

Immediate (right after deploy):

# Backend health
curl https://api.altsportsleagues.ai/health
# Should return: {"status":"healthy"}
 
# Frontend loads
curl https://altsportsleagues.ai
# Should return: HTTP 200

Cloud Run Console:

  • Latest revision shows "Serving 100% traffic"
  • No errors in recent logs
  • Metrics show requests being handled

Vercel Dashboard:

  • Deployment status: "Ready"
  • No build errors
  • Preview works correctly

If all green βœ…, deployment succeeded!


Q: What if production breaks after I deploy?

A: Don't panic! Rollback is quick:

Backend:

# List revisions
gcloud run revisions list --service altsportsleagues-backend --region us-central1
 
# Rollback (instant traffic switch)
gcloud run services update-traffic altsportsleagues-backend \
  --to-revisions PREVIOUS_REVISION=100 \
  --region us-central1

Frontend:

vercel rollback

Recovery time: < 2 minutes

Then:

  1. Fix the issue locally
  2. Test thoroughly
  3. Deploy again

Q: How often should I deploy?

A: Depends on your needs:

Recommended:

  • Critical bugs: Immediately (after testing)
  • New features: Weekly or bi-weekly
  • Documentation: As needed (auto-deploys)
  • Dependencies: Monthly security updates

Best practice:

  • Deploy during low-traffic hours (if possible)
  • Never deploy late Friday (weekend coverage)
  • Batch small changes (less deploy overhead)
  • Monitor for 30 minutes after deploy

Continuous deployment (auto-deploy every commit) is NOT recommended for backend - manual control prevents issues.


🌍 Scaling Questions

Q: How many users can this architecture support?

A: Scales to millions of users with proper optimization:

Current configuration supports:

  • ~10K concurrent users
  • ~1M API requests/day
  • ~100K page views/day

With optimization (caching, CDN, query optimization):

  • ~100K concurrent users
  • ~10M+ API requests/day
  • ~1M+ page views/day

Bottlenecks appear at:

  • Database connections (easily fixed: connection pooling)
  • Cloud Run max instances (easily fixed: increase limit)
  • Cost (addressed with caching and committed use discounts)

Reference: Similar architectures power apps with 100M+ users (e.g., many startups on Vercel + Cloud platforms)


Q: When should I add more regions?

A: Add regions when:

  1. > 20% users outside North America with latency complaints
  2. Regulatory requirements (data residency laws)
  3. Latency SLA requires < 100ms globally
  4. High availability needs (multi-region failover)

Current setup:

  • Frontend already global (Vercel edge network)
  • Backend in us-central1 (good for US users)
  • EU/Asia users see ~150-200ms latency (acceptable for most use cases)

Cost: Multi-region backend costs 2-3x more (run in multiple regions)


Q: How do I handle database backups?

A: Automatic backups are enabled:

Neo4j:

  • Configure automated snapshots
  • Export to Cloud Storage weekly
  • Point-in-time recovery available

Supabase:

  • Daily automated backups (built-in)
  • Point-in-time recovery (7-30 days depending on plan)
  • Manual backup: Export via Supabase dashboard

Firebase:

  • Daily automated backups
  • 30-day retention
  • Export via Firebase console

Recommended:

  • Test restore procedures monthly
  • Keep backups in separate region
  • Document recovery process

πŸ” Security Questions

Q: How secure is this architecture?

A: Very secure with multiple layers of protection:

Layer 1 - Cloudflare:

  • DDoS protection (automatic)
  • WAF (blocks OWASP Top 10 attacks)
  • SSL/TLS 1.2+ (forced)

Layer 2 - Platform:

  • Vercel: Edge security, rate limiting
  • Cloud Run: IAM, VPC, service accounts

Layer 3 - Application:

  • Firebase Auth (industry standard)
  • API key validation
  • Input validation (Pydantic/Zod)
  • CORS policies

Layer 4 - Data:

  • Database encryption at rest
  • TLS for all connections
  • Row-level security (Supabase)

Compliance: Suitable for GDPR, SOC 2 (with proper configuration)


Q: What happens if someone gets my API key?

A: Immediate actions:

  1. Rotate the key immediately:

    # In Google Secret Manager or Vercel
    # Generate new key
    # Update Secret Manager
    # Redeploy services
  2. Check usage logs:

    # Find unauthorized requests
    gcloud logging read \
      'resource.type="cloud_run_revision" 
       AND textPayload=~"API_KEY_VALUE"'
  3. Block old key:

    • Remove from Secret Manager
    • Add to blocklist if applicable
  4. Monitor for 24 hours:

    • Watch for unusual activity
    • Verify new key works
    • Confirm old key is blocked

Prevention:

  • Use Secret Manager (not .env in Git)
  • Rotate keys every 90 days
  • Monitor key usage patterns
  • Use scoped keys (minimum permissions)

🧩 Integration Questions

Q: How do I add a new API endpoint?

A: Simple process:

1. Create route in backend:

# apps/backend/routers/new_feature.py
from fastapi import APIRouter
 
router = APIRouter(prefix="/v1")
 
@router.get("/new-endpoint")
async def new_endpoint():
    return {"message": "New feature!"}

2. Include router:

# apps/backend/server.py
from routers import new_feature
 
app.include_router(new_feature.router)

3. Test locally:

./deploy-local-docker.sh
curl http://localhost:8090/v1/new-endpoint

4. Deploy:

./deploy-all.sh  # Option 2

5. Use in frontend:

// Automatically available via rewrite
const data = await fetch('/api/v1/new-endpoint').then(r => r.json());

No changes needed in frontend config! Rewrite handles it automatically.


Q: How do I add a new frontend page?

A: Next.js App Router makes it easy:

1. Create page:

// clients/frontend/app/my-page/page.tsx
export default function MyPage() {
  return <div>My New Page</div>;
}

2. Test locally:

npm run dev
open http://localhost:3031/my-page

3. Deploy:

vercel --prod

That's it! Routing is automatic with App Router.

For API data:

export default async function MyPage() {
  // Fetch data (uses rewrite to backend)
  const data = await fetch('/api/v1/my-data').then(r => r.json());
  
  return <div>{JSON.stringify(data)}</div>;
}

Q: How do I update the documentation?

A: Docs auto-sync from source:

For schema documentation:

  1. Update schema in data_layer/schemas/
  2. Deploy docs site: cd apps/docs-site && vercel --prod
  3. Schema injection auto-updates content

For new doc pages:

  1. Create MDX file: apps/docs-site/pages/my-doc.mdx
  2. Add to _meta.ts for navigation
  3. Deploy: vercel --prod

For API documentation:

  • Updates automatically from FastAPI OpenAPI spec
  • No manual updates needed
  • Just deploy backend with new endpoints

Best practice: Update docs in same PR as code changes


πŸ” Debugging Questions

Q: How do I debug issues in production?

A: Use the observability tools:

Step 1: Check logs

# Backend
gcloud run services logs tail altsportsleagues-backend \
  --region us-central1 \
  --limit 100
 
# Frontend
vercel logs

Step 2: Check metrics

  • Cloud Run Console β†’ Metrics tab
  • Vercel Dashboard β†’ Analytics
  • Cloudflare Dashboard β†’ Analytics

Step 3: Reproduce locally

# Start local environment
cd apps/backend && ./deploy-local-docker.sh
cd clients/frontend && npm run dev
 
# Try to reproduce the issue
# Debug with full access to logs and tools

Step 4: Test fix

  • Fix locally first
  • Verify fix works
  • Deploy to production

Never debug directly in production!


Q: Where can I find error details?

A: Multiple sources:

Backend Errors:

# Cloud Run logs
gcloud run services logs read altsportsleagues-backend \
  --region us-central1 \
  --format "value(textPayload)" \
  | grep ERROR

Frontend Errors:

  • Vercel Dashboard β†’ Deployment β†’ Runtime Logs
  • Browser DevTools β†’ Console tab
  • Network tab for API failures

Database Errors:

  • Supabase Dashboard β†’ Logs
  • Neo4j browser β†’ Query logs
  • Firebase Console β†’ Error reporting

Best tool: Cloud Logging (aggregates all Google Cloud logs)


❓ Still Have Questions?

Can't find your answer here? Try these resources:

Platform

Documentation

Community

Support

partnership@altsportsdata.comdev@altsportsleagues.ai

2025 Β© AltSportsLeagues.ai. Powered by AI-driven sports business intelligence.

πŸ€– AI-Enhancedβ€’πŸ“Š Data-Drivenβ€’βš‘ Real-Time