Month 5 Capstone3 Code Files

Month 5 Capstone: Production FastAPI Microservice, Streaming Chatbot & MLOps Platform

Month 5 Capstone: Production FastAPI Microservice, Streaming Chatbot & MLOps Platform

1. Executive Summary & Production Blueprint

This Month 5 Capstone represents the complete production enterprise wrapper around our Month 1–4 foundational engines (SRE CLI, Evaluator Suite, Hybrid RAG, and Agentic MCP Server).

It exposes an enterprise-grade REST microservice combining:

  1. Asynchronous Non-Blocking High Concurrency: Built on FastAPI & ASGI (Uvicorn), serving thousands of simultaneous requests.
  2. Server-Sent Events (SSE) Multiplexing: Streaming thought, component, token, citation, and done frames.
  3. Multi-Turn Chat Memory & Bounded Context: Sliding window token manager with background compaction.
  4. Tenant Security & Token-Bucket Rate Limiter: Guarding against Denial-of-Wallet (DoW) attacks via RPM burst limits and daily dollar caps.
  5. Sub-10ms Semantic Prompt Caching: Vector similarity matching (θ≥0.95\theta \ge 0.95) returning cached incident answers at $0.00 cost.
  6. Resilient Cascade Fallback Gateway: Zero-downtime routing from Primary (OpenAI gpt-4o-mini) to Secondary (Anthropic claude-3-5-haiku) on 429/503 errors.
  7. OpenTelemetry & Langfuse Observability: Full distributed trace context with W3C traceparent propagation and Prometheus /metrics exposition.
  8. Hardened Multi-Stage Container: Minimal non-root container (USER 10001) with cgroup limits and automated Kubernetes probes (/healthz, /readyz).

2. Architecture & Data Flow

Architecture Flow Diagram
Client (Browser / Python SDK / CLI)->|POST /v1/copilot/query| Auth[1. API Key Auth & Token-Bucket Rate Limiter
Quota{2. Spend Quota Check}
|Exceeded| Reject[HTTP 429 / 402 Error
|OK| Cache{3. Semantic Cache (Cosine >= 0.95)}
|Hit (< 10ms, $0.00)| CacheReturn[Instant SSE Token Stream
|Miss| GW[4. Resilient Cascade Model Router
P1[Primary: OpenAI gpt-4o-mini
|503 Outage| P2[Fallback: Claude 3.5 Haiku
& P2->Store[5. Store in Semantic Cache + Bounded Memory
OTel[6. Emit OpenTelemetry GenAI Span (W3C traceparent)
LF[7. Export Langfuse Observability Trace
Prom[8. Prometheus /metrics & K8s Health Probes

3. Microservice Endpoints Specification

MethodEndpointDescriptionExpected Output
GET/healthzKubernetes Liveness Probe{"status": "alive", "uptime": 42.1}
GET/readyzKubernetes Readiness Probe{"ready": true, "dependencies": {...}}
GET/v1/copilot/metricsPrometheus Metrics ExpositionPlain-text Prometheus counters, gauges, histograms
POST/v1/copilot/queryStreaming SSE & JSON Copilot Querytext/event-stream (thought, token, component, citation, done)
POST/v1/copilot/feedbackUser Feedback Scoring{"status": "recorded", "score": 1.0}
Month 5 Capstone: Production FastAPI Microservice, Streaming Chatbot & MLOps Platform | Month 5 AI Engineering Capstone · DataArena