viewof messageRate = Inputs.range([1000, 100000], {
value: 10000,
step: 1000,
label: "Message rate (msg/sec)"
})
viewof consumerCount = Inputs.range([1, 20], {
value: 10,
step: 1,
label: "Number of consumers"
})
viewof processingTime = Inputs.range([1, 100], {
value: 10,
step: 1,
label: "Processing time per message (ms)"
})
// Competing consumers calculations
competingConsumerThroughput = consumerCount * (1000 / processingTime)
competingMessagesPerConsumer = messageRate / consumerCount
competingMemoryMessages = messageRate
competingCanHandle = competingConsumerThroughput >= messageRate
// Fan-out calculations
fanoutThroughput = 1000 / processingTime
fanoutMessagesPerConsumer = messageRate
fanoutMemoryMessages = messageRate * consumerCount
fanoutCanHandle = fanoutThroughput >= messageRate
html`<div style="background: #f8f9fa; padding: 20px; border-left: 4px solid #9B59B6; margin: 20px 0; border-radius: 4px;">
<h4 style="color: #2C3E50; margin-top: 0;">Consumer Pattern Comparison</h4>
<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 15px; margin: 15px 0;">
<div style="background: ${competingCanHandle ? '#d4edda' : '#f8d7da'}; padding: 15px; border-radius: 4px; border: 2px solid ${competingCanHandle ? '#16A085' : '#E74C3C'};">
<h5 style="color: #2C3E50; margin-top: 0;">Competing Consumers</h5>
<div style="margin: 10px 0;">
<div style="color: #7F8C8D; font-size: 0.85em;">Messages per consumer</div>
<div style="color: #2C3E50; font-size: 1.3em; font-weight: bold;">${competingMessagesPerConsumer.toFixed(0)} msg/sec</div>
</div>
<div style="margin: 10px 0;">
<div style="color: #7F8C8D; font-size: 0.85em;">Total throughput capacity</div>
<div style="color: #2C3E50; font-size: 1.3em; font-weight: bold;">${competingConsumerThroughput.toFixed(0)} msg/sec</div>
</div>
<div style="margin: 10px 0;">
<div style="color: #7F8C8D; font-size: 0.85em;">Broker memory (messages)</div>
<div style="color: #2C3E50; font-size: 1.3em; font-weight: bold;">${competingMemoryMessages.toLocaleString()}</div>
</div>
<div style="margin-top: 10px; padding: 8px; background: white; border-radius: 4px; font-size: 0.85em; color: ${competingCanHandle ? '#155724' : '#721c24'}; border: 1px solid ${competingCanHandle ? '#c3e6cb' : '#f5c6cb'};">
${competingCanHandle ? '✓ Can handle load' : '✗ Cannot handle load - add more consumers'}
</div>
</div>
<div style="background: ${fanoutCanHandle ? '#d4edda' : '#f8d7da'}; padding: 15px; border-radius: 4px; border: 2px solid ${fanoutCanHandle ? '#16A085' : '#E74C3C'};">
<h5 style="color: #2C3E50; margin-top: 0;">Fan-Out Distribution</h5>
<div style="margin: 10px 0;">
<div style="color: #7F8C8D; font-size: 0.85em;">Messages per consumer</div>
<div style="color: #2C3E50; font-size: 1.3em; font-weight: bold;">${fanoutMessagesPerConsumer.toFixed(0)} msg/sec</div>
</div>
<div style="margin: 10px 0;">
<div style="color: #7F8C8D; font-size: 0.85em;">Per-consumer throughput needed</div>
<div style="color: #2C3E50; font-size: 1.3em; font-weight: bold;">${fanoutThroughput.toFixed(0)} msg/sec</div>
</div>
<div style="margin: 10px 0;">
<div style="color: #7F8C8D; font-size: 0.85em;">Broker memory (messages)</div>
<div style="color: #E67E22; font-size: 1.3em; font-weight: bold;">${fanoutMemoryMessages.toLocaleString()}</div>
</div>
<div style="margin-top: 10px; padding: 8px; background: white; border-radius: 4px; font-size: 0.85em; color: ${fanoutCanHandle ? '#155724' : '#721c24'}; border: 1px solid ${fanoutCanHandle ? '#c3e6cb' : '#f5c6cb'};">
${fanoutCanHandle ? '✓ Each consumer can handle load' : '✗ Consumers cannot keep up - reduce message rate'}
</div>
</div>
</div>
<div style="background: white; padding: 15px; border-radius: 4px; margin-top: 15px; border: 1px solid #ddd;">
<h5 style="color: #2C3E50; margin-top: 0;">Key Insights</h5>
<div style="font-size: 0.9em; color: #2C3E50; line-height: 1.6;">
• <strong>Memory multiplier:</strong> Fan-out uses ${consumerCount}× more broker memory (${fanoutMemoryMessages.toLocaleString()} vs ${competingMemoryMessages.toLocaleString()} messages)<br>
• <strong>Scaling:</strong> Competing consumers scale linearly (${consumerCount} consumers = ${consumerCount}× throughput)<br>
• <strong>Fan-out bottleneck:</strong> All consumers must process ${messageRate.toLocaleString()} msg/sec independently<br>
• <strong>Use competing consumers for:</strong> Work distribution where each message needs processing once<br>
• <strong>Use fan-out for:</strong> Events where multiple systems need the same data
</div>
</div>
</div>`Competing Consumers vs Fan-Out Performance
Competing Consumers vs Fan-Out Performance
animation
amqp
protocols
messaging
Try Set number of consumers to 10 and change processing time per message.
Observe Compare Messages per consumer and Broker memory (messages) with 10 consumers.
Explain Explain why 10 competing consumers scale throughput linearly.
Technical boundaries. Competing consumers divide the message rate evenly. Fan-out gives every consumer the full message rate, and throughput uses the same processing time for every consumer.