Volume Caps Advanced Configuration
Master sophisticated volume control strategies beyond basic daily limits. Learn dynamic caps, multi-tier management, overflow handling, and intelligent distribution to optimize lead flow and spending.
📍 You Are Here
You need advanced control over lead volume beyond simple daily caps. This guide covers complex capping scenarios, dynamic adjustments, and sophisticated distribution strategies.
🎯 What You'll Learn
- Advanced cap types
- Dynamic cap management
- Multi-dimensional caps
- Overflow strategies
- Cap sharing and pooling
- Performance optimization
🎛️ Advanced Cap Types
Beyond Daily Limits
Sophisticated volume control:
const advancedCaps = {
// Time-based caps
temporal: {
hourly: 100,
daily: 2000,
weekly: 12000,
monthly: 45000,
// Custom periods
custom_periods: [
{
name: "business_hours",
window: "9AM-5PM EST",
cap: 1500
},
{
name: "weekend",
days: ["Sat", "Sun"],
cap: 500
}
]
},
// Conditional caps
conditional: {
by_quality: [
{ score_range: [90, 100], cap: "unlimited" },
{ score_range: [70, 89], cap: 1000 },
{ score_range: [0, 69], cap: 200 }
],
by_state: {
"CA": 500,
"TX": 400,
"FL": 300,
"default": 100
},
by_source: {
"organic": "unlimited",
"paid_search": 1000,
"affiliates": 500,
"default": 200
}
},
// Financial caps
financial: {
daily_spend: 50000,
weekly_spend: 300000,
per_source_spend: 10000,
// Cost per acquisition limits
max_cpa_by_state: {
"CA": 75,
"NY": 65,
"default": 50
}
}
};
Rolling Window Caps
Continuous period tracking:
class RollingWindowCap {
constructor(windowSize, limit) {
this.windowSize = windowSize; // in milliseconds
this.limit = limit;
this.events = [];
}
canAccept() {
this.cleanup();
return this.events.length < this.limit;
}
accept() {
if (this.canAccept()) {
this.events.push(Date.now());
return true;
}
return false;
}
cleanup() {
const cutoff = Date.now() - this.windowSize;
this.events = this.events.filter(time => time > cutoff);
}
getUtilization() {
this.cleanup();
return {
used: this.events.length,
limit: this.limit,
percentage: (this.events.length / this.limit) * 100,
oldest_event: this.events[0],
time_until_available: this.getTimeUntilAvailable()
};
}
getTimeUntilAvailable() {
if (this.canAccept()) return 0;
const oldest = this.events[0];
const availableAt = oldest + this.windowSize;
return Math.max(0, availableAt - Date.now());
}
}
// Usage
const hourlyRollingCap = new RollingWindowCap(
60 * 60 * 1000, // 1 hour
100 // limit
);
Burst Caps
Handle traffic spikes:
const burstCapConfig = {
// Normal operation
sustained_rate: {
per_minute: 10,
per_hour: 500
},
// Burst allowance
burst: {
max_burst_size: 50,
burst_duration: "5 minutes",
cooldown_period: "15 minutes",
// Burst conditions
triggers: [
{
condition: "source_campaign = 'TV_Ad'",
burst_multiplier: 5
},
{
condition: "time_of_day = '20:00-21:00'",
burst_multiplier: 3
}
]
},
// Token bucket algorithm
token_bucket: {
capacity: 100,
refill_rate: 2, // tokens per second
min_tokens_required: 1,
// Variable token costs
token_costs: {
"high_quality": 1,
"medium_quality": 2,
"low_quality": 5
}
}
};
🔄 Dynamic Cap Management
Auto-Adjusting Caps
Intelligent cap modification:
class DynamicCapManager {
constructor(config) {
this.config = config;
this.metrics = new MetricsCollector();
this.adjustmentHistory = [];
}
async evaluateAndAdjust() {
const performance = await this.getPerformanceMetrics();
// Quality-based adjustment
if (performance.conversionRate > 0.8) {
this.increaseCap('high_conversion', 1.2);
} else if (performance.conversionRate < 0.3) {
this.decreaseCap('low_conversion', 0.8);
}
// Cost-based adjustment
if (performance.avgCPA < this.config.targetCPA * 0.8) {
this.increaseCap('efficient_spend', 1.15);
} else if (performance.avgCPA > this.config.targetCPA * 1.2) {
this.decreaseCap('expensive_spend', 0.85);
}
// Time-based patterns
const hourlyPattern = this.analyzeHourlyPattern();
this.adjustHourlyCaps(hourlyPattern);
// Capacity utilization
if (performance.capUtilization > 0.95) {
this.evaluateCapIncrease();
} else if (performance.capUtilization < 0.5) {
this.evaluateCapDecrease();
}
}
adjustHourlyCaps(pattern) {
pattern.forEach(hour => {
if (hour.conversionRate > this.config.minConversionRate) {
this.setHourlyCap(hour.hour, hour.optimalVolume);
}
});
}
increaseCap(reason, multiplier) {
const currentCap = this.getCurrentCap();
const newCap = Math.min(
currentCap * multiplier,
this.config.maxCap
);
this.setCap(newCap, reason);
this.logAdjustment({
action: 'increase',
reason,
from: currentCap,
to: newCap,
timestamp: new Date()
});
}
}
Predictive Capping
Forecast-based caps:
class PredictiveCapManager {
async calculateOptimalCaps() {
const historicalData = await this.getHistoricalData(30); // 30 days
const forecast = this.generateForecast(historicalData);
return {
daily: this.optimizeDailyCaps(forecast),
hourly: this.optimizeHourlyCaps(forecast),
quality_tiers: this.optimizeQualityTiers(forecast)
};
}
generateForecast(data) {
// Moving average with seasonality
const trend = this.calculateTrend(data);
const seasonality = this.extractSeasonality(data);
const dayOfWeekPattern = this.extractDayPattern(data);
// Machine learning prediction
const mlForecast = this.mlModel.predict({
features: [
trend,
seasonality,
dayOfWeekPattern,
this.externalFactors()
]
});
return {
expected_volume: mlForecast.volume,
expected_quality: mlForecast.quality,
confidence_interval: mlForecast.confidence,
recommendations: {
optimal_cap: mlForecast.volume * 1.1, // 10% buffer
quality_threshold: mlForecast.quality_p75,
peak_hours: mlForecast.peak_hours
}
};
}
optimizeDailyCaps(forecast) {
return forecast.days.map(day => ({
date: day.date,
cap: Math.ceil(day.expected_volume * day.quality_factor),
// Tiered caps
tiers: [
{
quality: 'premium',
range: [90, 100],
cap: Math.ceil(day.expected_premium * 1.2)
},
{
quality: 'standard',
range: [70, 89],
cap: Math.ceil(day.expected_standard)
},
{
quality: 'economy',
range: [50, 69],
cap: Math.ceil(day.expected_economy * 0.8)
}
]
}));
}
}
🌐 Multi-Dimensional Caps
Composite Cap Rules
Complex cap combinations:
class CompositeCap {
constructor(rules) {
this.rules = rules;
this.usage = new Map();
}
canAcceptLead(lead) {
// Check all applicable rules
for (const rule of this.rules) {
if (this.ruleApplies(rule, lead)) {
if (!this.checkRule(rule, lead)) {
return {
allowed: false,
reason: rule.name,
rule: rule,
current: this.getUsage(rule),
limit: rule.limit
};
}
}
}
return { allowed: true };
}
checkRule(rule, lead) {
const key = this.generateKey(rule, lead);
const usage = this.usage.get(key) || 0;
// Evaluate limit based on rule type
const limit = this.evaluateLimit(rule, lead);
return usage < limit;
}
generateKey(rule, lead) {
// Create unique key based on dimensions
const dimensions = rule.dimensions.map(dim => {
if (dim === 'time') {
return this.getTimeBucket(rule.timeBucket);
}
return lead[dim] || 'default';
});
return `${rule.name}:${dimensions.join(':')}`;
}
evaluateLimit(rule, lead) {
if (typeof rule.limit === 'number') {
return rule.limit;
}
// Dynamic limit calculation
if (typeof rule.limit === 'function') {
return rule.limit(lead, this.getContext());
}
// Percentage-based limit
if (rule.limit.type === 'percentage') {
const total = this.getTotalForPeriod(rule.period);
return Math.floor(total * rule.limit.value);
}
return Infinity;
}
}
// Example composite rules
const compositeRules = [
{
name: 'state_daily_cap',
dimensions: ['state', 'date'],
limit: 100
},
{
name: 'source_quality_hourly',
dimensions: ['source', 'quality_tier', 'hour'],
limit: (lead) => {
// Dynamic limit based on lead quality
if (lead.quality_score > 90) return 50;
if (lead.quality_score > 70) return 30;
return 10;
}
},
{
name: 'buyer_percentage',
dimensions: ['buyer', 'date'],
limit: {
type: 'percentage',
value: 0.25, // 25% of total daily volume
period: 'day'
}
}
];
Hierarchical Caps
Nested cap structures:
const hierarchicalCaps = {
global: {
daily: 10000,
children: {
by_source_type: {
'direct': {
cap: 4000,
children: {
by_state: {
'CA': 1500,
'TX': 1000,
'FL': 800,
'other': 700
}
}
},
'affiliate': {
cap: 3000,
children: {
by_affiliate: {
'partner_a': 1200,
'partner_b': 1000,
'partner_c': 800
}
}
},
'paid': {
cap: 3000,
children: {
by_campaign: {
'brand': 1500,
'competitor': 1000,
'generic': 500
}
}
}
}
}
}
};
class HierarchicalCapManager {
checkCaps(lead, path = []) {
let node = this.caps.global;
let totalPath = ['global'];
// Traverse hierarchy
for (const segment of path) {
if (!this.checkNodeCap(node, totalPath)) {
return {
allowed: false,
level: totalPath.join('.'),
limit: node.cap,
used: this.getUsage(totalPath)
};
}
// Move to child node
if (node.children && node.children[segment.type]) {
const childKey = this.getChildKey(lead, segment);
node = node.children[segment.type][childKey];
totalPath.push(`${segment.type}.${childKey}`);
} else {
break;
}
}
return { allowed: true };
}
}
💧 Overflow Strategies
Intelligent Overflow Handling
When caps are reached:
class OverflowManager {
constructor(config) {
this.strategies = config.strategies;
this.queues = new Map();
}
handleOverflow(lead, cappedDestination) {
const strategy = this.selectStrategy(lead, cappedDestination);
switch (strategy.type) {
case 'queue':
return this.queueForLater(lead, strategy);
case 'redirect':
return this.redirectToAlternate(lead, strategy);
case 'spillover':
return this.spilloverToNext(lead, strategy);
case 'upgrade':
return this.attemptUpgrade(lead, strategy);
case 'price_adjust':
return this.adjustPricing(lead, strategy);
default:
return this.reject(lead, 'cap_exceeded');
}
}
queueForLater(lead, strategy) {
const queue = this.getQueue(strategy.queueName);
queue.add({
lead,
queued_at: new Date(),
process_after: this.calculateProcessTime(strategy),
priority: this.calculatePriority(lead),
attempts: 0
});
return {
action: 'queued',
queue: strategy.queueName,
position: queue.length,
estimated_process_time: queue.estimatedWait()
};
}
redirectToAlternate(lead, strategy) {
const alternates = this.getAlternateDestinations(lead);
for (const alternate of alternates) {
if (alternate.canAccept(lead)) {
return {
action: 'redirected',
original: cappedDestination,
redirected_to: alternate.id,
price_adjustment: alternate.priceAdjustment || 0
};
}
}
return this.handleNoAlternates(lead);
}
spilloverToNext(lead, strategy) {
// Waterfall through destinations
const waterfall = strategy.waterfall || this.getDefaultWaterfall();
for (const destination of waterfall) {
const capCheck = destination.checkCap(lead);
if (capCheck.available) {
return {
action: 'spillover',
destination: destination.id,
tier: destination.tier,
price: destination.getPrice(lead)
};
}
}
return this.queueForLater(lead, { queueName: 'spillover_queue' });
}
}
Cap Sharing and Pooling
Share caps across entities:
class CapPool {
constructor(config) {
this.poolName = config.name;
this.totalCap = config.totalCap;
this.members = config.members;
this.allocation = config.allocation || 'proportional';
}
allocate() {
switch (this.allocation) {
case 'proportional':
return this.proportionalAllocation();
case 'priority':
return this.priorityAllocation();
case 'performance':
return this.performanceBasedAllocation();
case 'dynamic':
return this.dynamicAllocation();
}
}
proportionalAllocation() {
const weights = this.members.map(m => m.weight || 1);
const totalWeight = weights.reduce((a, b) => a + b, 0);
return this.members.map((member, i) => ({
member: member.id,
allocation: Math.floor(this.totalCap * (weights[i] / totalWeight)),
type: 'guaranteed'
}));
}
performanceBasedAllocation() {
const metrics = this.members.map(m => ({
member: m.id,
conversion: m.getConversionRate(),
revenue: m.getRevenue(),
quality: m.getQualityScore()
}));
// Calculate composite score
const scores = metrics.map(m =>
m.conversion * 0.4 +
m.revenue * 0.4 +
m.quality * 0.2
);
const totalScore = scores.reduce((a, b) => a + b, 0);
return this.members.map((member, i) => ({
member: member.id,
allocation: Math.floor(this.totalCap * (scores[i] / totalScore)),
type: 'performance',
score: scores[i]
}));
}
dynamicAllocation() {
// Real-time adjustment based on usage
const usage = this.getCurrentUsage();
const remaining = this.totalCap - usage.total;
// Redistribute remaining capacity
const activeMembers = this.members.filter(m =>
usage[m.id] < m.minAllocation
);
const distribution = this.redistributeCapacity(
remaining,
activeMembers,
usage
);
return distribution;
}
}
// Usage example
const sharedPool = new CapPool({
name: 'california_pool',
totalCap: 5000,
members: [
{ id: 'buyer_a', weight: 2, minAllocation: 500 },
{ id: 'buyer_b', weight: 1.5, minAllocation: 300 },
{ id: 'buyer_c', weight: 1, minAllocation: 200 }
],
allocation: 'dynamic'
});
📊 Cap Analytics
Usage Tracking
Monitor cap utilization:
class CapAnalytics {
constructor() {
this.metrics = new Map();
this.alerts = [];
}
trackUsage(capRule, event) {
const key = this.getMetricKey(capRule);
const metric = this.metrics.get(key) || this.initMetric(capRule);
metric.used++;
metric.lastUsed = new Date();
// Track patterns
const hour = new Date().getHours();
metric.hourlyPattern[hour]++;
// Check thresholds
this.checkThresholds(capRule, metric);
this.metrics.set(key, metric);
}
checkThresholds(capRule, metric) {
const utilization = metric.used / capRule.limit;
if (utilization > 0.9 && !metric.highUsageAlerted) {
this.alert({
type: 'high_usage',
rule: capRule.name,
utilization: utilization * 100,
message: `Cap ${capRule.name} at ${utilization * 100}% capacity`
});
metric.highUsageAlerted = true;
}
// Velocity check
const velocity = this.calculateVelocity(metric);
if (velocity > capRule.maxVelocity) {
this.alert({
type: 'high_velocity',
rule: capRule.name,
velocity,
message: `Unusually high usage rate for ${capRule.name}`
});
}
}
generateReport(period) {
const report = {
period,
summary: {
total_caps: this.metrics.size,
total_used: this.getTotalUsage(),
avg_utilization: this.getAverageUtilization()
},
by_cap: Array.from(this.metrics.entries()).map(([key, metric]) => ({
cap: key,
usage: metric.used,
limit: metric.limit,
utilization: (metric.used / metric.limit) * 100,
peak_hour: this.getPeakHour(metric.hourlyPattern),
trend: this.calculateTrend(metric)
})),
recommendations: this.generateRecommendations(),
alerts: this.alerts.filter(a =>
a.timestamp > period.start && a.timestamp < period.end
)
};
return report;
}
}
Optimization Recommendations
Data-driven cap adjustments:
class CapOptimizer {
analyzeAndRecommend(historicalData) {
const analysis = {
underutilized: this.findUnderutilized(historicalData),
frequently_capped: this.findFrequentlyCapped(historicalData),
inefficient_distribution: this.findInefficiencies(historicalData),
cost_optimization: this.analyzeCostEfficiency(historicalData)
};
return {
immediate_actions: [
...this.generateImmediateActions(analysis),
],
long_term_recommendations: [
...this.generateLongTermRecs(analysis)
],
estimated_impact: this.estimateImpact(analysis)
};
}
findUnderutilized(data) {
return data.caps.filter(cap => {
const avgUtilization = cap.totalUsed / cap.daysActive / cap.limit;
return avgUtilization < 0.5; // Less than 50% utilized
}).map(cap => ({
cap: cap.name,
current_limit: cap.limit,
avg_usage: cap.avgDaily,
recommendation: `Reduce cap to ${Math.ceil(cap.avgDaily * 1.2)}`,
savings: cap.reservedCost - (cap.avgDaily * 1.2 * cap.unitCost)
}));
}
findFrequentlyCapped(data) {
return data.caps.filter(cap => {
const capHitRate = cap.capHitCount / cap.daysActive;
return capHitRate > 0.8; // Hit cap 80% of days
}).map(cap => ({
cap: cap.name,
current_limit: cap.limit,
times_capped: cap.capHitCount,
lost_opportunity: cap.estimatedOverflow,
recommendation: `Increase cap to ${Math.ceil(cap.limit * 1.3)}`,
revenue_impact: cap.estimatedOverflow * cap.avgValue
}));
}
}
⚡ Performance Optimization
Cap Check Performance
Fast cap validation:
class FastCapChecker {
constructor() {
this.cache = new LRUCache(10000);
this.counters = new Map();
this.lastCleanup = Date.now();
}
async checkCap(lead, rule) {
// Quick cache check
const cacheKey = this.getCacheKey(lead, rule);
const cached = this.cache.get(cacheKey);
if (cached && cached.expires > Date.now()) {
return cached.result;
}
// Efficient counter lookup
const count = await this.getCount(rule);
const limit = await this.getLimit(rule, lead);
const result = {
allowed: count < limit,
used: count,
limit: limit,
remaining: Math.max(0, limit - count)
};
// Cache result
this.cache.set(cacheKey, {
result,
expires: Date.now() + 60000 // 1 minute
});
// Periodic cleanup
this.cleanupIfNeeded();
return result;
}
async getCount(rule) {
const key = this.getCounterKey(rule);
// Try memory first
if (this.counters.has(key)) {
return this.counters.get(key);
}
// Fall back to persistent storage
const count = await this.persistentStorage.get(key) || 0;
this.counters.set(key, count);
return count;
}
increment(rule) {
const key = this.getCounterKey(rule);
const current = this.counters.get(key) || 0;
const updated = current + 1;
this.counters.set(key, updated);
// Async persist
setImmediate(() => {
this.persistentStorage.set(key, updated);
});
return updated;
}
}
Distributed Cap Management
Scale across multiple servers:
class DistributedCapManager {
constructor(config) {
this.nodeId = config.nodeId;
this.redis = config.redisClient;
this.coordination = new CoordinationService(config);
}
async acquireCapacity(rule, requested = 1) {
const key = `cap:${rule.id}:counter`;
const limitKey = `cap:${rule.id}:limit`;
// Lua script for atomic operation
const luaScript = `
local current = redis.call('GET', KEYS[1]) or '0'
local limit = redis.call('GET', KEYS[2]) or '999999'
current = tonumber(current)
limit = tonumber(limit)
local requested = tonumber(ARGV[1])
if current + requested <= limit then
redis.call('INCRBY', KEYS[1], requested)
return {1, current + requested, limit}
else
return {0, current, limit}
end
`;
const result = await this.redis.eval(
luaScript,
2,
key,
limitKey,
requested
);
return {
acquired: result[0] === 1,
total_used: result[1],
limit: result[2],
remaining: result[2] - result[1]
};
}
async releaseCapacity(rule, amount = 1) {
const key = `cap:${rule.id}:counter`;
await this.redis.decrby(key, amount);
}
async resetCaps(pattern) {
// Coordinate reset across nodes
const lock = await this.coordination.acquireLock('cap_reset');
try {
const keys = await this.redis.keys(`cap:${pattern}:counter`);
if (keys.length > 0) {
await this.redis.del(...keys);
}
// Notify other nodes
await this.redis.publish('cap_reset', {
pattern,
timestamp: Date.now(),
node: this.nodeId
});
} finally {
await lock.release();
}
}
}
💡 Best Practices
Cap Design Principles
- Start Conservative: Begin with lower caps and increase
- Monitor Continuously: Track utilization and patterns
- Plan for Peaks: Account for traffic spikes
- Use Appropriate Granularity: Balance precision and performance
- Document Everything: Clear cap purposes and calculations
Implementation Tips
// Good: Clear, testable cap logic
const capConfig = {
name: 'california_daily_premium',
description: 'Daily cap for premium California leads',
conditions: {
state: 'CA',
quality_score: { min: 85 }
},
limit: {
value: 500,
period: 'day',
timezone: 'America/Los_Angeles'
},
overflow: {
strategy: 'queue',
max_queue_time: '4 hours'
},
alerts: {
thresholds: [80, 90, 100],
recipients: ['ops@company.com']
}
};
// Avoid: Unclear, hardcoded logic
if (lead.state === 'CA' && count < 500) { // What's this?
// Accept
}
Testing Strategies
class CapTester {
async testCapScenarios() {
const scenarios = [
{
name: 'Normal operation',
leads: this.generateLeads(100),
expected: { accepted: 100, rejected: 0 }
},
{
name: 'At capacity',
leads: this.generateLeads(500),
expected: { accepted: 500, rejected: 0 }
},
{
name: 'Over capacity',
leads: this.generateLeads(600),
expected: { accepted: 500, rejected: 100 }
},
{
name: 'Burst handling',
leads: this.generateBurst(200, '1 minute'),
expected: { accepted: 150, queued: 50 }
}
];
for (const scenario of scenarios) {
const result = await this.runScenario(scenario);
this.assertResults(result, scenario.expected);
}
}
}
📚 Related Documentation
- Volume Caps Configuration - Basic cap setup
- Flow Performance - Optimization strategies
- Multi-Buyer Distribution - Cap sharing
🎛️ Cap Excellence: Advanced volume management balances business needs with technical constraints. Design thoughtfully, monitor closely, and optimize continuously!
Comments
0 comments
Please sign in to leave a comment.