flowchart TB
Req["Gateway receives request with bearer token"]:::start
Check["Check ElastiCache Redis for cached district mapping"]:::start
A1["A: Redis reachable, fresh
within 60s TTL"]:::healthy
A2["Return cached district_id"]:::healthy
B1["B: Redis reachable, expired
Cache TTL Expiry passed"]:::healthy
B2["Re-fetch mapping from identity service"]:::healthy
B3["Re-populate Redis with a fresh 60s TTL"]:::healthy
C1["C: Redis unreachable"]:::fallback
C2["Fall back to the pod's local LRU Fallback Cache"]:::fallback
C3["Serve from local cache, else re-fetch from identity service directly"]:::fallback
End["Proceed to Tier-1 validation
ingestion never blocks on cache health"]:::start
Req --> Check
Check --> A1 --> A2 --> End
Check --> B1 --> B2 --> B3 --> End
Check --> C1 --> C2 --> C3 --> End
classDef start fill:#37474f,stroke:#1c2529,color:#fff,font-size:13px
classDef healthy fill:#2a9d8f,stroke:#1f7a6f,color:#fff,font-size:13px
classDef fallback fill:#e9a23b,stroke:#b8791f,color:#222,font-size:13px
linkStyle default stroke:#999,stroke-width:2px