Skip to content

RouterV2 Pipeline Documentation

Comprehensive documentation of the RouterV2 processing pipeline stages

🔄 Pipeline Overview

RouterV2 implements a sophisticated 11-stage processing pipeline designed for intelligent request routing and content delivery. Each stage has specific responsibilities and can execute in parallel where dependencies allow.

📋 Pipeline Stages Summary

Stage Name Purpose Parallel Dependencies
S00 Initialize Request setup and validation No None
S01 Prepare Input Query string and header processing Partial S00
S02 Check Redirect Redirect logic evaluation No S01
S03 Load External Dependencies Campaign and brand data loading Yes S01
S04 Process Data Data processing and transformation Yes S03
S05 Make Decision Intelligent routing decisions No S04
S06 Check Overflow Traffic overflow handling No S05
S07 Get Content Content generation and retrieval Yes S06
S08 Create Response Response formatting No S07
S09 Save Response Response persistence Yes S08
S10 Verbose Response Debug and verbose output No S09

🚀 Stage Details

S00: Initialize

File: S00Initialize/S1InitialSetup.js

Purpose: Initialize the request context and perform basic validation.

graph LR
    A[HTTP Request] --> B[Extract Request ID]
    B --> C[Generate Session ID]
    C --> D[Initialize Context]
    D --> E[Basic Validation]
    E --> F[Set Timestamps]

Key Operations: - Generate unique request ID - Extract or create session ID (wizsid) - Initialize message context structure - Set request timestamps - Perform basic request validation

Context Updates:

msgCtx.details = {
  requestId: "generated-uuid",
  sessionId: "extracted-or-generated-wizsid",
  timestamp: "2025-01-01T12:00:00.000Z",
  startTime: Date.now()
}

S01: Prepare Input

Files: S01PrepareInput/S1PrepareQS.js through S6CheckTestEvent.js

Purpose: Process and normalize input parameters from query string, headers, and body.

graph TD
    A[S1: Prepare QS] --> B[S2: Prepare Headers]
    B --> C[S3: Get QS Campaign]
    C --> D[S4: Should Create New Session]
    D --> E[S5: Get Wizsid]
    E --> F[S6: Check Test Event]

Sub-stages: 1. S1PrepareQS: Parse and normalize query string parameters 2. S2PrepareHeaders: Extract and process HTTP headers 3. S3GetQSCampaign: Determine campaign from query parameters 4. S4ShouldCreateNewSession: Evaluate session creation logic 5. S5GetWizsid: Extract or generate wizard session ID 6. S6CheckTestEvent: Identify test/debug requests

Key Operations: - Query string parsing and validation - Header extraction (User-Agent, IP, etc.) - Campaign identification from URL parameters - Session management logic - Test event detection

S02: Check Redirect

Files: S02CheckRedirect/CheckPermanantRedirect.js, CheckResellerRedirect.js

Purpose: Evaluate redirect conditions and handle permanent redirects.

graph LR
    A[Check Permanent Redirect] --> B{Redirect Required?}
    B -->|Yes| C[Set Redirect Response]
    B -->|No| D[Check Reseller Redirect]
    D --> E{Reseller Redirect?}
    E -->|Yes| F[Set Reseller Redirect]
    E -->|No| G[Continue Pipeline]

Key Operations: - Permanent redirect rule evaluation - Reseller-specific redirect logic - Redirect URL construction - Early pipeline termination for redirects

S03: Load External Dependencies

Files: S03LoadExternalDependencies/P0Init, P1Load, P2LoadBrand

Purpose: Load campaign data, brand information, and external configurations.

graph TD
    A[P0: Initialize] --> B[P1: Load Campaign Data]
    A --> C[P2: Load Brand Data]
    B --> D[Document Cache Lookup]
    C --> E[Brand Configuration]
    D --> F[Campaign Validation]
    E --> G[Brand Asset Loading]
    F --> H[Merge Data]
    G --> H

Parallel Operations: - Campaign data loading from document cache - Brand configuration and asset loading - External dependency resolution

Key Data Loaded: - Campaign configuration and settings - Brand templates and assets - Product configurations - Routing rules and constraints

S04: Process Data

Files: S04ProcessData/P0CheckVendorWizsidConfig.js through P2ProcessLoadedData

Purpose: Process and transform loaded data for decision making.

graph TD
    A[P0: Check Vendor Config] --> B[P1: Process Splits]
    A --> C[P0: Get Reseller Campaign]
    B --> D[P1: DatapassV2]
    C --> E[P2.1: Check Disabled Product]
    D --> F[P2: Process Loaded Data]
    E --> F

Key Operations: - Vendor-specific configuration processing - A/B testing and split logic - Data transformation and enrichment - Product availability validation - Campaign data processing

S05: Make Decision

Files: S05MakeDecision/S01LPPreview.js through S11Oops.js

Purpose: Make intelligent routing decisions based on processed data.

graph TD
    A[Decision Engine] --> B{Request Type}
    B -->|LP Preview| C[S01: LP Preview]
    B -->|Widget| D[S02: Widget Request]
    B -->|Ads| E[S03: Ads]
    B -->|Form| F[S04: Form Request]
    B -->|Redirect| G[S05: Redirect Tracking]
    B -->|Form Redirect| H[S06: Form Redirect]
    B -->|Site Page| I[S07: Site Page]
    B -->|LP Request| J[S08: LP Request]
    B -->|Home Page| K[S09: Home Page]
    B -->|Root Home| L[S10: Root Home Page]
    B -->|Error| M[S11: Oops]

Decision Types: 1. Landing Page Preview: Preview mode for landing pages 2. Widget Request: Widget content delivery 3. Ads: Advertisement content serving 4. Form Request: Form processing and display 5. Redirect Tracking: Tracked redirect handling 6. Form Redirect: Form submission redirects 7. Site Page: Static site page delivery 8. LP Request: Landing page request handling 9. Home Page: Home page content delivery 10. Root Home Page: Root-level home page 11. Oops: Error page handling

S06: Check Overflow

Files: S06CheckOverflow/S1CheckOverflowRedirect.js

Purpose: Handle traffic overflow and capacity management.

graph LR
    A[Check Traffic Levels] --> B{Overflow Detected?}
    B -->|Yes| C[Apply Overflow Rules]
    B -->|No| D[Continue Normal Flow]
    C --> E[Redirect to Overflow Target]
    D --> F[Proceed to Content]

Key Operations: - Traffic level monitoring - Overflow threshold evaluation - Overflow redirect rule application - Capacity management

S07: Get Content

Files: S07GetContent/S00GetDataPassPing.js through S08Widget.js

Purpose: Generate and retrieve content based on routing decisions.

graph TD
    A[Content Generation] --> B[S00: DataPass Ping]
    A --> C[S01: LP and Sitepage]
    A --> D[S02: Update LP URL]
    A --> E[S03: Prepare Homepage]
    A --> F[S04: Fetch Form Content]
    A --> G[S05: Ads]
    A --> H[S06: Add Location]
    A --> I[S07: Widget]

Content Types: - Landing page content generation - Form content and validation - Advertisement content - Widget content - Homepage content - Location-based content

S08: Create Response

Files: S08CreateResponse/S01InitResponse.js through S09ReturnResellerBid.js

Purpose: Format and prepare the HTTP response.

graph TD
    A[Response Creation] --> B[S01: Init Response]
    B --> C[S02: Set Cookies]
    C --> D{Response Type}
    D -->|Redirect| E[S03: Redirect]
    D -->|Content| F[S04: Return Content]
    D -->|Ads| G[S05: Return Ads]
    D -->|Redirect| H[S06: Return Redirect]
    D -->|Error| I[S07: Return Error]
    D -->|Widget| J[S08: Return Widget]
    D -->|Reseller| K[S09: Return Reseller Bid]

Response Types: - HTTP redirects (301, 302, 307) - HTML content delivery - JSON API responses - Advertisement content - Widget content - Error pages - Reseller bid responses

S09: Save Response

Files: S09SaveResponse/P01Save

Purpose: Persist response data and session state.

graph LR
    A[Response Data] --> B[Session Cache Update]
    A --> C[Response Logging]
    A --> D[Analytics Data]
    B --> E[Redis Update]
    C --> F[Log Storage]
    D --> G[Event Hub]

Key Operations: - Session state persistence - Response logging and analytics - Cache updates - Event publishing

S10: Verbose Response

Files: S10VerboseResponse/S01CreateVerboseResponse.js

Purpose: Generate debug and verbose response information.

graph LR
    A[Debug Mode Check] --> B{Verbose Enabled?}
    B -->|Yes| C[Generate Debug Info]
    B -->|No| D[Standard Response]
    C --> E[Add Pipeline Metrics]
    C --> F[Add Cache Info]
    C --> G[Add Decision Data]

Debug Information: - Pipeline execution metrics - Cache hit/miss statistics - Decision engine data - Performance timings - Error details

🔀 Parallel Processing

Parallel Execution Model

graph TD
    A[Stage Input] --> B{Parallel Capable?}
    B -->|Yes| C[Fork Execution]
    B -->|No| D[Sequential Execution]

    C --> E[Sub-process 1]
    C --> F[Sub-process 2]
    C --> G[Sub-process 3]

    E --> H[Synchronization Point]
    F --> H
    G --> H

    D --> I[Single Thread]
    I --> H

    H --> J[Stage Output]

Stages with Parallel Execution

  • S03: Campaign and brand loading
  • S04: Data processing operations
  • S07: Content generation
  • S09: Response saving operations

📊 Performance Monitoring

Pipeline Metrics

// Pipeline execution metrics
{
  totalExecutionTime: 150, // milliseconds
  stageMetrics: {
    S00: { duration: 5, status: "SUCCESS" },
    S01: { duration: 12, status: "SUCCESS" },
    S02: { duration: 3, status: "SKIPPED" },
    S03: { duration: 25, status: "SUCCESS", parallel: true },
    S04: { duration: 18, status: "SUCCESS", parallel: true },
    S05: { duration: 8, status: "SUCCESS" },
    S06: { duration: 2, status: "SKIPPED" },
    S07: { duration: 45, status: "SUCCESS", parallel: true },
    S08: { duration: 15, status: "SUCCESS" },
    S09: { duration: 10, status: "SUCCESS", parallel: true },
    S10: { duration: 7, status: "SUCCESS" }
  },
  cacheMetrics: {
    hits: 8,
    misses: 3,
    hitRatio: 0.73
  }
}

Next: API Documentation - Comprehensive API documentation and examples