Problem
Adding large language model capabilities to an established multi-tenant SaaS application fundamentally alters the operational profile of your Kubernetes cluster. Standard SaaS architectures are optimized for predictable, low-latency CRUD operations with short execution windows. AI workflows, by contrast, introduce high memory consumption, long-running connections for streaming tokens, unpredictable CPU and GPU utilization, and severe cost amplification if scaling policies are misconfigured.
A naive implementation routes AI prompts directly through the primary API gateway to synchronous endpoint workers. Under load, these requests exhaust connection pools, trigger cascading HTTP timeouts, and starve deterministic tenant operations of compute resources. To build a robust AI-enhanced platform, you must decouple deterministic control planes from probabilistic execution tiers while maintaining strict observability and cost governance.
Architecture overview
Our reference architecture runs on a dedicated, multi-zone Amazon EKS cluster separated into distinct node groups: general-purpose CPU nodes for core services, memory-optimized nodes for caching layers, and GPU-accelerated nodes (such as NVIDIA A10G or L4 instances) for model inference.
An Envoy-based Ingress controller acts as the edge, routing traffic to core microservices via internal gRPC links. A specialized LLM Gateway sits in front of the AI worker pools to handle prompt validation, semantic caching, token bucket rate limiting, and fallback routing between primary and secondary model providers. Event streaming via Apache Kafka acts as the foundational buffer between fast API requests and slow GPU-bound inference tasks.
Step-by-step flow
- Client requests enter the infrastructure via the API Gateway, which performs JWT validation and tenant context injection.
- The Ingress Controller directs standard REST traffic to the Core API Service deployment.
- Requests requiring AI generation are intercepted by the LLM Gateway for token budget verification and PII redaction.
- The LLM Gateway publishes the sanitized prompt payload to an internal Kafka topic for asynchronous processing.
- GPU Worker pods consume batches from Kafka, executing model inference with optimized tensor parallelization.
- Results are streamed back through the event bus and edge proxy while metrics are exported to Prometheus.
Design decisions and trade-offs
Choosing an asynchronous event-driven pattern for LLM execution trades immediate consistency for platform stability. Clients receive a job ID or an open Server-Sent Events (SSE) channel rather than a blocking HTTP response. This design protects the API layer from thread starvation, but it requires client applications to implement robust reconnection and state-reconciliation logic.
We utilize Redis for distributed token bucket rate limiting at the edge. While Redis adds a critical path dependency, its sub-millisecond evaluation latency prevents unauthorized or runaway prompts from ever reaching expensive GPU worker nodes. For model serving, vLLM deployed inside Kubernetes pods provides continuous batching and PagedAttention, significantly increasing throughput compared to naive Hugging Face TGI deployments.
apiVersion: apps/v1
kind: Deployment
metadata:
name: llm-worker
namespace: ai-workloads
spec:
replicas: 3
selector:
matchLabels:
app: llm-worker
template:
metadata:
labels:
app: llm-worker
spec:
nodeSelector:
node.kubernetes.io/purpose: gpu-accelerated
tolerations:
- key: "nvidia.com/gpu"
operator: "Exists"
effect: "NoSchedule"
containers:
- name: vllm-server
image: vllm/vllm-openai:latest
resources:
limits:
nvidia.com/gpu: "1"
memory: 64Gi
requests:
nvidia.com/gpu: "1"
memory: 32Gi
Failure modes
In a distributed AI architecture, failure modes are multifaceted. The most critical failure is queue saturation in Kafka during upstream provider outages or sudden viral user adoption. If GPU workers cannot drain the queue, consumer lag climbs rapidly, exhausting memory buffers.
Another severe failure mode is GPU memory fragmentation caused by highly variable input and output token lengths. Without aggressive chunking and paged memory management, vLLM instances suffer from Out-Of-Memory (OOM) kills that terminate active user streams without warning.
When not to use this
This architecture is over-engineered for low-throughput applications, internal-facing administrative tooling, or platforms where AI calls are rare and can be executed synchronously within a standard serverless function timeout. If your peak concurrency is under fifty requests per minute and your p99 latency tolerance exceeds thirty seconds, a direct REST integration with managed LLM endpoints without Kafka or custom ingress gateways is simpler and far more cost-effective.
Key takeaways
Isolating AI workloads onto dedicated node groups with explicit GPU tolerations prevents resource starvation for core SaaS features. Using Kafka as an ingestion buffer absorbs traffic spikes and protects downstream model endpoints. Finally, enforce strict token budgets at the edge via Redis before expensive compute is ever allocated.
Top comments (0)