Skip to main content

Architecture Overview

S-Parking leverages Google Cloud Platform’s serverless infrastructure to deliver a scalable, cost-effective parking management system. The architecture is built on Cloud Functions (2nd gen) and Firestore as the primary database.

Serverless Design

No server management required. Functions auto-scale based on demand.

Pay-per-use

Only pay for actual invocations and compute time.

Global CDN

Firebase Hosting with automatic SSL and edge caching.

Real-time Database

Firestore provides millisecond-latency queries with real-time listeners.

GCP Services Used

Cloud Functions (2nd Gen)

All backend logic runs as HTTP-triggered Cloud Functions deployed on Cloud Run. Each function is independently deployable and scalable. Key Features:
  • Concurrency: Handles multiple requests per instance
  • Cold Start Optimization: ~500ms startup time
  • CORS Support: Pre-configured for web client access
  • Environment: Node.js 20 runtime
Package Dependencies:
{
  "@google-cloud/firestore": "^7.1.0",
  "@google-cloud/functions-framework": "^3.3.0",
  "cors": "^2.8.5"
}

Firestore (Native Mode)

Firestore serves as the primary NoSQL database with three main collections:
  • parking_spots - Real-time parking spot status
  • parking_zones - Zone definitions and metadata
  • occupancy_history - Hourly snapshots for analytics
See Firestore Schema for detailed structure.

Firebase Hosting

Static assets and the web dashboard are served via Firebase Hosting:
{
  "hosting": {
    "public": ".",
    "ignore": ["gcp-functions/**", "**/node_modules/**"],
    "headers": [
      {
        "source": "**/*.html",
        "headers": [{"key": "Cache-Control", "value": "no-cache"}]
      },
      {
        "source": "js/**",
        "headers": [{"key": "Cache-Control", "value": "public, max-age=86400"}]
      }
    ]
  }
}

Firebase Authentication

Email/password authentication with custom claims for admin access. See Authentication for implementation details.

Scalability & Performance

Auto-scaling Strategy

  • Instances: 1-2 warm instances per function
  • Latency: Less than 200ms average
  • Cost: ~$5-10/month

Optimization Techniques

Client-side Caching
PERFORMANCE: {
  POLLING_INTERVAL: 20000,         // Poll every 20s
  CACHE_PARKING_STATUS: 15000,     // Cache parking status 15s
  CACHE_ZONES: 5 * 60 * 1000,      // Cache zones 5 min
  CACHE_HISTORY: 10 * 60 * 1000    // Cache history 10 min
}
Database Indexes
  • parking_spots: Indexed on status, zone_id
  • occupancy_history: Composite index on ts + zone_id
Batch Operations
const batch = firestore.batch();
expiredSpots.forEach(spot => {
  batch.update(spot.ref, { status: 1 });
});
await batch.commit();

Deployment Architecture

Regional Configuration

Primary Region: us-central1 (Iowa, USA)
  • Lowest latency for North/South America
  • Best pricing tier
  • High availability zone
Firestore Multi-region: nam5 (United States)
  • Automatic replication across multiple data centers
  • 99.999% uptime SLA

Monitoring & Logging

All functions log to Cloud Logging with structured logging:
console.log(`Reserva exitosa para ${spot_id}, Placa: ${license_plate}`);
console.warn("Error en reserva:", error.message);
console.error("🔥 ERROR CRÍTICO:", error);
Log Retention: 30 days (configurable) Alerts: Set up Cloud Monitoring alerts for:
  • Error rate > 5%
  • Latency > 1s (p95)
  • Cold starts > 100/hour

Cost Optimization

Function Optimization

  • Use connection pooling
  • Minimize cold starts
  • Set appropriate memory limits (256MB default)

Database Optimization

  • Use batch writes (saves 90% writes)
  • Implement client-side caching
  • Set up data retention policies

Hosting Optimization

  • Enable CDN caching
  • Compress assets with gzip
  • Use lazy loading for images

Monitoring Budget

  • Set up budget alerts
  • Monitor per-function costs
  • Review unused indexes
Estimated Monthly Costs (100 parking spots, 1000 daily users):
  • Cloud Functions: $15-25
  • Firestore: $10-15 (50K reads/day, 5K writes/day)
  • Firebase Hosting: $0 (under free tier)
  • Total: ~$25-40/month

Security Considerations

  • CORS: Configured to accept requests from authorized domains only
  • HTTPS Only: All traffic encrypted via TLS 1.3
  • Rate Limiting: Implemented at Cloud Functions level
  • Input Validation: All endpoints validate request parameters
  • Firestore Rules: Strict read/write rules based on authentication
See Authentication for detailed security implementation.

Build docs developers (and LLMs) love