Zero-Egress Media Architecture with Supabase Storage, Sharp & Next/Image
How to build high-performance image upload and transformation pipelines using presigned S3 URLs, edge CDN caching, and zero-egress architecture.
Handling user media uploads incorrectly can quickly ruin application performance and balloon cloud infrastructure bills. Streaming multi-megabyte image uploads through an API server consumes memory, ties up Node.js event loops, and incurs double egress costs (Client → API Server → S3 Storage Bucket).
In this article, we examine how we engineered a zero-egress media pipeline using Supabase Storage (S3-compatible API), Sharp image optimization, and Next.js <Image> edge transformations.
1. Direct Presigned Browser Uploads
The core philosophy of zero-egress architecture is simple: the application server never handles raw image bytes.
Instead, the browser requests a cryptographically signed upload ticket from the backend and transfers the binary payload directly to object storage over HTTPS.
1. Browser → POST /api/storage/presign { filename: 'hero.png', mime: 'image/png' }
2. API Server → Returns presigned S3 upload URL with 60-second expiration.
3. Browser → Direct PUT request to Supabase S3 bucket.
4. Browser → POST /api/media/confirm { storagePath, alt, width, height }
// Presign route handler in NestJS
@Post('storage/presign')
@UseGuards(JwtAuthGuard)
async getPresignedUploadUrl(@Body() dto: PresignDto) {
const extension = dto.filename.split('.').pop()?.toLowerCase() || 'webp';
const uniqueKey = `blogs/${dto.slug}/${uuidv4()}.${extension}`;
const { data, error } = await this.supabase.storage
.from('portfolio-storage')
.createSignedUploadUrl(uniqueKey);
if (error) throw new InternalServerErrorException(error.message);
return { signedUrl: data.signedUrl, path: data.path };
}
2. Client-Side Pre-Processing & WebP Compression
Before initiating an upload, high-resolution camera photos (often 12MB+ JPEGs) are normalized in a browser Web Worker using the OffscreenCanvas API:
- Images are scaled down to a maximum width of 2400 pixels.
- Unnecessary EXIF metadata (GPS coordinates, camera serials) is stripped.
- Images are encoded to WebP at 85% quality, reducing payload size by 75% to 90% before transmission.
3. Global Edge CDN Delivery & Next.js <Image>
Once stored in the bucket, images are delivered through a global CDN with Cache-Control: public, max-age=31536000, immutable. Next.js transforms assets on demand, generating responsive srcset variants in modern AVIF and WebP formats with automatic blur placeholders.
This setup achieves 100/100 Google Lighthouse media performance scores while keeping server compute costs virtually at zero.


