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:
- Asynchronous Non-Blocking High Concurrency: Built on FastAPI & ASGI (
Uvicorn), serving thousands of simultaneous requests. - Server-Sent Events (SSE) Multiplexing: Streaming
thought,component,token,citation, anddoneframes. - Multi-Turn Chat Memory & Bounded Context: Sliding window token manager with background compaction.
- Tenant Security & Token-Bucket Rate Limiter: Guarding against Denial-of-Wallet (DoW) attacks via RPM burst limits and daily dollar caps.
- Sub-10ms Semantic Prompt Caching: Vector similarity matching () returning cached incident answers at $0.00 cost.
- Resilient Cascade Fallback Gateway: Zero-downtime routing from Primary (
OpenAI gpt-4o-mini) to Secondary (Anthropic claude-3-5-haiku) on 429/503 errors. - OpenTelemetry & Langfuse Observability: Full distributed trace context with W3C
traceparentpropagation and Prometheus/metricsexposition. - 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
| Method | Endpoint | Description | Expected Output |
|---|---|---|---|
GET | /healthz | Kubernetes Liveness Probe | {"status": "alive", "uptime": 42.1} |
GET | /readyz | Kubernetes Readiness Probe | {"ready": true, "dependencies": {...}} |
GET | /v1/copilot/metrics | Prometheus Metrics Exposition | Plain-text Prometheus counters, gauges, histograms |
POST | /v1/copilot/query | Streaming SSE & JSON Copilot Query | text/event-stream (thought, token, component, citation, done) |
POST | /v1/copilot/feedback | User Feedback Scoring | {"status": "recorded", "score": 1.0} |