Delivery Guarantee Simulator
Try Set network failure rate to 20% and change delivery pattern.
Observe Compare Delivered, Lost, Duplicates, and Illustrative work units for 20 messages.
Explain Explain why 1 retry does not guarantee arrival.
Play
Reset
Technical boundaries. The model assumes one retry after an uncertain first attempt and counts unconfirmed results as lost. Real broker guarantees depend on confirms, persistence, routing, consumer acknowledgments, and recovery.
Select a delivery pattern in this simplified model. It assumes one retry after an uncertain first attempt; an unconfirmed result is counted as lost in the display. Real broker guarantees depend on confirms, persistence, routing, consumer acknowledgments, and recovery.
viewof simGuarantee = Inputs. select (["At-Most-Once" , "At-Least-Once" , "Idempotent application" ], {value : "At-Least-Once" , label : "Delivery pattern" })
viewof simFailRate = Inputs. range ([0 , 80 ], {value : 20 , step : 5 , label : "Network failure rate (%)" })
viewof simMessageCount = Inputs. range ([5 , 50 ], {value : 20 , step : 1 , label : "Messages to send" })
viewof simRunBtn = Inputs. button ("Run Simulation" , {reduce : (x) => (x || 0 ) + 1 })
simResults = {
simRunBtn;
const count = simMessageCount;
const failPct = simFailRate / 100 ;
const mode = simGuarantee;
let sent = 0 , delivered = 0 , lost = 0 , duplicates = 0 , overhead = 0 ;
for (let i = 0 ; i < count; i++ ) {
sent++;
const fails = Math . random () < failPct;
if (mode === "At-Most-Once" ) {
if (fails) { lost++; } else { delivered++; }
overhead += 0 ;
} else if (mode === "At-Least-Once" ) {
if (fails) {
overhead += 1 ;
const retryFails = Math . random () < failPct * 0.5 ;
if (retryFails) {
overhead += 1 ;
lost++;
} else {
delivered++;
if (Math . random () < 0.15 ) { duplicates++; }
}
} else {
delivered++;
overhead += 1 ;
}
} else {
// Same bounded retry model, with a durable idempotency check at the business action.
overhead += 2 ;
if (fails && Math . random () < failPct * 0.5 ) {
lost++;
overhead += 1 ;
} else {
delivered++;
if (fails) overhead += 1 ;
}
}
}
return {sent, delivered, lost, duplicates, overhead, mode};
}
html `
<div style="background: #f8f9fa; padding: 20px; border-radius: 8px; border-left: 4px solid #9B59B6; margin: 20px 0;">
<div style="font-size: 15px; font-weight: bold; color: #2C3E50; margin-bottom: 15px;">Simulation Results: ${ simResults. mode } </div>
<div style="display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 15px;">
<div style="background: white; padding: 12px; border-radius: 6px; text-align: center;">
<div style="font-size: 11px; color: #7F8C8D;">Sent</div>
<div style="font-size: 22px; font-weight: bold; color: #2C3E50;"> ${ simResults. sent } </div>
</div>
<div style="background: white; padding: 12px; border-radius: 6px; text-align: center;">
<div style="font-size: 11px; color: #7F8C8D;">Delivered</div>
<div style="font-size: 22px; font-weight: bold; color: #16A085;"> ${ simResults. delivered } </div>
</div>
<div style="background: white; padding: 12px; border-radius: 6px; text-align: center;">
<div style="font-size: 11px; color: #7F8C8D;">Lost</div>
<div style="font-size: 22px; font-weight: bold; color: #E74C3C;"> ${ simResults. lost } </div>
</div>
<div style="background: white; padding: 12px; border-radius: 6px; text-align: center;">
<div style="font-size: 11px; color: #7F8C8D;">Duplicates</div>
<div style="font-size: 22px; font-weight: bold; color: #E67E22;"> ${ simResults. duplicates } </div>
</div>
<div style="background: white; padding: 12px; border-radius: 6px; text-align: center;">
<div style="font-size: 11px; color: #7F8C8D;">Illustrative work units</div>
<div style="font-size: 22px; font-weight: bold; color: #7F8C8D;"> ${ simResults. overhead } </div>
</div>
</div>
<svg width="100%" height="60" viewBox="0 0 500 60">
${ Array . from ({length : simResults. sent }, (_, i) => {
const x = 10 + (i % 25 ) * 19 ;
const y = i < 25 ? 10 : 35 ;
const isLost = i < simResults. lost ;
const isDup = ! isLost && i >= simResults. sent - simResults. duplicates ;
const color = isLost ? "#E74C3C" : isDup ? "#E67E22" : "#16A085" ;
return `<rect x=" ${ x} " y=" ${ y} " width="15" height="15" rx="2" fill=" ${ color} " opacity="0.85"/>` ;
}). join ("" )}
</svg>
<div style="display: flex; gap: 15px; font-size: 11px; color: #7F8C8D; margin-top: 8px;">
<span><span style="display:inline-block;width:12px;height:12px;background:#16A085;border-radius:2px;vertical-align:middle;margin-right:4px;"></span> Delivered</span>
<span><span style="display:inline-block;width:12px;height:12px;background:#E74C3C;border-radius:2px;vertical-align:middle;margin-right:4px;"></span> Lost</span>
<span><span style="display:inline-block;width:12px;height:12px;background:#E67E22;border-radius:2px;vertical-align:middle;margin-right:4px;"></span> Duplicate</span>
</div>
<div style="background: white; padding: 12px; border-radius: 6px; margin-top: 12px;">
<div style="font-size: 12px; color: #2C3E50; line-height: 1.7;">
<strong>Insight:</strong>
${ simResults. mode === "At-Most-Once" ? `In this run, ${ simResults. lost } of ${ simResults. sent } messages were lost without a retry. Periodic telemetry may tolerate this; commands may not.` : simResults. mode === "At-Least-Once" ? `After one modeled retry, ${ simResults. lost } remain unconfirmed and ${ simResults. duplicates } duplicate(s) occurred. More retries and recovery can improve delivery, but consumers must tolerate redelivery.` : `With an assumed durable idempotency check, ${ simResults. delivered } business actions succeeded once and ${ simResults. lost } remain unconfirmed after the bounded retry. Idempotency does not guarantee arrival.` }
</div>
</div>
</div>
`
Back to the chapter