Online Advertising System
Flow hai: ad request → targeting (kaunse ads is user ke liye eligible hain) → auction (bid × predicted CTR se ranking) → winner → impression log. Poora budget 100ms ka hota hai, isliye targeting index memory mein rehta hai aur CTR prediction model bhi low-latency serving mein.
Sabse mushkil distributed problem BUDGET ENFORCEMENT hai. Advertiser ka daily budget khatam hone par ad turant band hona chahiye, par counters kai servers par distributed hain. Solution: har server ko budget ka chhota slice allot karo (local counter) aur periodically central se sync karo — thoda overspend acceptable maana jaata hai, latency ke badle.
// Auction — 100ms budget
Ad request → Targeting (in-memory index: geo, age, interest)
→ eligible ads (~1000)
→ score = bid × predictedCTR // eCPM
→ winner → serve → impression event (Kafka)
// Budget: local slice + periodic sync, exact global counter nahi
// (exact counter har impression par network round-trip maangega)- Targeting → auction (bid × CTR) → serve, sab 100ms mein
- Budget enforcement distributed hai — local slices + periodic sync
- Impressions async (Kafka); billing usi data ka accurate reprocessing
Auction sirf bid par nahi jeeti jaati. Platform apni kamai maximize karta hai, isliye ranking eCPM (effective cost per mille) par hoti hai = bid × predicted CTR. Kam bid par high-CTR ad, zyada bid par low-CTR ad ko haraa sakta hai.
CTR prediction ek low-latency ML model hai jo user features, ad features aur context (time, device, placement) leta hai. Ise 10-20ms mein score karna hota hai, isliye model chhota rakha jaata hai aur features precomputed hote hain.
// Ranking eCPM par, bid par nahi
Ad A: bid ₹10, CTR 0.5% -> eCPM = 10 × 0.005 = 0.05
Ad B: bid ₹5, CTR 2.0% -> eCPM = 5 × 0.020 = 0.10 ← jeetegaBots clicks generate karte hain jisse advertisers ka paisa barbaad hota hai. Detection async hoti hai — impression aur click events analyze karke suspicious patterns (same IP se hazaaron clicks, impossible click-through timing) mark kiye jaate hain aur billing se hataaye jaate hain.
ATTRIBUTION alag problem hai — user ne ad dekha, 2 din baad kharida. Us sale ka credit kis ad ko? Last-click, first-click, ya multi-touch attribution — ye business decision hai aur system ko dono events jodne padte hain.