Skip to main content
← Wednesday's Workflows

Pipeline Forecasting System Architecture 🏗️

Production-grade AI forecasting: 100 to 10,000 deals/day with 95% accuracy

October 16, 2025
19 min read
💼 Sales🏗️ Architecture🤖 Multi-Agent📊 ML Pipeline
🎯This Week's Journey

From prompts to production forecasting system.

Monday: 3 core prompts for deal scoring, risk detection, and forecast generation. Tuesday: automated Python agents. Wednesday: team workflows across sales, ops, and finance. Thursday: complete technical architecture with ML pipeline, multi-agent orchestration, and CRM integration at scale.

📋

Key Assumptions

1
Pipeline contains 100-10,000 active deals at any time
2
Salesforce or similar CRM is source of truth
3
Forecasts updated hourly for critical deals, daily for standard pipeline
4
Historical data available: 12+ months of closed deals for training
5
Compliance: SOC2 Type II, GDPR for EU customers, data residency requirements

System Requirements

Functional

  • Ingest deal data from Salesforce/CRM APIs in real-time
  • Score each deal with win probability (0-100%)
  • Detect risk signals (stalled deals, ghost contacts, pricing issues)
  • Generate weekly/monthly/quarterly forecasts with confidence intervals
  • Provide deal-level recommendations (next best action)
  • Support what-if scenarios (add/remove deals, adjust close dates)
  • Audit trail for all forecast changes and model predictions

Non-Functional (SLOs)

latency p95 ms500
freshness min60
availability percent99.9
forecast accuracy percent95
model inference ms200

💰 Cost Targets: {"per_deal_scored_usd":0.02,"per_forecast_generated_usd":0.5,"monthly_infrastructure_usd":800}

Agent Layer

planner

L4

Decomposes forecast request into subtasks, selects execution strategy

🔧 Pipeline analyzer, Task dependency resolver, Resource allocator

⚡ Recovery: If task fails: retry with exponential backoff (3x), If agent unavailable: reassign to backup agent, If critical path blocked: notify human + fallback to manual

ingestion

L2

Fetch and normalize deal data from Salesforce and other sources

🔧 Salesforce REST API, Data validator, Schema mapper, Deduplicator

⚡ Recovery: If API timeout: retry with jitter (5x), If rate limit: queue and backoff, If schema mismatch: log error + use last known good schema, If data quality < 90%: flag for manual review

scoring

L3

Calculate win probability for each deal using ML model

🔧 Feature store (Feast), ML model (XGBoost/LightGBM), SHAP explainer, Confidence estimator

⚡ Recovery: If model unavailable: fallback to rule-based scoring, If features missing: impute with historical median, If confidence < 70%: flag for human review, If inference timeout: return cached score with staleness warning

risk

L3

Identify deal risks (stalled, ghost contacts, pricing issues)

🔧 Activity analyzer (LLM), Pattern matcher (regex + ML), Email sentiment analyzer, Calendar engagement tracker

⚡ Recovery: If LLM fails: use rule-based fallback, If activity data incomplete: mark as 'insufficient data', If false positive rate > 20%: trigger model retraining

forecast

L3

Aggregate deal scores into period forecasts with confidence intervals

🔧 Monte Carlo simulator, Confidence interval calculator, Scenario engine, Historical accuracy tracker

⚡ Recovery: If simulation fails: use deterministic sum, If confidence interval too wide (>30%): flag as unreliable, If historical accuracy < 80%: trigger model review

evaluator

L4

Validate forecast quality, detect drift, trigger retraining

🔧 Accuracy calculator (MAPE, RMSE), Drift detector (KS test), Model comparator, Alert system

⚡ Recovery: If drift detected: auto-trigger retraining pipeline, If accuracy < 85%: escalate to ML team, If evaluation fails: log error + use last known metrics

guardrail

L4

Enforce policies, redact PII, prevent harmful outputs

🔧 PII detector (regex + NER), Policy engine, Output sanitizer, Audit logger

⚡ Recovery: If PII detected: block output + alert security team, If policy violation: reject + log incident, If guardrail fails: fail-safe (block all outputs)

ML Layer

Feature Store

Update: Hourly for active deals, daily for pipeline

  • deal_age_days
  • stage_duration_days
  • activity_count_30d
  • email_response_rate
  • meeting_count_30d
  • champion_engagement_score
  • account_health_score
  • competitor_mentions
  • pricing_discussions
  • contract_review_started
  • decision_maker_engaged
  • budget_confirmed

Model Registry

Strategy: Semantic versioning (major.minor.patch)

  • deal_scorer_v3
  • risk_detector_v2
  • forecast_aggregator_v1

Observability Stack

Real-time monitoring, tracing & alerting

0 active
SOURCES
Apps, Services, Infra
COLLECTION
9 Metrics
PROCESSING
Aggregate & Transform
DASHBOARDS
4 Views
ALERTS
Enabled
📊Metrics(9)
📝Logs(Structured)
🔗Traces(Distributed)
forecast_generation_time_ms
deal_scoring_latency_p95_ms
salesforce_api_success_rate
model_inference_latency_ms
forecast_accuracy_percent
agent_failure_rate

Deployment Variants

🚀

Startup Architecture

Fast to deploy, cost-efficient, scales to 100 competitors

Infrastructure

AWS (single region: us-east-1)
Serverless (Lambda + API Gateway)
Managed services (RDS, ElastiCache, S3)
OpenAI/Anthropic API (no self-hosted models)
Simple feature store (Redis + S3)
CloudWatch for observability
Time to market: 4-6 weeks
Cost: $200-800/mo (scales with volume)
Team: 2 engineers (full-stack + ML)
Deployment: GitHub Actions + Terraform
Monitoring: CloudWatch + Sentry

Risks & Mitigations

⚠️ Salesforce API rate limits exceeded (5,000 req/day)

High (at scale)

✓ Mitigation: Use Bulk API 2.0 for large syncs. Implement exponential backoff. Cache frequently accessed data. Request higher API limits from Salesforce.

⚠️ Model drift due to market changes (e.g., recession, new competitors)

Medium

✓ Mitigation: Weekly drift detection (KS test). Auto-retrain when drift >0.3. A/B test new models. Monitor forecast accuracy vs actuals.

⚠️ PII leakage in logs or model outputs

Low (with guardrails)

✓ Mitigation: Guardrail agent redacts PII. No PII in prompts. Audit logs reviewed quarterly. Incident response plan for breaches.

⚠️ Agent orchestration failures (deadlocks, infinite loops)

Low

✓ Mitigation: Timeout after 10 sec. Circuit breaker pattern. Fallback to partial results. Replay from checkpoint.

⚠️ Cost overruns from LLM API usage

Medium (at scale)

✓ Mitigation: Set per-user rate limits. Cache LLM responses. Use smaller models for simple tasks. Monitor cost per forecast.

⚠️ Data quality issues (missing fields, stale data)

Medium

✓ Mitigation: Data quality checks (completeness, freshness). Alert if quality <90%. Impute missing values with historical median. Flag low-quality forecasts.

⚠️ Vendor lock-in (Salesforce, AWS, LLM provider)

High

✓ Mitigation: Abstract integrations behind adapters. Use open standards (FHIR, OAuth). Multi-cloud strategy for enterprise. Document migration paths.

🧬

Evolution Roadmap

Progressive transformation from MVP to scale

🌱
Phase 1Weeks 1-12

Phase 1: MVP (0-3 months)

1
Deploy startup architecture (serverless + managed services)
2
Integrate Salesforce (REST API)
3
Implement 3 core agents (Ingestion, Scoring, Forecast)
4
Achieve 90% forecast accuracy on test set
5
Support 100 deals/day
Complexity Level
🌿
Phase 2Weeks 13-24

Phase 2: Scale (3-6 months)

1
Add Risk and Evaluator agents
2
Implement feature store (Feast)
3
Queue-based architecture (SQS + workers)
4
A/B testing framework
5
Support 1,000 deals/day
6
Improve accuracy to 94%
Complexity Level
🌳
Phase 3Weeks 25-52

Phase 3: Enterprise (6-12 months)

1
Multi-region deployment (US, EU, APAC)
2
Kubernetes + event streaming (Kafka)
3
Self-hosted models (TorchServe)
4
Enterprise feature store (Tecton)
5
Support 10,000+ deals/day
6
99.99% SLA
Complexity Level
🚀Production Ready
🏗️

Complete Systems Architecture

9-layer architecture from presentation to security

1
🌐

Presentation

4 components

Sales Dashboard (React)
Forecast UI (Next.js)
Mobile App (React Native)
Slack Bot
2
⚙️

API Gateway

4 components

Load Balancer (ALB/NLB)
Rate Limiter (Redis)
Auth Proxy (OAuth 2.0)
API Gateway (Kong/Apigee)
3
💾

Agent Layer

6 components

Ingestion Agent
Scoring Agent
Risk Agent
Forecast Agent
Orchestrator Agent
Guardrail Agent
4
🔌

ML Layer

5 components

Feature Store (Feast/Tecton)
Model Registry (MLflow)
Inference Service (TorchServe)
Training Pipeline (Airflow)
Evaluation Service
5
📊

Integration

4 components

Salesforce Connector
Email API (SendGrid)
Calendar API (Google/Outlook)
Data Warehouse Sync (Fivetran)
6
🌐

Data

4 components

PostgreSQL (transactional)
Redis (cache + queue)
S3 (data lake)
Snowflake (analytics)
7
⚙️

External

4 components

Salesforce API
OpenAI/Anthropic API
Clearbit/ZoomInfo (enrichment)
Stripe (billing)
8
💾

Observability

5 components

Metrics (Prometheus)
Logs (Loki/CloudWatch)
Traces (Jaeger/Tempo)
Dashboards (Grafana)
Alerts (PagerDuty)
9
🔌

Security

5 components

IAM/RBAC
Secrets Manager (Vault)
KMS (encryption)
WAF (CloudFlare)
Audit Log (immutable)
🔄

Sequence Diagram - Forecast Generation Flow

Automated data flow every hour

Step 0 of 14
Sales RepAPI GatewayOrchestratorIngestion AgentScoring AgentRisk AgentForecast AgentSalesforcePOST /forecast/generateAuthenticate + routeFetch latest pipeline dataGET /opportunities?updated_since=...Return 150 deals (JSON)Normalized deal dataScore all deals (parallel)Win probabilities (0-100%)Detect risks (parallel)Risk flags (stalled, ghost, pricing)Generate forecast with confidence intervalsForecast: $2.3M ± $200K (90% confidence)PATCH /opportunities (update scores)200 OK + forecast JSON

Data Flow - End-to-End

Salesforce → Forecast in 3 seconds

1
Sales Rep0ms
Clicks 'Generate Forecast'Request
2
API Gateway50ms
Authenticates + routesJWT token
3
Orchestrator100ms
Creates execution planTask DAG
4
Ingestion Agent600ms
Fetches deals from Salesforce150 deals (JSON)
5
Feature Store700ms
Enriches with features12 features per deal
6
Scoring Agent1300ms
Batch inference (XGBoost)Win probabilities
7
Risk Agent1300ms
Analyzes activities (parallel)Risk signals
8
Forecast Agent2000ms
Monte Carlo simulationForecast + confidence interval
9
Evaluator Agent2200ms
Validates forecast qualityQuality score
10
Guardrail Agent2300ms
Redacts PII, checks policiesApproved output
11
Salesforce Sync2400ms (non-blocking)
Updates deal scores (async)PATCH requests
12
Orchestrator2500ms
Returns forecast to userJSON response
13
Audit Logger2600ms (async)
Logs forecast eventImmutable log entry
1
Volume
0-100 deals/day
Pattern
Monolith + Serverless
🏗️
Architecture
Single API server (Node.js/Python)
Serverless functions (Lambda) for agents
PostgreSQL (RDS)
Redis (ElastiCache)
Salesforce API (direct calls)
Cost & Performance
$200/mo
per month
3-5 sec
2
Volume
100-1,000 deals/day
Pattern
Queue + Workers
🏗️
Architecture
API server (load balanced)
Message queue (SQS/RabbitMQ)
Worker pool (ECS/K8s)
PostgreSQL (read replicas)
Redis (cluster)
Feature store (Feast + S3)
Cost & Performance
$800/mo
per month
2-4 sec
3
Volume
1,000-10,000 deals/day
Pattern
Multi-Agent Orchestration
🏗️
Architecture
Container orchestration (K8s/ECS)
Event streaming (Kafka)
Agent framework (LangGraph)
Multi-model inference (TorchServe)
Distributed cache (Redis cluster)
Data lake (S3 + Athena)
Feature store (Tecton)
Cost & Performance
$3,000/mo
per month
1-3 sec
Recommended
4
Volume
10,000+ deals/day
Pattern
Enterprise Multi-Region
🏗️
Architecture
Global load balancer (CloudFront/CloudFlare)
Multi-region K8s clusters
Event mesh (Kafka + NATS)
Model serving (KServe/Seldon)
Distributed DB (CockroachDB/Spanner)
Multi-cloud (AWS + GCP/Azure)
Feature store (Tecton enterprise)
Cost & Performance
$10,000+/mo
per month
500ms-2 sec

Key Integrations

Salesforce CRM

Protocol: REST API + Bulk API 2.0
Sync: Fetch opportunities via REST API (incremental, updated_since)
Bulk: Use Bulk API 2.0 for initial load (>2000 records)
Write-back: PATCH scores to custom fields (async queue)
Webhooks: Subscribe to Opportunity updates (Platform Events)

Email APIs (Gmail/Outlook)

Protocol: IMAP + OAuth 2.0
Fetch: Pull emails related to deals (filter by contact email)
Parse: Extract sentiment, urgency, next steps (LLM)
Enrich: Update activity log with email metadata
Privacy: Never store email content, only metadata

Calendar APIs (Google/Outlook)

Protocol: CalDAV + OAuth 2.0
Fetch: Pull meeting invites with deal contacts
Analyze: Count meetings, detect no-shows, measure engagement
Enrich: Update deal activity score
Privacy: Only meeting metadata (time, attendees), no content

Data Warehouse (Snowflake)

Protocol: JDBC + Snowpipe
Export: Stream deal scores, forecasts to Snowflake (Snowpipe)
Analytics: BI tools (Tableau/Looker) query warehouse
Historical: 2+ years of closed deals for model training
Sync: Hourly incremental loads

Security & Compliance

Failure Modes & Recovery

FailureFallbackImpactSLA
Salesforce API downUse cached deal data (max age: 1 hour) + alert sales opsDegraded (stale data), not broken99.9% (Salesforce SLA)
ML model inference timeoutUse rule-based scoring (stage × amount × age)Lower accuracy (85% vs 94%), but functional99.5% (model availability)
Feature store unavailableUse cached features (Redis) or compute on-the-flyIncreased latency (2x), but accurate99.9%
Forecast generation fails (Monte Carlo crash)Use deterministic sum (probability × amount)No confidence intervals, but forecast available99.0%
Agent orchestration deadlockTimeout after 10 sec, return partial resultsIncomplete forecast, flagged as 'partial'99.5%
Database connection pool exhaustedQueue requests, return 503 (retry after)Temporary unavailability (30-60 sec)99.9%
PII detected in outputBlock output, alert security team, log incidentForecast unavailable until manual review100% (safety first)

RAG vs Fine-Tuning for Risk Detection

Hallucination Detection in Deal Scoring

Model hallucinates unrealistic win probabilities (e.g., 99% for early-stage deal)
L1
Confidence threshold (reject if model confidence <70%)
L2
Logical consistency (e.g., stage 1 deal can't be >50%)
L3
Historical comparison (flag if score deviates >30% from similar deals)
L4
Human review queue (sales manager approves flagged deals)
Hallucination rate: 1.2% (flagged), 100% caught before reaching users

Evaluation Framework

Forecast Accuracy (MAPE)
8.3%target: <10%
Deal Scoring Precision
94.1%target: >90%
Deal Scoring Recall
89.7%target: >85%
Risk Detection F1
88.9%target: >85%
Model Latency (p95)
320mstarget: <500ms
Testing: Shadow mode: Run new model on 10% of traffic for 2 weeks. Compare accuracy, latency, cost. A/B test if metrics improve >5%.

Dataset Curation

1
Collect: 50K closed deals (2 years) - Export from Salesforce
2
Clean: 42K usable (remove duplicates, test accounts) - Deduplication + data quality checks
3
Label: 42K labeled (won/lost, risk flags) - ($$0 (labels from CRM))
4
Augment: +8K synthetic (edge cases) - SMOTE for imbalanced classes + LLM-generated risk scenarios
5
Split: Train: 40K, Val: 5K, Test: 5K - Time-based split (avoid data leakage)
50K high-quality examples. Class balance: 60% won, 40% lost. Risk coverage: 15% of deals.

Agentic RAG for Deal Insights

Agent iteratively retrieves context based on reasoning
Deal mentions 'competitor X pricing'. Agent reasons: 'Need competitor pricing data + our pricing + win rates vs X'. RAG retrieves: (1) Competitor X pricing sheet, (2) Our pricing for similar deals, (3) Historical win rate vs X (35%). Agent generates insight: 'Risk: Competitor X is 20% cheaper. Recommendation: Emphasize ROI, not price.'
💡 Not one-shot retrieval. Agent decides what context it needs, retrieves iteratively, reasons over combined context.

Continuous Learning Loop

1
: -
2
: -
3
: -
4
: -
5
: -
6
: -
7
: -

Tech Stack Summary

LLMs
Claude 3.5 Sonnet (Anthropic) or GPT-4 (OpenAI)
ML Models
XGBoost (deal scoring), BERT (risk detection), statsmodels (forecasting)
Orchestration
LangGraph (agent framework) or custom DAG engine
Feature Store
Feast (open-source) or Tecton (enterprise)
Model Registry
MLflow or SageMaker Model Registry
Database
PostgreSQL (RDS) or CockroachDB (multi-region)
Cache
Redis (ElastiCache) or Memcached
Queue
SQS (startup) or Kafka (enterprise)
Compute
Lambda (startup) or EKS (enterprise)
Monitoring
CloudWatch (startup) or Datadog (enterprise)
Security
AWS Secrets Manager, KMS, WAF, GuardDuty
CI/CD
GitHub Actions (startup) or ArgoCD (enterprise)
🏗️

Need Architecture Review?

We'll audit your forecasting system, identify bottlenecks, and show you how to scale 10x with AI agents.

©

2026 Randeep Bhatia. All Rights Reserved.

No part of this content may be reproduced, distributed, or transmitted in any form without prior written permission.