Image Generation
Architectureaiserverless
Async image jobs: queue, GPU workers, moderation, CDN delivery
Open & fork this on Zstem →Architecture
- API: Synchronous request handling
- Async Workers: Queue-driven generation pipeline
- Delivery: Stored output served from the edge
- User: Submits prompts; polls job status; views images via CDN
- API Gateway: REST API: POST /jobs to submit, GET /jobs/{id} for status
- Submit Job: Validates the prompt, records the job, enqueues the work
- Job Status: Reads job state and returns the CDN URL when complete
- Job Table: Job state machine: PENDING → RUNNING → COMPLETE/FAILED
- Job Queue: Decouples burst submissions from GPU capacity; DLQ on repeated failure
- Worker: Pulls jobs, drives the model, stores output, updates status
- Stable Diffusion: Text-to-image model endpoint
- Moderation: Scans generated images before publication
- Image Bucket: Generated images, private origin
- CloudFront: Cached, signed-URL delivery of finished images
Sequence
Participants: User, API Gateway, Submit λ, Job Table, Job Queue, Worker λ, Stable Diffusion, S3 + CloudFront
- User→API GatewayPOST /jobs {prompt}
- API Gateway→Submit λinvoke
- Submit λ→Job Tableput job PENDING
- Submit λ→Job Queueenqueue jobId
- API Gateway→User202 {jobId}
- Job Queue→Worker λdeliver job
- Worker λ→Stable Diffusiongenerate(prompt)
- Stable Diffusion→Worker λimage bytes
- Worker λ→S3 + CloudFrontstore image
- Worker λ→Job Tableupdate COMPLETE + url
- User→API GatewayGET /jobs/{id}
- API Gateway→Job Tableread status
- API Gateway→User200 {status,url}