# Ads Serving Service Architecture

## Overview

```mermaid
graph LR
    REQ[Ad Request] --> GW[Gateway]
    GW --> CACHE[Redis Cache]
    CACHE --> AUC[Auction]
    AUC --> RESP[Response]
    RESP --> EVT[Async Events]
```

## eCPM Calculation

```
eCPM = (Bid × Predicted_CTR × 1000) + Quality_Score
```

## Redis Data Structures

| Key | Type | TTL |
|-----|------|-----|
| `ads:active:{placement}` | Sorted Set | 5 min |
| `freq:{userId}:{date}` | Hash | 24h |
| `budget:{campaignId}:{date}` | String | 24h |

## Latency Budget

| Phase | Target |
|-------|--------|
| Redis lookup | < 5ms |
| Auction logic | < 20ms |
| **Total** | **< 100ms** |
