| 1 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 440 512" role="img" aria-labelledby="queuesFlowTitle queuesFlowDesc"> |
| 2 | <title id="queuesFlowTitle">A batch closes on size or on timeout, and an unacknowledged message returns to the queue until the retry bound moves it to the dead-letter queue</title> |
| 3 | <desc id="queuesFlowDesc">The upper panel shows two batches under a consumer with max_batch_size 10 and |
| 4 | max_batch_timeout 5 seconds. A busy queue reaches ten messages before the |
| 5 | timeout, so the batch closes on size. A sparse queue reaches only three |
| 6 | messages, so the batch closes on the timeout and the consumer receives a |
| 7 | partial batch. The timeout runs from the oldest ready message, not from the |
| 8 | last one. The lower panel shows the settlement cycle. One queue cell with one |
| 9 | writer leases a batch to one call of queue(batch, env, ctx). A message that the |
| 10 | handler acknowledges, or that a clean return leaves unsettled, is deleted. A |
| 11 | message that calls retry, that a thrown handler abandons, or that no |
| 12 | settlement reaches, returns to the queue as the same message with its attempts |
| 13 | count raised by one, so a consumer can see a duplicate. When attempts pass |
| 14 | max_retries, the message leaves the loop and moves to the dead-letter queue |
| 15 | cell, which is itself a queue with its own consumer. celld deletes the message |
| 16 | instead when no dead_letter_queue is configured.</desc> |
| 17 | <style> |
| 18 | svg { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; } |
| 19 | text { font-size: 13px; fill: currentColor; } |
| 20 | tspan { fill: currentColor; } |
| 21 | .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; } |
| 22 | .lead { font-weight: 600; } |
| 23 | .sm { font-size: 12px; } |
| 24 | .d-ink { color: #121212; } |
| 25 | .d-soft { color: #3d3b37; } |
| 26 | .d-faint { color: #6e6a62; } |
| 27 | .d-acc { color: #10803f; } |
| 28 | .d-panel { color: #ffffff; } |
| 29 | .d-sunk { color: #f0eee8; } |
| 30 | .d-tint { color: #d6efdf; } |
| 31 | @media (prefers-color-scheme: dark) { |
| 32 | .d-ink { color: #efede7; } |
| 33 | .d-soft { color: #c9c6be; } |
| 34 | .d-faint { color: #928e85; } |
| 35 | .d-acc { color: #3fc472; } |
| 36 | .d-panel { color: #1a1a19; } |
| 37 | .d-sunk { color: #232321; } |
| 38 | .d-tint { color: #10301d; } |
| 39 | } |
| 40 | </style> |
| 41 | <defs> |
| 42 | <marker id="queues-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6" |
| 43 | markerHeight="6" orient="auto-start-reverse"> |
| 44 | <path class="d-soft" fill="currentColor" d="M0 0 L10 5 L0 10 z" /> |
| 45 | </marker> |
| 46 | </defs> |
| 47 | |
| 48 | <!-- Panel one: the batch window, where two limits race. --> |
| 49 | <rect class="d-sunk" fill="currentColor" x="8" y="8" width="424" height="170" rx="10" /> |
| 50 | <rect class="d-faint" fill="none" stroke="currentColor" x="8" y="8" width="424" height="170" rx="10" /> |
| 51 | <text class="d-ink lead" fill="currentColor" x="22" y="32">A batch closes on whichever limit arrives first</text> |
| 52 | <text class="d-faint mono" fill="currentColor" x="22" y="52">max_batch_size 10 · max_batch_timeout 5 s</text> |
| 53 | |
| 54 | <path class="d-faint" fill="none" stroke="currentColor" stroke-dasharray="4 4" d="M300 62 V152" /> |
| 55 | |
| 56 | <!-- A busy queue fills the batch before the clock runs out. --> |
| 57 | <g class="d-acc" fill="currentColor"> |
| 58 | <circle cx="24" cy="82" r="4" /> |
| 59 | <circle cx="48" cy="82" r="4" /> |
| 60 | <circle cx="72" cy="82" r="4" /> |
| 61 | <circle cx="96" cy="82" r="4" /> |
| 62 | <circle cx="120" cy="82" r="4" /> |
| 63 | <circle cx="144" cy="82" r="4" /> |
| 64 | <circle cx="168" cy="82" r="4" /> |
| 65 | <circle cx="192" cy="82" r="4" /> |
| 66 | <circle cx="216" cy="82" r="4" /> |
| 67 | <circle cx="240" cy="82" r="4" /> |
| 68 | </g> |
| 69 | <path class="d-acc" fill="none" stroke="currentColor" stroke-width="2.5" d="M252 68 V96" /> |
| 70 | <text class="d-soft sm" fill="currentColor" x="24" y="105">closes on size, before the timeout</text> |
| 71 | |
| 72 | <!-- A sparse queue reaches the clock with a partial batch. --> |
| 73 | <g class="d-acc" fill="currentColor"> |
| 74 | <circle cx="24" cy="130" r="4" /> |
| 75 | <circle cx="100" cy="130" r="4" /> |
| 76 | <circle cx="184" cy="130" r="4" /> |
| 77 | </g> |
| 78 | <path class="d-acc" fill="none" stroke="currentColor" stroke-width="2.5" d="M300 116 V144" /> |
| 79 | <text class="d-soft sm" fill="currentColor" x="24" y="153">closes on the timeout, 3 messages</text> |
| 80 | <text class="d-faint sm" fill="currentColor" x="308" y="134">partial batch</text> |
| 81 | <text class="d-faint sm" fill="currentColor" x="290" y="170" text-anchor="middle">the timeout runs from the oldest message</text> |
| 82 | |
| 83 | <!-- Panel two: the settlement cycle and the bound that ends it. --> |
| 84 | <text class="d-ink lead" fill="currentColor" x="22" y="204">An unacknowledged message returns to the queue</text> |
| 85 | |
| 86 | <rect class="d-tint" fill="currentColor" x="24" y="216" width="146" height="62" rx="8" /> |
| 87 | <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="24" y="216" width="146" height="62" rx="8" /> |
| 88 | <text class="d-ink" fill="currentColor" x="97" y="242" text-anchor="middle">JOBS queue cell</text> |
| 89 | <text class="d-soft sm" fill="currentColor" x="97" y="262" text-anchor="middle">one writer</text> |
| 90 | |
| 91 | <rect class="d-panel" fill="currentColor" x="240" y="216" width="192" height="62" rx="8" /> |
| 92 | <rect class="d-soft" fill="none" stroke="currentColor" x="240" y="216" width="192" height="62" rx="8" /> |
| 93 | <text class="d-ink mono" fill="currentColor" x="336" y="242" text-anchor="middle">queue(batch, env, ctx)</text> |
| 94 | <text class="d-soft sm" fill="currentColor" x="336" y="262" text-anchor="middle">one batch, one lease</text> |
| 95 | |
| 96 | <g class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5"> |
| 97 | <path d="M170 247 H232" marker-end="url(#queues-arrow)" /> |
| 98 | <path d="M336 278 V336" marker-end="url(#queues-arrow)" /> |
| 99 | <path d="M336 294 H97 V336" marker-end="url(#queues-arrow)" /> |
| 100 | <path d="M24 366 H12 V247 H18" marker-end="url(#queues-arrow)" /> |
| 101 | <path d="M97 406 V440" marker-end="url(#queues-arrow)" /> |
| 102 | </g> |
| 103 | <text class="d-faint sm" fill="currentColor" x="201" y="237" text-anchor="middle">lease</text> |
| 104 | <text class="d-soft sm" fill="currentColor" x="108" y="311">retry(), a throw,</text> |
| 105 | <text class="d-soft sm" fill="currentColor" x="108" y="327">or no settlement</text> |
| 106 | |
| 107 | <rect class="d-panel" fill="currentColor" x="24" y="336" width="146" height="70" rx="8" /> |
| 108 | <rect class="d-soft" fill="none" stroke="currentColor" x="24" y="336" width="146" height="70" rx="8" /> |
| 109 | <text class="d-ink" fill="currentColor" x="97" y="360" text-anchor="middle">back to the queue</text> |
| 110 | <text class="d-soft sm" fill="currentColor" x="97" y="379" text-anchor="middle">attempts + 1</text> |
| 111 | <text class="d-soft sm" fill="currentColor" x="97" y="396" text-anchor="middle">the same message</text> |
| 112 | |
| 113 | <rect class="d-panel" fill="currentColor" x="240" y="336" width="192" height="70" rx="8" /> |
| 114 | <rect class="d-soft" fill="none" stroke="currentColor" x="240" y="336" width="192" height="70" rx="8" /> |
| 115 | <text class="d-ink" fill="currentColor" x="336" y="366" text-anchor="middle">deleted</text> |
| 116 | <text class="d-soft sm" fill="currentColor" x="336" y="387" text-anchor="middle">ack(), or a clean return</text> |
| 117 | |
| 118 | <text class="d-acc mono" fill="currentColor" x="108" y="428">attempts > max_retries</text> |
| 119 | |
| 120 | <rect class="d-tint" fill="currentColor" x="24" y="444" width="250" height="58" rx="8" /> |
| 121 | <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="24" y="444" width="250" height="58" rx="8" /> |
| 122 | <text class="d-ink" fill="currentColor" x="149" y="470" text-anchor="middle">dead-letter queue cell</text> |
| 123 | <text class="d-soft sm" fill="currentColor" x="149" y="490" text-anchor="middle">a queue with its own consumer</text> |
| 124 | |
| 125 | <text class="d-faint sm mono" fill="currentColor" x="286" y="466">no dead_letter_queue</text> |
| 126 | <text class="d-faint sm" fill="currentColor" x="286" y="486">celld deletes it</text> |
| 127 | </svg> |