Lesson 32 Deployment Patterns
Theme:

Homework

Complete these tasks before Lesson 33. Tasks 1 and 2 involve writing code or configuration; Task 3 is research-based. All three reinforce production deployment skills.

Task 1: Production-Ready Dockerfile

Goal: Write a multi-stage Dockerfile that produces a minimal, secure production image for an LLM API service.

Instructions

Starting from the basic Dockerfile in the lab, enhance it to meet production standards:

  1. Multi-stage build: Use a builder stage that installs all dependencies, and a runtime stage that copies only the installed packages and application code.
  2. Non-root user: Create a dedicated appuser and run the application as that user (not as root).
  3. Health check: Add a HEALTHCHECK instruction that pings your /health endpoint every 30 seconds.
  4. Metadata labels: Add LABEL instructions for maintainer, version, and description.
  5. Graceful shutdown: Ensure uvicorn receives SIGTERM properly (use exec form of CMD, not shell form).

Deliverable

A complete Dockerfile that builds successfully. Test by running:

docker build -t llm-app:prod .
docker run --rm -e ANTHROPIC_API_KEY=test -p 8000:8000 llm-app:prod
# In another terminal:
curl http://localhost:8000/health

Self-check

Task 2: Canary Deployment Pipeline Design

Goal: Design a canary deployment pipeline for an LLM-powered chat service, either as a diagram or as a CI/CD configuration file.

Instructions

Your pipeline should cover the full lifecycle from code push to production rollout. Include the following stages:

  1. Build & Test: Lint, type-check, unit tests with mocked LLM responses.
  2. Eval Gate: Run an eval suite of 50+ test prompts against the live model. Define pass/fail criteria (e.g., accuracy ≥ 90%, format compliance ≥ 95%, no safety violations).
  3. Canary Deploy: Deploy the new version alongside the current version. Route 10% of traffic to the canary.
  4. Monitoring Window: Monitor for 30 minutes. Track: error rate, p50/p99 latency, eval score on live traffic, user feedback signals.
  5. Promotion or Rollback: Define automated rollback triggers (e.g., error rate > 2x baseline, p99 > 150% of baseline). If no triggers fire, promote to 100%.

Deliverable

Choose one of the following formats:

Self-check

Task 3: vLLM vs TGI Comparison

Goal: Research and compare the two leading open-model serving frameworks to understand when to use each.

Instructions

Research vLLM and Text Generation Inference (TGI) using their official documentation, benchmark results, and community discussions. Write a comparison covering:

  1. Architecture: How does vLLM's PagedAttention differ from TGI's approach to memory management? Why does this matter for throughput?
  2. Throughput: Find or estimate benchmark numbers for serving a 7B-parameter model (e.g., Llama 3.1 8B) on a single A100 GPU. Compare requests/second and tokens/second for both frameworks.
  3. Ecosystem: Which framework integrates better with your existing tools? Consider: model format support, API compatibility, monitoring, multi-GPU support.
  4. Recommendation: In one paragraph, state when you would choose vLLM over TGI and vice versa.

Deliverable

A written comparison (300-500 words) with a summary table:

CriterionvLLMTGI
Throughput (tok/s)......
API compatibility......
Multi-GPU......
Quantisation support......
Ease of deployment......

Self-check

📥 Reference Solution

⬇ lab_answer.py

Submission

There is no formal submission for this course. These tasks are for your own development. However:

Next lesson: Lesson 33 — Custom Training