|
| 1 | +# 🎯 Auction Orchestration Flow |
| 2 | + |
| 3 | +## 🔄 System Flow Diagram |
| 4 | + |
| 5 | +```mermaid |
| 6 | +%%{init: { |
| 7 | + "theme": "base", |
| 8 | + "themeVariables": { |
| 9 | + "background": "#ffffff", |
| 10 | + "primaryColor": "#dbeafe", |
| 11 | + "primaryTextColor": "#1e3a8a", |
| 12 | + "primaryBorderColor": "#2563eb", |
| 13 | + "lineColor": "#334155", |
| 14 | + "secondaryColor": "#fef3c7", |
| 15 | + "tertiaryColor": "#d1fae5", |
| 16 | + "actorBkg": "#eff6ff", |
| 17 | + "actorBorderColor": "#3b82f6", |
| 18 | + "actorTextColor": "#1e40af", |
| 19 | + "actorLineColor": "#64748b", |
| 20 | + "signalColor": "#1e293b", |
| 21 | + "signalTextColor": "#0f172a", |
| 22 | + "labelBoxBkgColor": "#f1f5f9", |
| 23 | + "labelBoxBorderColor": "#cbd5e1", |
| 24 | + "labelTextColor": "#1e293b", |
| 25 | + "loopTextColor": "#1e293b", |
| 26 | + "noteBkgColor": "#fef3c7", |
| 27 | + "noteBorderColor": "#d97706", |
| 28 | + "noteTextColor": "#78350f", |
| 29 | + "activationBorderColor": "#059669", |
| 30 | + "activationBkgColor": "#d1fae5", |
| 31 | + "sequenceNumberColor": "#0f172a" |
| 32 | + }, |
| 33 | + "themeCSS": ".sequenceNumber{font-size:26px!important;font-weight:900!important;fill:#ffffff!important;paint-order:stroke fill;stroke:#1e293b;stroke-width:1px;} .sequenceNumber circle{r:32px!important;stroke-width:3px!important;stroke:#1e293b!important;fill:#2563eb!important;} .mermaid svg{background:#ffffff!important;border-radius:8px;box-shadow:0 2px 4px rgba(0,0,0,0.06);} .actor{font-weight:600!important;} .messageText{font-weight:600!important;font-size:16px!important;} .activation0{stroke-width:3px!important;} .messageLine0,.messageLine1{stroke-width:3px!important;} .messageText tspan{font-size:16px!important;} path.messageLine0,path.messageLine1{stroke-width:3px!important;} marker#arrowhead path,marker#crosshead path{stroke-width:2px!important;}" |
| 34 | +}}%% |
| 35 | +sequenceDiagram |
| 36 | + autonumber |
| 37 | +
|
| 38 | + participant Client as 🌐 Browser/TSJS |
| 39 | + participant TS as 🛡️ Trusted Server |
| 40 | + participant Orch as 🎯 Orchestrator |
| 41 | + participant APS as 📦 APS Provider |
| 42 | + participant Prebid as 🎰 Prebid Provider |
| 43 | + participant Med as ⚖️ AdServer Mediator |
| 44 | + participant Mock as 🎭 Mocktioneer |
| 45 | +
|
| 46 | + %% === Auction Request Initiation === |
| 47 | + rect rgb(243,244,246) |
| 48 | + Note over Client,Mock: 🚀 Auction Request Initiation |
| 49 | + activate Client |
| 50 | + activate TS |
| 51 | + Client->>TS: POST /auction<br/>AdRequest with adUnits[] |
| 52 | + Note right of Client: { "adUnits": [{ "code": "header-banner",<br/> "mediaTypes": { "banner": { "sizes": [[728,90]] } } }] } |
| 53 | + |
| 54 | + TS->>TS: 🔧 Parse AdRequest<br/>🔄 Transform to AuctionRequest<br/>🆔 Generate user IDs<br/>📊 Build context |
| 55 | + deactivate Client |
| 56 | + deactivate TS |
| 57 | + end |
| 58 | +
|
| 59 | + %% === Orchestrator Strategy Detection === |
| 60 | + rect rgb(239,246,255) |
| 61 | + Note over Client,Mock: 🧠 Auction Strategy Detection |
| 62 | + activate TS |
| 63 | + activate Orch |
| 64 | + TS->>Orch: orchestrator.run_auction() |
| 65 | + Orch->>Orch: 🔍 Detect strategy<br/>mediator? parallel_mediation : parallel_only |
| 66 | + deactivate TS |
| 67 | + |
| 68 | + Note over Orch: Strategy determined by config:<br/>[auction]<br/>mediator = "adserver_mock" → parallel_mediation<br/>No mediator → parallel_only |
| 69 | + end |
| 70 | +
|
| 71 | + %% === Parallel Provider Execution === |
| 72 | + rect rgb(243,232,255) |
| 73 | + Note over Client,Mock: 🔄 Parallel Provider Execution |
| 74 | + activate APS |
| 75 | + activate Prebid |
| 76 | + activate Mock |
| 77 | + |
| 78 | + par Parallel Provider Calls |
| 79 | + Orch->>APS: POST /e/dtb/bid<br/>APS TAM format |
| 80 | + Note right of Orch: { "pubId": "5128",<br/> "slots": [{ "slotID": "header-banner",<br/> "sizes": [[728,90]] }] } |
| 81 | + |
| 82 | + APS->>Mock: APS TAM request |
| 83 | + Mock-->>APS: APS bid response<br/>(encoded prices, no creative) |
| 84 | + Note right of Mock: { "contextual": { "slots": [{<br/> "slotID": "header-banner",<br/> "amznbid": "Mi41MA==", // "2.50"<br/> "fif": "1" }] } } |
| 85 | + |
| 86 | + APS-->>Orch: AuctionResponse<br/>(APS bids) |
| 87 | + and |
| 88 | + Orch->>Prebid: POST /openrtb2/auction<br/>OpenRTB 2.x format |
| 89 | + Note right of Orch: { "id": "request",<br/> "imp": [{ "id": "header-banner",<br/> "banner": { "w": 728, "h": 90 } }] } |
| 90 | + |
| 91 | + Prebid->>Mock: OpenRTB request |
| 92 | + Mock-->>Prebid: OpenRTB response<br/>(clear prices, with creative) |
| 93 | + Note right of Mock: { "seatbid": [{ "seat": "prebid",<br/> "bid": [{ "price": 2.00, "adm": "<html>..." }] }] } |
| 94 | + |
| 95 | + Prebid-->>Orch: AuctionResponse<br/>(Prebid bids) |
| 96 | + end |
| 97 | + |
| 98 | + Note over Orch: 📊 Collected bids from all providers<br/>APS: encoded prices, no creative<br/>Prebid: clear prices, with creative |
| 99 | + deactivate Mock |
| 100 | + deactivate APS |
| 101 | + deactivate Prebid |
| 102 | + end |
| 103 | +
|
| 104 | + %% === Winner Selection Strategy === |
| 105 | + alt Mediator Configured (parallel_mediation) |
| 106 | + rect rgb(236,253,245) |
| 107 | + Note over Client,Mock: ⚖️ Mediation Flow |
| 108 | + activate Med |
| 109 | + Orch->>Med: POST /adserver/mediate<br/>All bids for final selection |
| 110 | + Note right of Orch: { "id": "auction-123",<br/> "imp": [...],<br/> "ext": { "bidder_responses": [<br/> { "bidder": "amazon-aps",<br/> "bids": [{ "encoded_price": "Mi41MA==" }] },<br/> { "bidder": "prebid",<br/> "bids": [{ "price": 2.00 }] }] } } |
| 111 | + |
| 112 | + Med->>Med: 🔓 Decode APS encoded prices<br/>📏 Apply floor prices<br/>🏆 Select highest CPM per slot |
| 113 | + Note right of Med: Base64 decode: "Mi41MA==" → "2.50"<br/>Winner: APS at $2.50 vs Prebid at $2.00 |
| 114 | + |
| 115 | + Med-->>Orch: OpenRTB response with winners |
| 116 | + Note right of Med: { "seatbid": [{ "seat": "amazon-aps",<br/> "bid": [{ "price": 2.50, "impid": "header-banner" }] }] } |
| 117 | + deactivate Med |
| 118 | + end |
| 119 | + else No Mediator (parallel_only) |
| 120 | + rect rgb(253,243,235) |
| 121 | + Note over Client,Mock: 🏆 Direct Winner Selection |
| 122 | + Orch->>Orch: 📏 Compare clear prices only<br/>⚠️ Skip APS (encoded prices)<br/>🏆 Select highest CPM |
| 123 | + Note right of Orch: APS bids skipped (encoded prices)<br/>Winner: Prebid at $2.00 (only clear price) |
| 124 | + |
| 125 | + Note over Orch: 📝 Results: Limited winner selection<br/>Cannot compare encoded APS prices<br/>Prebid wins by default |
| 126 | + end |
| 127 | + end |
| 128 | +
|
| 129 | + %% === Response Assembly === |
| 130 | + rect rgb(243,244,246) |
| 131 | + Note over Client,Mock: 📦 Response Assembly |
| 132 | + activate TS |
| 133 | + activate Client |
| 134 | + Orch->>Orch: 🔄 Transform to OpenRTB response<br/>🖼️ Generate iframe creatives<br/>🔏 Rewrite creative URLs<br/>📊 Add orchestrator metadata |
| 135 | + |
| 136 | + Orch-->>TS: OpenRTB BidResponse |
| 137 | + Note right of Orch: { "id": "auction-response",<br/> "seatbid": [{ "seat": "amazon-aps",<br/> "bid": [{ "price": 2.50,<br/> "adm": "<iframe src=\"/first-party/proxy?tsurl=...\">",<br/> "w": 728, "h": 90 }] }] }<br/> "ext": { "orchestrator": {<br/> "strategy": "parallel_mediation",<br/> "bidders": 2, "time_ms": 150 } } |
| 138 | + |
| 139 | + TS-->>Client: 200 OpenRTB response<br/>with winning creative |
| 140 | + deactivate Orch |
| 141 | + deactivate TS |
| 142 | + end |
| 143 | +
|
| 144 | + %% === Creative Rendering === |
| 145 | + rect rgb(239,246,255) |
| 146 | + Note over Client,Mock: 🖼️ Creative Rendering |
| 147 | + Client->>Client: 💉 Inject winning creative<br/>🖼️ Render iframe<br/>🌐 Load creative through proxy |
| 148 | + Note right of Client: iframe src="/first-party/proxy?tsurl=...&tstoken=sig"<br/>Ensures first-party serving<br/>Maintains privacy & security |
| 149 | + deactivate Client |
| 150 | + end |
| 151 | +
|
| 152 | +``` |
| 153 | + |
| 154 | +## 📋 Flow Summary |
| 155 | + |
| 156 | +### **Phase 1: Request Initiation** |
| 157 | +- **Browser** sends `POST /auction` with ad units in Prebid.js format |
| 158 | +- **Trusted Server** parses and transforms to internal `AuctionRequest` |
| 159 | +- Generates user IDs (persistent + fresh) and builds auction context |
| 160 | + |
| 161 | +### **Phase 2: Strategy Detection** |
| 162 | +- **Orchestrator** checks configuration for mediator |
| 163 | +- **With mediator** → `parallel_mediation` strategy |
| 164 | +- **Without mediator** → `parallel_only` strategy |
| 165 | + |
| 166 | +### **Phase 3: Parallel Execution** |
| 167 | +- **APS Provider** receives APS TAM format request |
| 168 | + - Mocktioneer returns APS response with **encoded prices** (`amznbid: "Mi41MA=="`) |
| 169 | + - **No creative HTML** provided (typical for real APS) |
| 170 | +- **Prebid Provider** receives OpenRTB 2.x request |
| 171 | + - Mocktioneer returns OpenRTB response with **clear prices** |
| 172 | + - **Includes creative HTML** in `adm` field |
| 173 | + |
| 174 | +### **Phase 4: Winner Selection** |
| 175 | + |
| 176 | +#### **🔄 With Mediator (Recommended)** |
| 177 | +1. **AdServer Mediator** receives all bids |
| 178 | +2. **Decodes APS prices** (base64 → actual CPM) |
| 179 | +3. **Applies floor prices** and selects highest CPM per slot |
| 180 | +4. **Returns OpenRTB response** with proper winner selection |
| 181 | + |
| 182 | +#### **⚡ Without Mediator (Limited)** |
| 183 | +1. **Orchestrator** compares only clear prices |
| 184 | +2. **APS bids skipped** (encoded prices can't be compared) |
| 185 | +3. **Prebid wins by default** if no other clear-price bidders |
| 186 | + |
| 187 | +### **Phase 5: Response Assembly** |
| 188 | +- **Creative HTML** rewritten with first-party proxy URLs |
| 189 | +- **Orchestrator metadata** added (strategy, timing, bid counts) |
| 190 | +- **OpenRTB response** returned to browser |
| 191 | + |
| 192 | +### **Phase 6: Creative Rendering** |
| 193 | +- **Winning creative** injected into iframe |
| 194 | +- **Resources proxied** through first-party domain |
| 195 | +- **Privacy & security** maintained throughout |
| 196 | + |
| 197 | +## 🔑 Key Technical Details |
| 198 | + |
| 199 | +### **Price Encoding** |
| 200 | +- **APS Mock**: Uses base64 encoding (`"Mi41MA=="` → `"2.50"`) |
| 201 | +- **Real APS**: Uses proprietary encoding (only Amazon/GAM can decode) |
| 202 | +- **Prebid**: Uses clear decimal prices (`2.50`) |
| 203 | + |
| 204 | +### **Request Formats** |
| 205 | +- **APS TAM**: `{ "pubId": "...", "slots": [...] }` |
| 206 | +- **OpenRTB 2.x**: `{ "imp": [...] }` |
| 207 | +- **AdRequest**: `{ "adUnits": [...] }` |
| 208 | + |
| 209 | +### **Response Formats** |
| 210 | +- **APS**: `{ "contextual": { "slots": [...] } }` (no `adm`) |
| 211 | +- **OpenRTB**: `{ "seatbid": [{ "seat": "...", "bid": [...] }] }` |
| 212 | + |
| 213 | +### **Configuration Examples** |
| 214 | + |
| 215 | +#### **Parallel Mediation** |
| 216 | +```toml |
| 217 | +[auction] |
| 218 | +enabled = true |
| 219 | +providers = ["prebid", "aps"] |
| 220 | +mediator = "adserver_mock" # ← Enables mediation |
| 221 | +timeout_ms = 2000 |
| 222 | +``` |
| 223 | + |
| 224 | +#### **Parallel Only** |
| 225 | +```toml |
| 226 | +[auction] |
| 227 | +enabled = true |
| 228 | +providers = ["prebid", "aps"] |
| 229 | +# No mediator = direct comparison |
| 230 | +timeout_ms = 2000 |
| 231 | +``` |
| 232 | + |
| 233 | +### **Advantages of Mediation** |
| 234 | +- ✅ **Proper APS integration** - Can decode and compare APS bids |
| 235 | +- ✅ **Fair competition** - All bidders compete on equal footing |
| 236 | +- ✅ **Floor pricing** - Configurable minimum bid thresholds |
| 237 | +- ✅ **Flexibility** - Easy to add new providers |
| 238 | + |
| 239 | +### **Limitations Without Mediation** |
| 240 | +- ❌ **APS bids ignored** - Can't compare encoded prices |
| 241 | +- ❌ **Unfair competition** - Only clear-price bidders compete |
| 242 | +- ❌ **Reduced revenue** - May miss higher APS bids |
0 commit comments