Running AI on Azure without runaway cost
More images, more embeddings, more compute — the AI cloud bill grows fast. Here is how we kept it under control on Azure.
Why AI cloud bills grow with the catalog
Every new batch of images means more embeddings, a bigger index, more memory to hold it and more CPU to search it. Unchecked, that pushes you onto ever-bigger instances — the bill climbs with the catalog rather than with the value.
Optimise the architecture before adding compute
The cheapest performance gain is usually architectural, not more hardware. Precomputed embeddings, an optimised index, cached popular results and batch split from serving removed most of the pressure — so we scaled compute only for proven bottlenecks.
Azure hosting options compared
| Option | Best for |
|---|---|
| App Service for Containers | Simple managed API hosting, lower operational overhead |
| Azure Container Apps | Autoscaling and event-driven workloads, batch and API separated |
| Azure Kubernetes Service | Larger scale with separate API, indexer and worker services |
Cost controls that actually work
Set measurable targets (response time, cost per recommendation, max startup), size dev and test below production, turn on autoscaling and cost alerts, and make spend visible per batch run and per API call. Measured cost stops over-scaling being the default.
Key decision: hosting tier, and scale vs. optimise
Pick the smallest hosting that fits, and never add compute before profiling the real bottleneck.
Which Azure hosting?
- Simple managed API, low opsApp Service for Containers
- Autoscale and event-driven, batch and API splitAzure Container Apps
- Many services: API, indexer, crawler, workersAzure Kubernetes Service (AKS)
Slow or costly: add compute? Profile first.
- Memory-bound (large index)?optimise or compress the index, cache, then size memory
- CPU-bound (search)?cache hot queries, then add CPU
- Slow startup?prebuild the index, lighten startup
- Storage throughput?move to a faster storage tier
Only scale the proven bottleneck, not everything at once.
More technical detail
# deploy the container image to Azure App Service
az webapp config container set \
--name fashion-ai-api --resource-group <resource-group> \
--docker-custom-image-name <registry>.azurecr.io/clip-backend:latest
# runtime settings: prebuilt index path + worker/timeout tuning
az webapp config appsettings set \
--name fashion-ai-api --resource-group <resource-group> \
--settings INDEX_PATH=/app/index/fashion.index \
WEB_CONCURRENCY=2 GUNICORN_TIMEOUT=180