flowchart TB
P1["Textbook sends POST /xapi/statements
(batch)"]:::before
P2["AuthN Token Cache lookup
Redis, 60s TTL; falls back to local LRU on Redis failure"]:::before
P3["Tier-1 structural validation
all-or-nothing per batch"]:::before
P4["Assign UUIDv7 Statement ID where missing"]:::before
P5["Produce to Kafka
acks=all, key = district:student"]:::after
OK["Broker acks → 200 with statement IDs"]:::after
Fail["Backpressure Queue full AND broker unreachable
→ 503 + Retry-After + page alert"]:::exc
P1 --> P2 --> P3 --> P4 --> P5
P5 --> OK
P5 --> Fail
classDef before fill:#8b9bb0,stroke:#5f6e82,color:#fff,font-size:13px
classDef after fill:#2a9d8f,stroke:#1f7a6f,color:#fff,font-size:13px
classDef exc fill:#e9a23b,stroke:#b8791f,color:#222,font-size:13px
linkStyle default stroke:#999,stroke-width:2px