Capacity Planning for Messaging Systems

Planning Resource Requirements


Introduction

Capacity planning ensures your messaging systems can handle expected load while maintaining performance. For Azure Service Bus and Event Hubs, proper capacity planning prevents bottlenecks, ensures SLA compliance, and optimizes costs. This guide covers systematic approaches to planning messaging capacity.

This comprehensive guide covers:

  • Demand forecasting — Predicting load
  • Sizing calculations — Determining requirements
  • Scaling strategies — Handling growth
  • Cost planning — Budget considerations

Planning Fundamentals

Key Metrics

┌─────────────────────────────────────────────────────────────────────┐
│                  MESSAGING CAPACITY METRICS                         │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   THROUGHPUT:                                                       │
│   • Messages per second (mps)                                       │
│   • Messages per day                                                │
│   • Peak vs average load                                            │
│                                                                     │
│   SIZE:                                                             │
│   • Average message size                                            │
│   • Peak message size                                               │
│   • Total data per day                                              │
│                                                                     │
│   LATENCY:                                                          │
│   • End-to-end delay tolerance                                      │
│   • Processing time per message                                     │
│   • Queue depth impact                                              │
│                                                                     │
│   DURABILITY:                                                       │
│   • Required message retention period                               │
│   • Delivery guarantees needed                                      │
│   └── Number of retry attempts                                      │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Demand Forecasting

public class CapacityForecast
{
    public class ForecastResult
    {
        public int CurrentMPS { get; set; }
        public int ProjectedMPS_6Months { get; set; }
        public int ProjectedMPS_12Months { get; set; }
        public int RecommendedNamespaceUnits { get; set; }
    }

    public ForecastResult GenerateForecast(
        HistoricalData data,
        GrowthProjection growth)
    {
        var currentPeak = data.PeakMessagesPerSecond;
        var growthRate = growth.MonthlyPercent;

        var forecast = new ForecastResult
        {
            CurrentMPS = currentPeak,
            ProjectedMPS_6Months = (int)(currentPeak * Math.Pow(1 + growthRate, 6)),
            ProjectedMPS_12Months = (int)(currentPeak * Math.Pow(1 + growthRate, 12))
        };

        // Add buffer for unexpected growth
        var withBuffer = (int)(forecast.ProjectedMPS_6Months * 1.2);

        // Map to Service Bus Premium messaging units
        forecast.RecommendedNamespaceUnits = MapToMessagingUnits(withBuffer);

        return forecast;
    }

    private int MapToMessagingUnits(int mps)
    {
        // Each messaging unit handles ~1000 mps
        return (int)Math.Ceiling(mps / 1000.0);
    }
}

Service Bus Sizing

Premium Messaging Units

{
  "serviceBusSizing": {
    "messagingUnits": {
      "1_unit": {
        "description": "Entry level",
        "throughput": "~1000 mps",
        "connections": 5000,
        "price": "$150/month"
      },
      "2_units": {
        "description": "Standard load",
        "throughput": "~2000 mps",
        "connections": 10000,
        "price": "$300/month"
      },
      "4_units": {
        "description": "High load",
        "throughput": "~4000 mps",
        "connections": 20000,
        "price": "$600/month"
      },
      "8_units": {
        "description": "Very high load",
        "throughput": "~8000 mps",
        "connections": 40000,
        "price": "$1200/month"
      }
    },
    "calculation": {
      "step1": "Measure peak messages/second",
      "step2": "Add 20% buffer for bursts",
      "step3": "Divide by 1000 (1 unit = 1000 mps)",
      "step4": "Round up to next integer",
      "step5": "Consider connection limits"
    }
  }
}

Example Calculations

┌─────────────────────────────────────────────────────────────────────┐
│                  SIZING EXAMPLES                                    │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   EXAMPLE 1: SMALL WORKLOAD                                         │
│   ───────────────────────────                                       │
│   • 500 messages/second average                                     │
│   • 1000 messages/second peak                                       │
│   • With 20% buffer: 1200 mps                                       │
│   • 1200 / 1000 = 1.2 → Round up to 2 units                         │
│   • Recommended: 2 messaging units                                  │
│                                                                     │
│   EXAMPLE 2: MEDIUM WORKLOAD                                        │
│   ───────────────────────────                                       │
│   • 2000 messages/second average                                    │
│   • 4000 messages/second peak                                       │
│   • With 20% buffer: 4800 mps                                       │
│   • 4800 / 1000 = 4.8 → Round up to 5 units                         │
│   • Recommended: 4-8 messaging units                                │
│                                                                     │
│   EXAMPLE 3: HIGH WORKLOAD                                          │
│   ───────────────────────────                                       │
│   • 8000 messages/second average                                    │
│   • 12000 messages/second peak                                      │
│   • With 20% buffer: 14400 mps                                      │
│   • 14400 / 1000 = 14.4 → Round up to 16 units                      │
│   • Consider partitioning across namespaces                         │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Event Hubs Sizing

Throughput Units

{
  "eventHubsSizing": {
    "throughputUnits": {
      "1_tu": {
        "ingress": "1 MB/s or 1000 events/sec",
        "egress": "2 MB/s",
        "price": "~$25/month"
      }
    },
    "partitionCount": {
      "recommendation": "TU count × 4",
      "min": 2,
      "max": 32,
      "default": 4
    },
    "capture": {
      "storage": "Per event size × retention × partition",
      "enableForAnalytics": true
    }
  }
}

Scaling Strategy

Auto-Scaling Configuration

{
  "autoScaleConfig": {
    "premiumNamespace": {
      "autoScaling": {
        "enabled": true,
        "minimumUnits": 1,
        "maximumUnits": 16,
        "scaleOn": "Throughput exceed 80% for 5 minutes",
        "scaleOff": "Throughput below 30% for 15 minutes"
      }
    }
  }
}

Cost Planning

Cost Estimation

{
  "costPlanning": {
    "serviceBusPremium": {
      "base": "Messaging units × $150/month",
      "additional": [
        "Namespace hours: ~$0.01/hour",
        "Operations: $0.013/10K"
      ]
    },
    "estimation": {
      "example_1": "2 units: $300/month base",
      "example_2": "4 units: $600/month base",
      "example_3": "8 units: $1,200/month base"
    },
    "optimization": {
      "commitment": "Reserve 1 year (20% savings), 3 years (40% savings)",
      "rightSizing": "Review quarterly, adjust as needed"
    }
  }
}

Best Practices

Capacity Planning Checklist

PracticeDescription
Measure actual loadUse metrics, don't guess
Include growth bufferPlan for 6-12 months
Test at scaleLoad test before production
Monitor utilizationTrack actual vs. capacity
Plan for failureConsider region redundancy
Review regularlyQuarterly capacity review

Related Topics


Azure Integration Hub - Architect Level Solution Design & Architecture Reviews