A scalable, serverless API for shortening URLs, built with Go on Cloud Run, Firestore for storage, and Redis (Memorystore) for caching. Handles 10K+ RPS with <100ms latency.
sequenceDiagram
participant C as Client
participant CR as Cloud Run (Go App)
participant R as Redis (Cache)
participant F as Firestore (DB)
Note over C, F: Shorten Flow
C->>+CR: POST /shorten { "url": "https://example.com" }
CR->>+F: Store {short_code, original_url, created_at}
F-->>-CR: Ack
CR-->>-C: { "short_url": "https://app.run.app/abc123" }
Note over C, F: Redirect Flow (with Cache)
C->>+CR: GET /abc123
CR->>+R: GET abc123 (cache check)
alt Cache Hit
R-->>-CR: "https://example.com"
CR-->>-C: 302 Redirect
else Cache Miss
R-->>-CR: Miss
CR->>+F: Get doc by short_code
F-->>-CR: {original_url}
CR->>+R: SET abc123 "https://example.com" (TTL 1h)
CR-->>-C: 302 Redirect
end