Deploying LLM-Powered Services
Package your AI backend as a container, manage secrets and configuration, and handle long-running requests with queues and background jobs.
Intermediate · about 6 hours · difficulty 3/5
Learn first: Streaming Responses, Async I/O and Concurrency
An AI feature is still a web service, with a few twists: requests are slow, outputs stream, costs scale with usage, and some jobs (ingesting documents, running agents, batch evals) take minutes.
Service basics
- Containerize your API with Docker so the same image runs locally, in CI and in production.
- Configuration: model names, temperatures and prompt versions come from config, not hard-coded strings, so you can change them without a redeploy.
- Secrets: provider API keys live in a secret manager or platform environment variables, never in the image.
- Timeouts: set them at every layer (client, load balancer, your code, the model SDK). Many platforms kill requests after 30 to 60 seconds, which long agent runs exceed.
Long-running work
- Move ingestion, embedding and agent tasks to a job queue (Celery, RQ, BullMQ, cloud task queues) with workers.
- Return a job id immediately and let the client poll or subscribe for progress.
- Make jobs idempotent and resumable so a crash halfway does not duplicate side effects.
- For durable multi-step agent workflows, workflow engines such as Temporal or Inngest provide retries and state.
Streaming in production
Check that proxies and load balancers do not buffer server-sent events, and send heartbeats on long streams.
Where to deploy
Serverless platforms are simple for light traffic; containers on a PaaS or Kubernetes suit steady load and background workers. GPU hosting is only needed if you serve models yourself.
Good enough to move on
You can deploy a containerized AI API with streaming, config-driven model settings, secrets from the platform, and a worker that processes document ingestion jobs from a queue.
Key concepts
- Docker for AI services
- Config-driven model settings
- Secret management
- Timeouts at every layer
- Job queues and workers
- Durable workflow engines
- Streaming through proxies
- Serverless vs containers
Mini project
Deploy a Dockerized FastAPI or Node service to a cloud platform with a streaming chat endpoint and a separate worker that ingests uploaded PDFs from a queue, reporting progress to the client.
Check yourself
Why should a 3 minute agent run not be handled inside a normal synchronous HTTP request?
Free resources
- Docker get started (Docker)
- FastAPI: deployment (FastAPI)
- Celery documentation (Celery)