viewof numPublishers = Inputs.range([100, 5000], {
value: 1200,
step: 100,
label: "Number of message publishers:",
format: x => x.toLocaleString()
})
viewof msgPerSecPerPublisher = Inputs.range([1, 10], {
value: 4,
step: 1,
label: "Messages per second (per publisher):"
})
viewof msgSizeBytes = Inputs.range([100, 500], {
value: 200,
step: 50,
label: "Average message size (bytes):",
format: x => `${x} B`
})
viewof numConsumers = Inputs.range([1, 10], {
value: 3,
step: 1,
label: "Number of consumers:"
})
viewof topicFilterPercent = Inputs.range([10, 100], {
value: 50,
step: 10,
label: "% messages each consumer needs:",
format: x => `${x}%`
})
// Calculations
totalMsgPerSec = numPublishers * msgPerSecPerPublisher
bytesPerSec = totalMsgPerSec * msgSizeBytes
// Direct exchange (publish to each consumer separately)
directPublishBandwidth = bytesPerSec * numConsumers
directQueueBandwidth = bytesPerSec // Each consumer gets their dedicated queue
// Topic exchange (publish once, broker routes)
topicPublishBandwidth = bytesPerSec
topicQueueBandwidth = bytesPerSec * (topicFilterPercent / 100) // Each consumer gets filtered subset
// Fanout exchange (publish once, broadcast to all)
fanoutPublishBandwidth = bytesPerSec
fanoutQueueBandwidth = bytesPerSec * numConsumers
// Waste calculations
directWaste = bytesPerSec * numConsumers * (1 - topicFilterPercent / 100)
topicWaste = 0
fanoutWaste = bytesPerSec * numConsumers * (1 - topicFilterPercent / 100)
isNarrowBandwidth = typeof window !== 'undefined' && window.innerWidth < 700
html`<div style="background: #f8f9fa; border-left: 4px solid #2C3E50; padding: 15px; margin-top: 15px; font-family: Arial, sans-serif;">
<h4 style="color: #2C3E50; margin-top: 0;">Bandwidth Comparison: ${totalMsgPerSec.toLocaleString()} msg/s</h4>
<div style="display: grid; grid-template-columns: ${isNarrowBandwidth ? '1fr' : 'repeat(3, 1fr)'}; gap: 12px; margin-top: 10px;">
<!-- Direct Exchange -->
<div style="background: white; padding: 12px; border-radius: 4px; border: 2px solid #E67E22;">
<div style="color: #E67E22; font-weight: bold; font-size: 14px; margin-bottom: 8px;">Direct (3x Publish)</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">Publish Bandwidth</div>
<div style="color: #2C3E50; font-size: 18px; font-weight: bold;">${(directPublishBandwidth / 1024 / 1024).toFixed(2)} MB/s</div>
</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">Queue Bandwidth (per consumer)</div>
<div style="color: #2C3E50; font-size: 14px;">${(directQueueBandwidth / 1024).toFixed(0)} KB/s</div>
</div>
<div style="background: #fee; padding: 6px; border-radius: 3px; font-size: 11px; color: #E74C3C;">
${numConsumers}x publish traffic; ${(directWaste / 1024 / 1024).toFixed(2)} MB/s of queue traffic is filtered by consumers
</div>
</div>
<!-- Topic Exchange -->
<div style="background: white; padding: 12px; border-radius: 4px; border: 2px solid #16A085;">
<div style="color: #16A085; font-weight: bold; font-size: 14px; margin-bottom: 8px;">Topic (1x Publish)</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">Publish Bandwidth</div>
<div style="color: #2C3E50; font-size: 18px; font-weight: bold;">${(topicPublishBandwidth / 1024 / 1024).toFixed(2)} MB/s</div>
</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">Queue Bandwidth (per consumer)</div>
<div style="color: #2C3E50; font-size: 14px;">${(topicQueueBandwidth / 1024).toFixed(0)} KB/s</div>
</div>
<div style="background: #efe; padding: 6px; border-radius: 3px; font-size: 11px; color: #16A085;">
Filtered routing under the assumed equal match ratio
</div>
</div>
<!-- Fanout Exchange -->
<div style="background: white; padding: 12px; border-radius: 4px; border: 2px solid #E74C3C;">
<div style="color: #E74C3C; font-weight: bold; font-size: 14px; margin-bottom: 8px;">Fanout (Broadcast)</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">Publish Bandwidth</div>
<div style="color: #2C3E50; font-size: 18px; font-weight: bold;">${(fanoutPublishBandwidth / 1024 / 1024).toFixed(2)} MB/s</div>
</div>
<div style="margin-bottom: 8px;">
<div style="color: #7F8C8D; font-size: 11px;">Queue Bandwidth (total)</div>
<div style="color: #2C3E50; font-size: 14px;">${(fanoutQueueBandwidth / 1024 / 1024).toFixed(2)} MB/s</div>
</div>
<div style="background: #fee; padding: 6px; border-radius: 3px; font-size: 11px; color: #E74C3C;">
${((1 - topicFilterPercent / 100) * 100).toFixed(0)}% wasted
</div>
</div>
</div>
<div style="margin-top: 15px; padding: 12px; background: #efe; border-radius: 4px; border-left: 4px solid #16A085;">
<div style="color: #2C3E50; font-weight: bold; margin-bottom: 5px;">Recommendation: Topic Exchange</div>
<div style="color: #2C3E50; font-size: 13px;">
Saves ${((directPublishBandwidth - topicPublishBandwidth) / 1024 / 1024).toFixed(2)} MB/s publish bandwidth vs. Direct (${(((directPublishBandwidth - topicPublishBandwidth) / directPublishBandwidth) * 100).toFixed(0)}% reduction).
${fanoutWaste > 0 ? ` Avoids ${(fanoutWaste / 1024 / 1024).toFixed(2)} MB/s wasted bandwidth vs. Fanout.` : ''}
</div>
</div>
`Interactive Calculator: Exchange Type Bandwidth Comparison
Interactive Calculator: Exchange Type Bandwidth Comparison
animation
amqp
protocols
messaging
Try Change number of consumers to 5.
Observe Watch Publish Bandwidth and Queue Bandwidth after Calculate bandwidth.
Explain Explain why topic routing uses 1 publish under the assumed equal match ratio.
Technical boundaries. Topic routing assumes an equal match ratio for each consumer. Bandwidth uses message rate and average message size.