Implementation Patterns: Control Plane, Data Plane, and Post Upload Validation
API Gateway Pattern
The most common pattern places URL generation behind an API gateway. Client authenticates to your API, requests a presigned URL, receives the URL for direct storage access. This centralizes authorization logic while offloading bandwidth to storage. Implementation requires: authentication middleware validating client identity, authorization logic determining access rights, URL generation with appropriate scope, and logging for audit. The API should be stateless to scale horizontally. URL generation takes 1-5ms with no storage I/O, so a single server handles 10,000+ URLs per second.
Edge Function Pattern
For latency sensitive applications, generate URLs at edge locations. A request to CDN edge triggers a serverless function that generates the presigned URL. This reduces round trip from 100-200ms to origin down to 10-30ms at edge. Challenge: edge functions need signing credentials. Options include replicating credentials to edge locations which increases attack surface, having edge call origin for signature only, or using pre-generated URL pools at edge with short expiration for predictable content.
Batch Generation Pattern
When clients need multiple URLs like a thumbnail gallery, generate in batch rather than individually. A page with 50 images should not require 50 API calls. Batch endpoint accepts list of object keys, validates authorization for all, returns all URLs in single response. Limit batch size to 100-500 URLs with rate limiting. A request for thousands of URLs could be reconnaissance probing for valid object keys.
Upload Workflow Pattern
Uploads require more than just a presigned URL. Full workflow: client requests upload URL with file metadata including name, size, and type. Server validates metadata and generates URL with content type and length conditions. Client uploads directly to storage. Storage notifies server of completion via event or webhook. Server verifies upload exists with correct size and updates database. Verification is critical. Without it, clients could claim upload complete without actually uploading or upload different content than declared.