Platform Engineering · Lesson 162

AI/ML Platform Architecture: From Data to Models and LLMs in Production

An AI/ML platform is the shared ground that lets many teams build, ship, and run models without each rebuilding the same plumbing: data from the lakehouse, a feature store, managed training on shared GPUs, experiment tracking and a model registry, serving for online and batch inference, an AI gateway in front of hosted and self-hosted language models, evaluation and guardrails, monitoring, and governance with cost per team. This lesson follows one team from "we have an idea" to a model and an LLM feature in production, and shows the two ways platforms fail: every team running its own GPU stack, and LLM calls going straight to providers with keys in code.

Difficulty: Master · Know this first: Lesson 161, Lesson 148

What you will learn

By the end of this lesson you can work at four levels:

This page teaches it with a plain-language analogy, an animated diagram with normal and failure scenarios, a simulator, a quiz, basic, intermediate, advanced, and master checks, the expert detail ("Go deeper"), a production incident, a hands-on lab with commands and their output, and a production design exercise.

Run it as:

When it breaks, I check

One thing to remember

Where the time goes

This bar adds up hours of one team's work from idea to production. It is a worked example, not a measurement. The training and gateway hops are where teams either reuse the platform or pay for not having one.

Try it: platform or per-team stacks?

Pick how training, serving, and LLM access are provided for 10 teams. The readouts show time to production, GPU utilisation, and what a leaked key costs.

6 daysto production
71%GPU utilisation
$2,000 capa leaked credential costs

Check yourself

Three questions. No score is saved anywhere — this is just you against the material.

Basic to master

AI/ML platforms grow in four levels: using the platform, building its pieces, operating it as shared infrastructure, and running it as a governed product.

Basic — Use the platform

At the basic level you can take a model from data to production with the platform's paved road.

  • Governed data, the feature store, pipeline templates, the registry, serving templates.
  • The AI gateway for language-model calls, with your team's identity and budget.
  • Your team's dashboard and costs.

Where it breaks: working around the platform "just this once" with a key or a private GPU VM.

Try it: Basic

Your service needs an LLM. How should it call one?

Now do it: Route one model call through a gateway.

Intermediate — Build the pieces

At the intermediate level you build platform components.

  • A GPU node pool with the device plugin, images, and Kueue queues per team.
  • Pipeline and serving templates that include logging, SLOs, and canary rollout.
  • A gateway with per-team keys or identities, budgets, routing, and logging.

Try it: Intermediate

One team's large training job blocks everyone else's. What fixes it?

Now do it: Set quotas for two teams in a test cluster.

Advanced — Operate shared infrastructure

At the advanced level the platform has SLOs and capacity plans of its own.

  • Platform SLOs: queue wait, endpoint availability, gateway latency.
  • Capacity: reserved, on-demand, and Spot GPUs; utilisation and wait reported weekly.
  • Evaluation and guardrail services offered to every LLM feature.

Try it: Advanced

Which number tells you the shared GPU pool is too small?

Now do it: Plot queue wait for a week.

Master — A governed product

At the master level the platform is a product with users, a roadmap, and governance built in.

  • Model and AI feature inventory with risk tiers, approvals, and model cards.
  • Allowed models and providers per data classification, enforced at the gateway.
  • Adoption, time to production, and cost per team as the platform's own metrics.

Trade-off: a central platform can become a bottleneck; templates and self-service keep teams fast while control stays central.

Try it: Master

Confidential data must not be sent to external model providers. Where is that enforced?

Now do it: Write the routing rule for one data class.

Go deeper

The layers and the common choices on each cloud (and open source). Platforms mix them; what matters is that each layer is shared, owned, and measured.

A Kueue setup that gives two teams a guaranteed share of a GPU pool, borrowing from each other when idle (check the Kueue documentation for your version):

apiVersion: kueue.x-k8s.io/v1beta1
kind: ClusterQueue
metadata: {name: forecasting}
spec:
  cohort: gpu-pool                     # queues in a cohort can borrow unused quota
  namespaceSelector: {}
  resourceGroups:
  - coveredResources: ["nvidia.com/gpu"]
    flavors:
    - name: a100
      resources:
      - {name: "nvidia.com/gpu", nominalQuota: 8, borrowingLimit: 8}
---
apiVersion: kueue.x-k8s.io/v1beta1
kind: LocalQueue
metadata: {name: training, namespace: forecasting}
spec: {clusterQueue: forecasting}

One time it broke

This is a composite of a failure pattern that keeps repeating; the details are illustrative. One shared key, many services.

Timeline

  • Months 0–6Eleven services call two LLM providers directly. They share one provider key, copied into configuration files "until the gateway exists".
  • Friday 18:00A repository is mirrored to a contractor's system that is later exposed. The key is in it.
  • WeekendThe key is used for high-volume requests. The provider's usage alert goes to a former employee's email.
  • Monday 09:30Finance sees $38,000 of usage. The key is revoked, breaking all eleven services until new keys are deployed. Nobody can tell which prompts were legitimate.

What changed after

Provider keys exist only in the AI gateway, services authenticate to it with workload identity, each team has a budget and rate limit, prompts are logged with redaction, and secret scanning blocks provider keys in repositories.

Try it yourself, from scratch

Everything here runs on any Linux machine: your own laptop, WSL on Windows (run wsl --install in PowerShell once), or a small cloud VM. The Python needs only Python 3 and its standard library; check that you have it with python3 --version.

Before you start: A practice cluster for the Kubernetes steps: Docker, kind, and kubectl, then kind create cluster. The program needs only Python 3.

1. Linux commands

Type each one, read what it prints, and compare it with the note above it.

  1. See which nodes offer GPUs and how many (none on a kind cluster, which is the point of the next steps).

    kubectl get nodes -o custom-columns=NAME:.metadata.name,GPUS:.status.allocatable.nvidia\.com/gpu

    Expect: Each node with its allocatable GPUs, or <none> where the device plugin is not installed. Read-only.

  2. Install Kueue, the job queueing controller, into the practice cluster.

    Changes a real system: Installing a cluster-wide controller changes how jobs are scheduled: practise on kind, roll out to shared clusters through your platform's change process.

    kubectl apply --server-side -f https://github.com/kubernetes-sigs/kueue/releases/download/v0.10.1/manifests.yaml
    kubectl -n kueue-system rollout status deploy/kueue-controller-manager --timeout=180s

    Options: --server-side is needed for Kueue's large CRDs; pin a release you have checked.

    Expect: Kueue's CRDs and controller, then successfully rolled out.

    Clean up: kind delete cluster removes everything.

  3. List the queue objects Kueue added: these are how teams get quotas on a shared pool.

    kubectl api-resources --api-group=kueue.x-k8s.io

    Expect: ClusterQueue, LocalQueue, ResourceFlavor, Workload, and others. Read-only.

2. Python: ai_gateway.py

This program is a small AI gateway: services call it with their identity, it holds the provider keys, applies each team's monthly budget, routes confidential data only to the self-hosted model, and records every call for audit. Then it compares GPU utilisation for ten per-team GPU stacks with one shared, queued pool. Save it as ai_gateway.py, then run it.

# ai_gateway.py
BUDGET = {"forecasting": 2000.0, "support-bot": 500.0}
PRICE_PER_1K = {"hosted-large": 0.010, "hosted-small": 0.001, "self-hosted": 0.0004}
ALLOWED = {"public": ["hosted-large", "hosted-small", "self-hosted"], "confidential": ["self-hosted"]}
spent = {t: 0.0 for t in BUDGET}
audit = []

def call(team, model, tokens, data_class):
    if team not in BUDGET:
        return "401 unknown caller"
    if model not in ALLOWED[data_class]:
        model = ALLOWED[data_class][0]                    # reroute instead of leaking confidential data
        note = " (rerouted for " + data_class + " data)"
    else:
        note = ""
    cost = tokens / 1000 * PRICE_PER_1K[model]
    if spent[team] + cost > BUDGET[team]:
        audit.append((team, model, tokens, "DENIED: budget"))
        return f"429 {team} over its monthly budget"
    spent[team] += cost
    audit.append((team, model, tokens, "ok"))
    return f"200 {model}{note}, {cost:.2f} USD"

print(call("forecasting", "hosted-large", 120_000, "public"))
print(call("forecasting", "hosted-large", 80_000, "confidential"))
print(call("support-bot", "hosted-large", 60_000_000, "public"))
print(call("leaked-key-user", "hosted-large", 1_000_000, "public"))
print("spend:", {t: round(s, 2) for t, s in spent.items()}, "| audit entries:", len(audit))
print()

HOURS_USED = [3, 2, 4, 1, 6, 2, 3, 5, 2, 4]               # hours a day each team runs an 8-GPU job
gpu_hours = sum(h * 8 for h in HOURS_USED)
per_team = gpu_hours / (len(HOURS_USED) * 8 * 24)
pool_gpus = 16                                            # one shared pool sized for the combined, queued demand
pooled = gpu_hours / (pool_gpus * 24)
print(f"10 stacks of 8 GPUs: {len(HOURS_USED) * 8} GPUs at {per_team:.0%} utilisation")
print(f"one queued pool:     {pool_gpus} GPUs at {pooled:.0%} utilisation for the same work")

Run it, and you should see this output:

$ python3 ai_gateway.py
200 hosted-large, 1.20 USD
200 self-hosted (rerouted for confidential data), 0.03 USD
429 support-bot over its monthly budget
401 unknown caller
spend: {'forecasting': 1.23, 'support-bot': 0.0} | audit entries: 3

10 stacks of 8 GPUs: 80 GPUs at 13% utilisation
one queued pool:     16 GPUs at 67% utilisation for the same work

3. What to notice

4. Advanced: every step as one Bash script

The same Linux steps, made into a real script you can keep and run again. It uses the Bash features a production script needs: functions (one per step), an array of step names, arguments to choose steps, a case for options, exit codes recorded for each step, and a trap that prints a summary even when you stop it with Ctrl+C. Make a folder for this lesson (mkdir -p ~/labs/ai-ml-platform-architecture && cd ~/labs/ai-ml-platform-architecture) and save this as lab.sh.

#!/usr/bin/env bash
# The Linux steps of "AI/ML Platform Architecture: From Data to Models and LLMs in Production", as one script (save it as lab.sh).
#
#   ./lab.sh          run every step, in order
#   ./lab.sh 2 4      run only steps 2 and 4
#   ./lab.sh --list   list the steps
#
# The steps share one shell, so a later step can use what an earlier one set up (a folder,
# a variable, a container): run them all in order the first time. Your own scripts should
# start with "set -euo pipefail"; this one runs teaching commands, and some of them fail on
# purpose, so it records each step's exit code instead of stopping at the first failure.

STEPS=(
  'See which nodes offer GPUs and how many (none on a kind cluster, which is the point of the next steps).'
  'Install Kueue, the job queueing controller, into the practice cluster.'
  'List the queue objects Kueue added: these are how teams get quotas on a shared pool.'
)

step_1() {
kubectl get nodes -o custom-columns=NAME:.metadata.name,GPUS:.status.allocatable.nvidia\.com/gpu
}

step_2() {
kubectl apply --server-side -f https://github.com/kubernetes-sigs/kueue/releases/download/v0.10.1/manifests.yaml
kubectl -n kueue-system rollout status deploy/kueue-controller-manager --timeout=180s
}

step_3() {
kubectl api-resources --api-group=kueue.x-k8s.io
}

# print a step that has to be run by hand, instead of running it
by_hand() {
  echo "  (run this one yourself: $1)"
  sed 's/^/    /'
}

RESULTS=()
run_step() {
  local n=$1 start=$SECONDS code
  printf '\n== step %d of %d: %s\n' "$n" "${#STEPS[@]}" "${STEPS[n-1]}"
  "step_$n"
  code=$?
  RESULTS+=("step $n: exit code $code, $((SECONDS - start)) s")
}

summary() {
  echo
  echo "== summary"
  local r
  for r in "${RESULTS[@]}"; do echo "  $r"; done
}

case "${1:-}" in
  -h|--help) sed -n '2,6p' "$0"; exit 0 ;;
  --list) for i in "${!STEPS[@]}"; do echo "$((i + 1)). ${STEPS[i]}"; done; exit 0 ;;
esac

[ $# -eq 0 ] && set -- $(seq 1 "${#STEPS[@]}")
for n in "$@"; do
  if ! [[ $n =~ ^[0-9]+$ ]] || (( n < 1 || n > ${#STEPS[@]} )); then
    echo "there is no step '$n'; try --list" >&2
    exit 2
  fi
done
trap summary EXIT
trap 'echo; echo "stopped with Ctrl+C"; exit 130' INT
for n in "$@"; do run_step "$n"; done

Then make it executable and run it:

chmod +x lab.sh
./lab.sh --list     # the steps
./lab.sh            # every step, then a summary of exit codes and times
./lab.sh 2 3        # only steps 2 and 3

5. Learn the basics behind it

New to a feature used above? These W3Schools pages explain each one from zero, with examples you can run in the browser.

If you remember nothing else

Design exercise

Ten teams use ML and language models in ten different ways, with nine GPU clusters and provider keys in many repositories. Design the AI/ML platform and the migration.

Clarifying questions to ask

Which layers does the platform own, and which stay with teams? How is GPU capacity shared and bought? How do LLM calls flow, and what does the gateway enforce? How are models and prompts evaluated and governed? How do you measure the platform's success? In what order do teams move?

Rough sizing

Say 10 teams, 60 GPUs at 18% average utilisation, 40 million LLM tokens a day across two providers, and a self-hosted open model for confidential data.

Shape of the answer

A lakehouse with catalog grants; a shared feature store; one Kubernetes GPU pool with Kueue quotas per team, Spot for training with checkpoints, reserved capacity for serving; MLflow tracking and registry with gate templates; KServe and vLLM serving templates with SLOs; an AI gateway holding all provider keys with workload identity, budgets, routing (confidential data only to the self-hosted model), redacted logging, and guardrails; evaluation sets in CI; an inventory with risk tiers; monthly cost per team; teams migrate starting with those holding provider keys, then GPU stacks by utilisation.

Trade-offs to name

Centralising slows teams that had freedom and removes duplicated work and unbounded risk; a shared pool needs fair scheduling and clear priorities; the gateway is a critical dependency, so it needs its own SLO and redundancy.

Failure modes and how to troubleshoot them

Each row is one way this system went wrong in the diagram's scenarios. The hop number is where to look first.

ScenarioWhereEffectWhat goes wrong
A GPU stack per teamHop 3: TrainingBreaksThere is no shared training. The team spends six weeks building a GPU node pool, drivers, images, a pipeline tool, and serving, then runs one training job a night. Its GPUs average 14% utilisation; eight other teams have done the same.
LLM keys in codeHop 6: AI gatewayBreaksThere is no gateway. Services call providers directly with a shared key in a configuration file in the repository. The repository is mirrored to a contractor's system and the key leaks. Over a weekend it is used for $38,000 of requests.

How to troubleshoot

  1. Write down the symptom and when it started: what users see, which number moved, and what changed just before (a deploy, a config change, traffic).
  2. Walk the path in order, from the first hop to the last: Data → Features → Training → Tracking and registry → Serving → AI gateway → Evaluation and guardrails → Monitoring → Governance and cost. The first hop whose evidence is wrong is where to dig.
  3. At that hop, run the read-only check from the diagram or the lab first; change nothing until the evidence points at a cause.
  4. Fix the smallest thing that restores service, or roll back the last change, and confirm the symptom is gone with the same check.
  5. Write down what you found and the check that would have caught it sooner, so the next person starts there.

Architecture review checklist

Review the design in this lesson, or your own, against these ten areas. Tick an area when you can answer its question with evidence: a number, a test, a document, or an owner. Your ticks stay in this browser.

  1. Business outcomeWhich result for users or the business does this design serve, and which number shows it is working?
  2. SecurityWho and what can reach each part, how is identity proven, and how is data protected in transit and at rest?
  3. ReliabilityWhat is the target (SLO), which single failures does the design survive, and how was that tested?
  4. PerformanceWhat latency and throughput are required at peak, and where is the first bottleneck?
  5. OperationsHow is it deployed, observed, and changed safely, and who is paged when it breaks?
  6. CostWhat does it cost per month and per unit of work (request, tenant, model call), and what grows the bill?
  7. SustainabilityWhich resources sit idle, which region and hardware does it run on, and what can scale to zero?
  8. GovernanceWhich policies, guardrails, and compliance rules apply, and how are they enforced in code?
  9. OwnershipWhich team owns each component, its budget, and its on-call, and where is that written down?
  10. Failure and recovery planWhat is the RTO and RPO, what is the runbook for a region or dependency loss, and when was it last rehearsed?

References and review

The official documentation and standards behind this lesson. Versions and defaults change; when a command or field here differs from them, trust the official page.

Last updated . Next review due by November 2027. Found something out of date? Tell me.

Saved on this device, in this browser.
Next in this series · Lesson 163
Zero-Trust Cloud Architecture: Identity, Device, and Every Request Verified

Zero trust drops the idea that being inside the network makes you trustworthy. Every request, from a person or a workload, is authenticated, authorised for that specific resource, and evaluated in context (who, from which device…

Go to Lesson 163 →

Or browse the full course from the Lessons index.