Skip to content

Invisible Regression: Cache Hit Sessizce Düşünce

Yeni bir feature push ettin. Test geçti. Production'da haftalarca cache hit rate %90'dan %5'e düştü, kimse fark etmedi. Bu sessiz regression'ı önleme stratejileri.

Şükrü Yusuf KAYA
11 min read
Intermediate

Anti-Pattern 2: Invisible Regression

Real-world hikaye (gerçek danışmanlık vakası):
Bir e-ticaret şirketi 6 aydır LLM tabanlı destek sistemi çalıştırıyor. Cache hit rate başlangıçta %92, beklenen maliyet aylık 3K.Birgu¨nmuhasebe"AIfaturasıbuay3K. Bir gün muhasebe "AI faturası bu ay 25K olmuş" diye geldi. Ne oldu?
Detective work: 3 hafta önce bir dev system prompt'a "Sistem zamanı: {current_time}" ekleyip merge etmiş. Test'lerde gözükmedi (UI feature). Cache hit rate %92'den %3'e düştü. Kimse fark etmedi. 3 haftada $22K extra harcandı.
Bu invisible regression. Çözümleri:

Çözüm 1: Pre-Push Cache Hit Test#

python
# tests/test_cache_hit_rate.py
import pytest
 
@pytest.fixture
def test_environment():
"""Test ortamında 100 sample query yap."""
return {
"queries": [f"Test query {i}" for i in range(100)],
"user": MockUser(),
}
 
def test_cache_hit_rate_above_threshold(test_environment):
"""Cache hit rate min %85 olmalı."""
total_creation = 0
total_read = 0
 
for q in test_environment["queries"]:
resp = make_request(test_environment["user"], q)
total_creation += resp.usage.cache_creation_input_tokens or 0
total_read += resp.usage.cache_read_input_tokens or 0
 
hit_rate = total_read / max(1, total_read + total_creation)
assert hit_rate >= 0.85, f"Cache hit rate {hit_rate:.2%} below threshold!"
 
# CI'da her PR'de bu test çalışsın
# pytest tests/test_cache_hit_rate.py
Pre-push hit rate test
Bu test PR'de hit rate'in düştüğünü yakalar. Önleyici tedbir.

Çözüm 2: Production Alerts (Modül 11)#

Eğer pre-push test atlandıysa ya da production'a özgü bir regression varsa, monitoring alarmı kritik:
- alert: CacheHitRateRegression expr: | avg_over_time(cache_hit_rate[1h]) < 0.85 for: 30m annotations: summary: "Cache hit rate < 85% son 1 saatte"
30 dakika sustained — false positive'leri filtrele. Yine de gerçek regression'ları yakalar.

Çözüm 3: Cost Baselining#

python
# Hourly cost'u tut
HOURLY_COST_BASELINE = 4.50 # $4.50/saat (ölçülen baseline)
 
if current_hour_cost > 1.5 * HOURLY_COST_BASELINE:
send_alert(f"Cost spike: {current_hour_cost} vs baseline {HOURLY_COST_BASELINE}")
```
 
Cost spike anomaly detection. Hit rate'e dolaylı işaret.

Çözüm 4: Canary Deployment + Comparison#

A/B testing (Modül 11 Ders 76) burada da işe yarar. Yeni release %5 user'a deploy edilir. Cost ve hit rate kıyaslanır:
Control (%95): hit rate %92, cost/req $0.025 New (%5): hit rate %30, cost/req $0.150 ← ANLİK FARK
Bu fark hemen göze çarpıyor → rollback yapılır.
Defense in Depth
3 katmanlı savunma:
  1. Pre-push test (CI'da hit rate test)
  2. Canary release (%5 trafik kontrolü)
  3. Production alarm (real-time threshold)
Üçü birlikte invisible regression olasılığını sıfıra yaklaştırır.

✓ Pekiştir#

Bir Sonraki Derste#

Cross-tenant cache leak — multi-tenant sistemde güvenlik açıkları.

Yorumlar & Soru-Cevap

(0)
Yorum yazmak için giriş yap.
Yorumlar yükleniyor...

Related Content