Wandering Giants Compute · Learn
Guide

How to Build a Scalable AI Image and Video Generation Platform

The short answer

Separate the API from the GPUs. The API writes jobs to a queue such as Redis; GPU workers, one per GPU with the model preloaded, pull jobs, generate, upload results to object storage and fire a webhook. Size the fleet as arrival rate × seconds per job, plus peak headroom.

Core pattern
API → queue → pull-based GPU workers → object storage → webhook
GPUs needed (average)
Jobs per second × GPU-seconds per job
Example: 50,000 SDXL images/day
≈62.5 GPU-hours/day on RTX 4090s (estimate)
Example: 500 Wan 2.1 1.3B clips/day
≈33 GPU-hours/day on RTX 4090s (published speed)
Healthy GPU utilisation target
60–80% busy at peak
Separate pools
Image and video workers on different queues and GPUs
Image GPU / video GPU
RTX 4090 $1.59/hr / RTX PRO 6000 $4.89/hr

A single GPU running an image API is a weekend project. A platform that serves thousands of users images and video, with predictable waits, no lost jobs and a bill that tracks revenue, is an architecture problem. The answer most teams reach is the same: keep the web tier away from the GPUs, connect them with a queue, and let GPU workers pull work when they are free. This guide sets out that design, the capacity maths for sizing it, and the reliability and cost decisions that decide whether it holds up.

It builds on how to build an AI image generation API, which covers the single-GPU version, and our pillar guide to running Stable Diffusion on a cloud GPU.

What does the architecture of a generation platform look like?

A scalable image and video platform has six layers: an API gateway, a job store, a queue, GPU workers, object storage and notifications. GPUs only ever talk to the queue, the job store and storage.

LayerResponsibilityTypical tools
API gatewayAuth, validation, rate limits, pricing, job creationFastAPI, Node, Go; any web framework
Job storeJob state, ownership, history, usage recordsPostgres, Redis
QueueOrdered work, priorities, back-pressureRedis lists or streams, Postgres SKIP LOCKED, SQS, RabbitMQ
GPU workersOne per GPU: model preloaded, pull a job, generate, uploadPython + diffusers or ComfyUI headless
Object storage + CDNDurable outputs, fast deliveryAny S3-compatible store and CDN
NotificationsTell the client it is doneWebhooks, server-sent events, WebSockets

The flow for one request: the client calls POST /generate; the gateway checks the key and the user's quota, writes a job row, pushes the job id onto the right queue and returns 202 with the id. A free worker pops the job, marks it running, generates, uploads the result, marks it done with the URL and fires the webhook. The client either receives the webhook or polls the job.

Why should GPU workers pull jobs rather than be load-balanced?

Pull-based workers take a job only when they are free, which suits work that takes seconds to minutes and uses a whole GPU. A load balancer spreading HTTP requests cannot see that one GPU is halfway through a 10-minute video and another is idle.

Pulling gives you four things almost for free:

  • No overload. A worker never holds more jobs than it can run.
  • Elastic fleet. Start a new GPU worker and it begins pulling; stop one and it simply stops. No reconfiguration.
  • Priorities. Workers check the high-priority queue first.
  • Resilience. If a worker dies, its job can be returned to the queue and picked up elsewhere.

A minimal worker with Redis looks like this:

python
# worker.py — one process per GPU; CUDA_VISIBLE_DEVICES selects the card
import json, os, socket, time, redis, torch
from diffusers import StableDiffusionXLPipeline

r = redis.Redis(host=os.environ["REDIS_HOST"], password=os.environ.get("REDIS_PASSWORD"))
QUEUES = ["q:image:paid", "q:image:free"]          # checked in this order
WORKER = f"{socket.gethostname()}:{os.environ.get('CUDA_VISIBLE_DEVICES', '0')}"

pipe = StableDiffusionXLPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0",
    torch_dtype=torch.float16, variant="fp16").to("cuda")

def upload(path: str) -> str:
    ...  # put the file in object storage, return a signed or CDN URL

while True:
    _, raw = r.blpop(QUEUES)                       # blocks until a job arrives
    job = json.loads(raw)
    key = f"job:{job['id']}"
    r.hset(key, mapping={"status": "running", "worker": WORKER, "started": time.time()})
    try:
        img = pipe(job["prompt"], num_inference_steps=job.get("steps", 30)).images[0]
        path = f"/tmp/{job['id']}.png"
        img.save(path)
        r.hset(key, mapping={"status": "done", "url": upload(path), "finished": time.time()})
    except Exception as exc:
        r.hset(key, mapping={"status": "error", "error": str(exc)[:500]})

BLPOP across several keys checks them in the order given, which gives simple priority. It removes the job from the queue as it hands it over, so a worker that crashes mid-job loses that job. For at-least-once delivery, use BLMOVE to move each job into a per-worker processing list and remove it only when done, or use Redis Streams with consumer groups, or Postgres with SELECT ... FOR UPDATE SKIP LOCKED. Make jobs idempotent (writing the same output twice is harmless) so retries are safe.

How do you size the GPU fleet?

GPUs busy on average = jobs per second × GPU-seconds per job. Size for the peak, not the average, and aim for about 60–80% utilisation at peak so queues stay short.

Worked example 1: images. A product makes 50,000 SDXL images a day, each about 4.5 GPU-seconds on an RTX 4090 (our rough estimate from published community figures, not a measurement).

StepFormulaResult
Average arrival rate50,000 ÷ 86,400 s0.58 jobs/s
Average GPUs busy0.58 × 4.52.6 GPUs
GPU-hours per day50,000 × 4.5 ÷ 3,60062.5 GPU-hours
Peak rate (assume 3× average)0.58 × 31.74 jobs/s
GPUs busy at peak1.74 × 4.57.8 GPUs
Fleet at peak for 70% utilisation7.8 ÷ 0.7≈11 RTX 4090s

Worked example 2: video. 500 Wan 2.1 1.3B clips a day at about 4 minutes each on an RTX 4090 (the Wan team's published figure for 480p): 500 × 4 ÷ 60 = 33 GPU-hours a day, or about 1.4 GPUs busy on average. Video demand is lumpier, so plan on 3–4 GPUs at peak and accept that users wait minutes, not seconds.

The gap between example 1's average of 2.6 busy GPUs and its peak fleet of 11 is the central cost problem of generation platforms. Keep 11 GPUs on all day and average utilisation is about 24%. The next section is about closing that gap.

How do you avoid paying for idle GPUs?

Run a base fleet for normal load, queue short spikes, and add GPUs for sustained peaks. Idle capacity is the biggest avoidable cost in this kind of platform.

StrategyHow it worksTrade-off
Base + scheduled peakKeep 4 GPUs on; add 6 more for the hours your traffic peaksNeeds predictable daily patterns
Queue absorptionLet short spikes wait; show honest ETAsUsers wait longer during spikes
Tiered priorityPaid users on the priority queue; free tier waitsFree users get slower service
Burst to serverlessOverflow jobs go to a scale-to-zero GPU serviceHigher price per GPU-hour, cold starts
Cheaper models for draftsFLUX.1 [schnell] previews, [dev]-class or larger models only on requestTwo model pools to run

Cost for example 1, using our prices and the 62.5 GPU-hours of real work a day:

Fleet planGPU-hours paid per dayUtilisationOur daily GPU cost
Ideal (pay only for work)62.5100%62.5 × $1.59/hr ≈ $99.38
4 always on + 6 for 8 peak hours96 + 48 = 14443%144 × $1.59/hr ≈ $228.96
11 always on26424%264 × $1.59/hr ≈ $419.76

The middle plan costs a little over half of the always-on plan and keeps peak waits short. GPU utilisation and cost efficiency covers more of these levers.

Should image and video share GPUs?

No. Run separate queues and worker pools. Image jobs take seconds on 24 GB cards; video jobs take minutes and want 48–96 GB. If they share workers, one video job blocks dozens of images and image latency becomes unpredictable.

PoolTypical GPUPriceJob timeQueue
Image (SDXL, FP8 FLUX)RTX 4090 (24 GB)$1.59/hr1–20 sq:image:*
Image (BF16 FLUX, SD 3.5 Large)L40S (48 GB)$1.89/hr3–20 sq:image-large:*
Video (14B-class models)RTX PRO 6000 (96 GB) or H100 (80 GB)$4.89/hr / $4.99/hr5–40 minq:video:*

For video, also consider splitting one clip across several GPUs for faster turnaround, as shown in how to run open-source AI video models in the cloud, and checkpointing long jobs so a failure late in a 30-minute render does not start from zero. Hardware choices for each pool are discussed in what GPU you need for AI video generation.

How do you manage models and LoRAs across workers?

Bake models onto each worker's disk before it joins the pool, load them once at start-up, and swap only small things (LoRAs) per job.

  • Pin model versions. Download by exact revision (huggingface-cli download REPO --revision COMMIT) so every worker runs the same weights.
  • Warm before serving. Run one throwaway generation at start-up, then start pulling jobs. The first generation after loading is slow.
  • Route by model. A worker that has FLUX loaded pulls from the FLUX queue; do not make workers reload 24 GB of weights per job.
  • Hot-swap LoRAs. diffusers can load, combine and unload LoRAs per job with load_lora_weights, set_adapters and unload_lora_weights. Cache the most-used ones in memory.
  • Health checks. If a worker hits a GPU error (an Xid error in the system log, or repeated CUDA errors), stop it pulling and replace the machine rather than retrying on it.

What should you monitor?

Monitor the user's wait, not just the GPU. Five metrics tell you almost everything:

  1. Queue wait time (p50 and p95) per queue: the number your users feel.
  2. Generation time per model and GPU type: catches regressions and slow hosts.
  3. Queue depth: the trigger for adding GPUs.
  4. GPU utilisation across the fleet: the number your finance team feels.
  5. Failure rate by error type: out-of-memory, timeouts, content-policy refusals.

Export them from workers to Prometheus or any metrics service, and alert on p95 wait, not on single failures.

What about storage, safety and licences?

Storage, content safety and model licences are where generation platforms fail outside the GPU.

  • Storage. A 1024×1024 PNG is typically 1–2 MB and a 5-second MP4 a few MB. A million images is terabytes. Use object storage with lifecycle rules, serve through a CDN, and consider WebP or JPEG for previews.
  • Content safety. Decide your policy, filter prompts before they reach the queue, optionally classify outputs, and log decisions. Self-hosting means this is your job.
  • Provenance. Many platforms embed content credentials (the C2PA standard) or watermarks in outputs; decide early, because adding it later is harder.
  • Licences. FLUX.1 [schnell], Wan 2.1/2.2 and Mochi 1 are Apache 2.0; SDXL is CreativeML Open RAIL++-M; FLUX.1 [dev] is non-commercial; SD 3.5 is free commercially only under US$1 million revenue; HunyuanVideo's licence has territorial restrictions. Read the model cards, such as [FLUX.1 [schnell]](https://huggingface.co/black-forest-labs/FLUX.1-schnell) and Wan 2.1, before you commit to a model.

Build or buy?

Build your own platform when generation is central to your product, volume is steady, or you need control over models and data. Buy a hosted API when volume is small or unpredictable.

FactorSelf-hosted platformHosted image or video API
Cost at steady high volumeLower per outputHigher per output
Cost at low or spiky volumeHigher (idle GPUs)Lower (pay per output)
Model choice and LoRAsAnything with a suitable licenceWhat the provider offers
Data privacyPrompts stay on your machinesPrompts go to the provider
Engineering effortReal: queue, workers, monitoringMinimal

Many teams do both: a hosted API while they find product fit, then their own GPU fleet once volume is steady. The broader infrastructure decisions are in GPU infrastructure for AI SaaS and production GPU infrastructure.

When does renting from Wandering Giants Compute fit?

Renting from us fits the GPU worker tier of this design: dedicated machines with root access, Ubuntu, CUDA and PyTorch ready, from 24 GB RTX 4090s for image pools to 96 GB RTX PRO 6000s and 141 GB H200s for video, with 1, 2, 4 or 8 of the same card per machine. You pay by the minute from prepaid credit, so adding six GPUs for an evening peak costs those evening hours, and prices are in your own currency with UK VAT shown. Workers can run anywhere our partners' ~35 data-centre sites are, and your users' prompts stay on your machines.

What we do not provide matters for a platform: no autoscaling or scale-to-zero, no uptime SLA, no multi-node clusters, and no managed Kubernetes. You run the queue and decide when to add machines. If you need those features, providers that specialise in them are a better fit for the burst tier. If you want dependable, private GPU workers you control, see our GPUs and prices.

Frequently asked questions

Why should GPU workers pull jobs instead of receiving them from a load balancer?

A worker only takes a job when it is free, so no GPU gets two heavy jobs while another sits idle, and slow jobs such as video do not block fast ones. Pull-based queues also survive worker restarts and let you add or remove GPUs without reconfiguring anything.

How many GPUs do I need for an image generation product?

Multiply jobs per second at peak by GPU-seconds per job, then divide by a target utilisation of about 0.7. For example, a peak of 1.74 SDXL images per second at 4.5 seconds each needs about 7.8 busy GPUs, so about 11 RTX 4090s at peak.

Should images and video share the same GPUs?

Usually not. Video jobs take minutes and need large GPUs, while image jobs take seconds and run well on 24 GB cards. Mixing them makes image latency unpredictable. Use separate queues and worker pools, sized independently.

Where should generated images and videos be stored?

In object storage (any S3-compatible service), not on GPU machines. Workers upload results and return a signed URL or a CDN link. Set lifecycle rules to delete or archive old outputs, because storage quietly becomes a large bill at scale.

How do I handle traffic spikes without paying for idle GPUs?

Keep a base fleet sized for normal load near 70% utilisation, queue the overflow and show users an honest wait time, and add GPUs when queue wait passes a threshold. Serverless GPU platforms that scale to zero can absorb bursts; they cost more per GPU-hour but nothing when idle.

Which models can a commercial image or video platform use?

Check each licence. FLUX.1 [schnell], Wan 2.1, Wan 2.2 and Mochi 1 are Apache 2.0; SDXL uses the CreativeML Open RAIL++-M licence; FLUX.1 [dev] is non-commercial; SD 3.5 is free commercially below US$1 million revenue; HunyuanVideo has territorial restrictions.

Wandering Giants Compute

Rent the GPU for this, by the minute.

Build your worker fleet on dedicated GPUs, from RTX 4090s for images to 96 GB RTX PRO 6000s for video, up to eight per machine, billed by the minute.

Prepaid credit, billed by the minute, stops itself when credit runs out. Prices in £, $, €, ¥, CA$, A$, CHF and S$; UK prices include VAT.

Keep reading

About this article. Written by the Wandering Giants Compute team, the people who run Wandering Giants Compute. Hardware figures are the manufacturers’ published specifications. Speeds and costs marked as estimates are worked out from those specifications and our current prices, with the method shown; they are not measured benchmarks. Wandering Giants prices are taken live from our price list each time this page is built.

Last reviewed 25 November 2026.