The spam attack problem
A viral video might receive 10,000 identical crypto scam comments. Without caching, each one triggers a separate AI API call.
Two-layer cache
- Exact match — PostgreSQL KV lookup, 7-day TTL
- Similarity match — pgvector cosine distance < 0.05 returns majority classification
Fallback when AI is slow
If OpenAI latency exceeds 3 seconds, a rule-based classifier takes over automatically. See AI spam detection details.