<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: KasimirBerg5341</title>
    <description>The latest articles on DEV Community by KasimirBerg5341 (@kasimirberg5341).</description>
    <link>https://dev.to/kasimirberg5341</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4096547%2F5ecd291a-3a27-4b91-990f-29dae833014d.png</url>
      <title>DEV Community: KasimirBerg5341</title>
      <link>https://dev.to/kasimirberg5341</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kasimirberg5341"/>
    <language>en</language>
    <item>
      <title>Google Cloud Pub/Sub Dead Letter Queues vs AWS SQS DLQ — Weekly Edtech Digest Retries</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Sun, 25 Oct 2026 02:17:21 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/google-cloud-pubsub-dead-letter-queues-vs-aws-sqs-dlq-weekly-edtech-digest-retries-5em8</link>
      <guid>https://dev.to/kasimirberg5341/google-cloud-pubsub-dead-letter-queues-vs-aws-sqs-dlq-weekly-edtech-digest-retries-5em8</guid>
      <description>&lt;p&gt;Short answer: choose the dead-letter design that makes delivery evidence easiest to prove, not the one with the most attractive retry vocabulary. For a weekly digest sent to active students, both Google Cloud Pub/Sub and Amazon SQS can support at-least-once processing with a dead-letter destination. Neither destination turns an ambiguous handoff into exactly-once email delivery. The design still needs an idempotency key, a durable delivery record, and an operator-visible reason for every quarantine.&lt;/p&gt;

&lt;p&gt;The important distinction is operational. Pub/Sub forwards an undeliverable message from a subscription to a dead-letter topic after an approximate number of delivery attempts, with a configurable range of 5 to 100. SQS moves a message after its receive count reaches &lt;code&gt;maxReceiveCount&lt;/code&gt;. Those controls look similar in a diagram, but they measure different observations and create different proof obligations.&lt;/p&gt;

&lt;h2&gt;
  
  
  What guarantee does a weekly digest actually need?
&lt;/h2&gt;

&lt;p&gt;Start with the business event, not the queue. A digest job represents a particular customer, reporting period, and content revision. I would derive one stable key from those values and write a delivery record before acknowledging the queue message. The mail provider is then an effect of that record, not the source of truth.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;


&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DigestJob&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;period&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;revision&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;

    &lt;span class="nd"&gt;@property&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;idempotency_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;digest:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;customer_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;period&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;revision&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;should_send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;DigestJob&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;delivery_store&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;delivery_store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sending&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That record must distinguish &lt;code&gt;queued&lt;/code&gt;, &lt;code&gt;sending&lt;/code&gt;, &lt;code&gt;sent&lt;/code&gt;, and &lt;code&gt;failed&lt;/code&gt;, with timestamps and the last error class. A worker crash after the email API accepts the request but before the acknowledgement is the classic duplicate boundary. A DLQ can preserve the job for inspection; it cannot retract the first email.&lt;/p&gt;

&lt;p&gt;Do not confuse quarantine with deletion.&lt;/p&gt;

&lt;p&gt;For this workload, I would define the guarantee as: every eligible digest is either sent once as observed by the delivery ledger, or remains recoverable with enough evidence to retry safely. That is a narrower and more honest contract than “exactly once.”&lt;/p&gt;

&lt;h2&gt;
  
  
  Why do Pub/Sub and SQS DLQs behave differently?
&lt;/h2&gt;

&lt;p&gt;The comparison belongs after the contract because the settings are not interchangeable. Pub/Sub uses a dead-letter topic attached to a subscription. The service forwards messages that exceed the configured delivery-attempt threshold, and the forwarding path depends on the required service-agent permissions. Google documents the delivery-attempt count as approximate, so it is a trigger for quarantine rather than a precise execution counter.&lt;/p&gt;

&lt;p&gt;SQS uses a redrive policy on the source queue, with &lt;code&gt;maxReceiveCount&lt;/code&gt; controlling when a message is moved to its dead-letter queue. The source queue and DLQ must satisfy the service's queue-type and regional constraints. A visibility-timeout expiration makes a message visible again, so a receive count records receive cycles, not necessarily completed worker attempts. Retention behavior also matters: for standard queues, the original enqueue timestamp is retained for expiration accounting after movement; FIFO queues have different timestamp behavior.&lt;/p&gt;

&lt;p&gt;The storage-minded question is therefore: which timestamp and counter will an on-call engineer trust during a digest incident? If the answer is “the number in the console,” the design is incomplete. Persist the application attempt, the broker metadata you receive, and the transition that caused quarantine.&lt;/p&gt;

&lt;p&gt;That is the limit.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concern&lt;/th&gt;
&lt;th&gt;Pub/Sub dead-letter topic&lt;/th&gt;
&lt;th&gt;SQS dead-letter queue&lt;/th&gt;
&lt;th&gt;Design consequence&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Quarantine trigger&lt;/td&gt;
&lt;td&gt;Approximate delivery-attempt threshold&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;maxReceiveCount&lt;/code&gt; on receive/redrive behavior&lt;/td&gt;
&lt;td&gt;Treat both as safety valves, not business truth&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Destination shape&lt;/td&gt;
&lt;td&gt;Topic consumed through another subscription&lt;/td&gt;
&lt;td&gt;Queue read directly by a consumer&lt;/td&gt;
&lt;td&gt;Keep replay tooling behind an internal interface&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Duplicate boundary&lt;/td&gt;
&lt;td&gt;Forwarding and acknowledgement remain separate effects&lt;/td&gt;
&lt;td&gt;Visibility expiry and deletion remain separate effects&lt;/td&gt;
&lt;td&gt;Make the digest ledger idempotent&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Evidence&lt;/td&gt;
&lt;td&gt;Delivery metadata plus application logs&lt;/td&gt;
&lt;td&gt;Receive metadata plus application logs&lt;/td&gt;
&lt;td&gt;Store a correlation key outside the broker&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Azure Service Bus uses a dead-letter subqueue and a delivery-count threshold, which is another useful comparison: a third implementation still does not remove the need for an application-level ledger. The names differ; the failure boundary does not.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which failures should be retried, and which should be quarantined?
&lt;/h2&gt;

&lt;p&gt;A retry policy should classify errors before it counts them. A temporary timeout from the content store can be retried with bounded exponential backoff. A malformed recipient address should go to quarantine without consuming a week of repeated attempts. A permission error needs an alert and a short retry window, because blindly replaying it only produces more identical failures.&lt;/p&gt;

&lt;p&gt;The classifier should be deterministic and recorded with the job. Keep the broker callback small: fetch the job, apply the decision, and make the acknowledgement or visibility change explicit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;enum&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Enum&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Enum&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;RETRY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;retry&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;QUARANTINE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;quarantine&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;MARK_SENT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mark_sent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Exception&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MARK_SENT&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;TimeoutError&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;ConnectionError&lt;/span&gt;&lt;span class="p"&gt;)):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;RETRY&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;isinstance&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;QUARANTINE&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Action&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;QUARANTINE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is intentionally conservative. An unknown exception is not evidence that a retry is safe. It may be a programming defect, a schema mismatch, or a side effect that already succeeded. The DLQ should receive enough context to answer three questions without reconstructing the entire week: what digest was intended, what was attempted, and why did the worker stop?&lt;/p&gt;

&lt;p&gt;Do not use the broker's dead-letter payload as your only archive. Message retention, destination retention, and replay permissions are operational settings, not a permanent audit strategy. The delivery ledger and immutable application logs should have an owner and a retention policy that matches the promises made to customers.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should the comparison change the architecture?
&lt;/h2&gt;

&lt;p&gt;I would hide the broker behind four operations: publish, receive, acknowledge, and quarantine. The adapter can translate a Pub/Sub topic or an SQS queue into those operations, while the digest service owns idempotency, error classification, and replay authorization. That boundary is more valuable than pretending the two services expose the same semantics.&lt;/p&gt;

&lt;p&gt;A replay command should accept a digest key or a reviewed batch, create a new attempt record, and refuse to send a job already marked &lt;code&gt;sent&lt;/code&gt; unless an operator explicitly supplies a new revision. Replaying an entire dead-letter destination by default is a poor fit for customer mail: one poison message can be joined by many valid messages, and a bulk action makes the blast radius hard to inspect.&lt;/p&gt;

&lt;p&gt;The trade-off is deliberate: a reviewed replay is slower than a bulk redrive, but it gives the operator a chance to separate an expired recipient record from a transient outage. A bulk redrive is useful only when the failure class is known, the downstream side effect is idempotent, and the team has a bounded way to stop it. Without those conditions, the queue's convenience is purchased with an unmeasured customer-visible risk.&lt;/p&gt;

&lt;p&gt;For observability, measure the states that explain customer impact: age of the oldest queued digest, number of jobs by failure class, quarantine rate, time from &lt;code&gt;sending&lt;/code&gt; to &lt;code&gt;sent&lt;/code&gt;, and duplicate-prevention decisions. Alerting only on queue depth misses a worker that is acknowledging messages before it writes the ledger.&lt;/p&gt;

&lt;p&gt;The same test matrix should run against both adapters. Inject a timeout before the external send, after the external send, before acknowledgement, and after acknowledgement. Then verify that a replay cannot create a second send for the same idempotency key. Test malformed payloads separately. Also test permissions for the dead-letter destination, because a configured destination that the service cannot publish to is a configuration failure, not a recoverable customer job.&lt;/p&gt;

&lt;p&gt;The most useful test is the uncomfortable one: let the worker lose its process after the downstream mail request returns success, then let the broker deliver the same job again. The expected result is not “the message was eventually acknowledged.” The expected result is a single delivery-ledger transition, one recorded external request, and a second worker that declines to send because the idempotency key is already resolved. If the implementation cannot observe that boundary, a green retry dashboard says very little about customer-visible duplicates. This test also exposes a common storage mistake: treating a &lt;code&gt;sending&lt;/code&gt; row as proof that the external request failed, when it may instead mean that the process disappeared after the request succeeded.&lt;/p&gt;

&lt;p&gt;That boundary deserves its own runbook entry. Name the job key, the ledger row, the broker message identifier, and the external request identifier separately; they answer different questions during replay. The broker identifier tells you what was redelivered, while the idempotency key tells you whether the business effect was already claimed. The external request identifier is the evidence to ask the mail system about. Collapsing those values into one log field makes a duplicate investigation look tidy while removing the links needed to prove what happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  A restrained rollout for delivery guarantees
&lt;/h2&gt;

&lt;p&gt;Roll out the weekly digest path in stages. First, write delivery records and observe the existing worker without changing its send policy. Next, enable bounded retries for a single customer cohort and inspect the failure taxonomy. Then enable quarantine and replay only after an operator can locate a job, read its evidence, and make a reversible decision.&lt;/p&gt;

&lt;p&gt;The broker choice is easy to revisit while the queue adapter is isolated. The delivery contract is expensive to revisit after customers have received duplicates or missed a digest. Make that contract the stable part: at-least-once job processing, idempotent effects, explicit quarantine, and evidence that survives a broker migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/pubsub/docs/dead-letter-topics" rel="noopener noreferrer"&gt;https://cloud.google.com/pubsub/docs/dead-letter-topics&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/azure/service-bus-messaging/message-transfers-locks-settlement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dead-letter-queues" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dead-letter-queues&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/" rel="noopener noreferrer"&gt;https://aws.amazon.com/builders-library/making-retries-safe-with-idempotent-APIs/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>messaging</category>
      <category>deadletterqueues</category>
      <category>edtech</category>
    </item>
    <item>
      <title>Delayed Node.js Queue Scheduling for Shipment Updates (and Why I Chose One)</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Sat, 24 Oct 2026 02:11:40 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/delayed-nodejs-queue-scheduling-for-shipment-updates-and-why-i-chose-one-4p4g</link>
      <guid>https://dev.to/kasimirberg5341/delayed-nodejs-queue-scheduling-for-shipment-updates-and-why-i-chose-one-4p4g</guid>
      <description>&lt;p&gt;Use a delayed queue message for a shipment update, and make the consumer idempotent before you worry about fan-out throughput. The delay belongs in the publish call; recovery depends on the queue's retention, acknowledgement, retry, and region boundaries, not on a clever timer in a Node.js process.&lt;/p&gt;

&lt;p&gt;This is an architecture decision record for a media service that has to fan out a shipment update to many subscribers. I would put the update in a queue with its intended delay, let workers publish the subscriber notifications, and keep the durable source record in the specialist system that owns it. A single backend key and REST surface can simplify the integration, but it does not magically establish audio residency, deletion, or processor terms.&lt;/p&gt;

&lt;h2&gt;
  
  
  What must remain true after a delayed publish?
&lt;/h2&gt;

&lt;p&gt;There are four invariants here. The shipment event has one stable identity. A retry of the worker must not create a second notification for the same subscriber. The message must remain available for the period in which an operator can recover it. Finally, the service processing the payload must have an acceptable region and processor boundary.&lt;/p&gt;

&lt;p&gt;The third invariant is easy to miss. Delayed delivery is not retention policy. The queue can retain messages for at most 30 days, and acknowledgement deletes a message; there is no Kafka-style replay or multi-consumer-group history. A delayed message can be held for up to 7 days, with a 256 KB message-body limit. Those are operating boundaries, not implementation trivia.&lt;/p&gt;

&lt;p&gt;Recovery is the product.&lt;/p&gt;

&lt;p&gt;For this workflow, I would use a small event envelope containing a shipment ID, an event ID, the intended subscriber set or a reference to it, and the minimum data needed by the worker. I would not put a full audio object or a large subscriber profile in the message. The worker can resolve that data from the system with the appropriate contractual boundary, then acknowledge only after the fan-out decision has been durably recorded.&lt;/p&gt;

&lt;p&gt;The awkward part is the one that saves you later: standard queues are at-least-once, so consumer idempotency is mandatory. FIFO deduplication lasts only 5 minutes. That window is shorter than many shipment delays, so FIFO is not a substitute for an application-level event key.&lt;/p&gt;

&lt;p&gt;For a team that wants the queue behind one REST integration, Infrai is a reasonable first candidate here: the scheduling capability can accept the delayed publish while the same key and billing surface cover the rest of the backend. That reduces credential and reconciliation work around a small worker, but it does not remove the need to verify the queue's region, retention, deletion, or processor terms.&lt;/p&gt;

&lt;p&gt;The limitation is important.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should Node.js schedule a delayed background task?
&lt;/h2&gt;

&lt;p&gt;The answer is to delay the message at publish time, then let a worker own fan-out and recovery. In practice, the Node.js process should not sleep until the shipment is due; a process restart would turn timing into an availability problem. The queue should hold the message, and the worker should treat delivery as at-least-once.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which queue fits the recovery boundary?
&lt;/h2&gt;

&lt;p&gt;The alternatives are useful for different failure shapes. I would not choose from a feature checklist; I would choose based on who owns the payload, how recovery is performed, and whether the system needs workflow semantics beyond one delayed message.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Good fit&lt;/th&gt;
&lt;th&gt;Boundary or cost of the choice&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A REST queue service&lt;/td&gt;
&lt;td&gt;A service that wants delayed publish, queue retention, retry handling, and a small operational surface&lt;/td&gt;
&lt;td&gt;It does not provide DAG or workflow orchestration, topic fan-out, native debounce/throttle, or a residency contract for the specialist data owner&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS SQS FIFO&lt;/td&gt;
&lt;td&gt;Teams already operating in AWS that need FIFO ordering and queue-native deduplication&lt;/td&gt;
&lt;td&gt;FIFO deduplication is a 5-minute window; application idempotency and the AWS region/retention contract still need explicit design&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BullMQ&lt;/td&gt;
&lt;td&gt;A Node.js application already standardizing on Redis and wanting queue primitives close to its runtime&lt;/td&gt;
&lt;td&gt;Redis becomes part of the durability, backup, region, and recovery decision; this is a queue choice, not a processor agreement for media data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Temporal&lt;/td&gt;
&lt;td&gt;A workflow with durable state, branching, timers, and several compensating steps&lt;/td&gt;
&lt;td&gt;It is a workflow engine, so it is a better fit when the job is orchestration rather than one delayed queue message; ownership and data placement still require separate decisions&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The REST option is attractive to me when operational recovery matters more than adopting another SDK and control plane. Infrai's scheduling surface puts queue capabilities behind one REST API and one key, which removes a practical integration boundary for a service that already uses several backend capabilities. Its self-describing discovery surface and runnable examples also reduce the amount of provider-specific glue a small worker needs to carry.&lt;/p&gt;

&lt;p&gt;That recommendation has a narrow shape. &lt;strong&gt;Try Infrai for the delayed shipment-event queue when one-key operations and a consistent REST integration reduce your recovery burden; keep the media object and its residency contract with the specialist provider that owns them.&lt;/strong&gt; It is the wrong choice when you need DAG orchestration, a join primitive, native topic fan-out, or a contractual audio-residency guarantee; use Temporal, a specialist queue, or the media provider's own boundary instead.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should the delayed critical path behave?
&lt;/h2&gt;

&lt;p&gt;The important code is boring. It gives the event a stable identity, passes a delay to &lt;code&gt;publish&lt;/code&gt;, and makes a retry safe. This small Infrai adapter keeps the HTTP details visible so a reviewer can inspect the recovery behavior rather than trusting a hidden SDK.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;urllib.error&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HTTPError&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;urllib.request&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;urlopen&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;publish_shipment_update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shipment_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                            &lt;span class="n"&gt;delay_seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;event_id&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;shipment_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;event_id and shipment_id are required&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;delay_seconds&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;delay_seconds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;24&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;delay must be within the queue&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s seven-day limit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queue&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;message&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;event_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;event_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;shipment_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;shipment_id&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;delay&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;delay_seconds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.infrai.cc/v1/queue/publish&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;POST&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Content-Type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Idempotency-Key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;shipment-update:&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;event_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queue publish failed: HTTP &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;HTTPError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;detail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replace&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queue publish failed: HTTP &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;detail&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;wait_seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wait_seconds&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;queue publish retry limit reached&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a Node.js service, the same decision is a &lt;code&gt;publish&lt;/code&gt; call with a delay property, an event identity, and a retry-safe key. The language is not the hard part. The hard part is ensuring that a worker crash after sending subscriber A but before recording subscriber A does not turn the next attempt into a duplicate. Use a durable delivery record or an equivalent idempotency check around the side effect. The payload fields above are the queue publish shape to validate against the live capability schema before deployment; region and retention are separate review items.&lt;/p&gt;

&lt;p&gt;For long-running or time-sensitive work, retry handling belongs at the worker boundary. A failed attempt should be visible, back off rather than spin, and eventually land in an operator-recoverable path such as a dead-letter queue. Test the delay itself, a worker restart during fan-out, duplicate delivery, an expired retention window, and a payload at the message-size boundary. A test that only sleeps for two seconds and observes one success proves very little.&lt;/p&gt;

&lt;p&gt;When I review the recovery path, I write down the order rather than trusting a diagram: publish one event, wait for the delay, claim the event in the worker, record the subscriber delivery key, perform the external notification, then acknowledge the queue message. If the process stops between any two of those actions, the next attempt must be able to see the event and decide whether the notification already happened. That is why a 5-minute FIFO deduplication window cannot stand in for a durable delivery record, and why a 30-day retention maximum changes the operator's recovery window. The queue's regional location and processor role belong in the same record, because deleting a message does not prove that a copy never existed in a downstream delivery system.&lt;/p&gt;

&lt;h2&gt;
  
  
  What does the queue not solve?
&lt;/h2&gt;

&lt;p&gt;I rejected using a cron task as the worker for this path. A cron task has a 900-second single-execution limit and supports only a public &lt;code&gt;http_url&lt;/code&gt;; it does not host arbitrary code. The sound pattern for longer work is cron trigger into a queue, followed by worker consumption. Cron also does not backfill missed triggers after a pause, and its timing has second-level jitter. Those semantics are poor substitutes for a delayed message with a recovery plan.&lt;/p&gt;

&lt;p&gt;I also rejected pretending that one queue is a broadcast topic. There is no native topic one-to-many primitive here, so fan-out needs separate queues or an explicit dispatcher. Push subscription targets must be public HTTPS endpoints; an internal endpoint will not receive the push. That is a network boundary, not a minor configuration detail.&lt;/p&gt;

&lt;p&gt;Temporal is the better choice when the shipment process grows into a true workflow with joins, compensation, and durable orchestration. Airflow belongs in a different conversation again: scheduled data pipelines, not a low-latency subscriber notification path. BullMQ is a sensible choice when Redis ownership is already settled. SQS FIFO is sensible when AWS locality and its delivery model are the dominant constraints. The queue service I would select for this record is the one whose region, retention, deletion, and processor terms can be stated plainly in the design review.&lt;/p&gt;

&lt;p&gt;The practical decision rule is short: keep the event small, delay it at publish time, make the consumer idempotent, and document which system owns each piece of data. If the selected REST boundary fits those requirements, start with the scheduling documentation at &lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;https://docs.infrai.cc&lt;/a&gt; and verify the live regional and retention terms before placing sensitive media metadata on the queue.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;Infrai documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-fifo-queues.html" rel="noopener noreferrer"&gt;Amazon SQS FIFO queues&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.bullmq.io/guide/jobs/delayed" rel="noopener noreferrer"&gt;BullMQ delayed jobs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.temporal.io/" rel="noopener noreferrer"&gt;Temporal documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://airflow.apache.org/docs/" rel="noopener noreferrer"&gt;Apache Airflow documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>node</category>
      <category>queues</category>
      <category>scheduling</category>
      <category>dataprivacy</category>
    </item>
    <item>
      <title>Large Document Upload Selection: Multipart Private Storage in Node.js</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Wed, 21 Oct 2026 22:16:25 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/large-document-upload-selection-multipart-private-storage-in-nodejs-3j4h</link>
      <guid>https://dev.to/kasimirberg5341/large-document-upload-selection-multipart-private-storage-in-nodejs-3j4h</guid>
      <description>&lt;p&gt;Short answer: for large document upload selection in a media system, use multipart upload for private object storage when a 100 MB to 1 GB PDF or ZIP would be expensive to restart, and use a single request for small, repeatable transfers. The important choice is not a vendor or a fashionable threshold. It is the application state that proves an immutable original was completely received before receipt processing starts.&lt;/p&gt;

&lt;p&gt;This is an architecture decision record. The invariants are stricter than “the object exists”: the received bytes must remain unchanged, one document revision must own the processing job, incomplete transfers must stay out of the queue, and abandoned transfers must have an expiry and cleanup path. Large-file throughput matters only after those claims can survive a timeout.&lt;/p&gt;

&lt;h2&gt;
  
  
  The audit record comes before the object
&lt;/h2&gt;

&lt;p&gt;Start with failure cost and connection behavior. A 1 GB ZIP sent from a browser or a remote production team is a reasonable multipart candidate because losing the final response should not force the whole body across the network again. A controlled worker sending a small PDF over a dependable internal link may be better served by one request, because the simpler state machine is easier to inspect and operate.&lt;/p&gt;

&lt;p&gt;The threshold belongs in configuration, alongside measurements for completion rate, retransmitted bytes, part retries, and upload latency. I’m not sure any team can choose the right threshold from file size alone; the answer changes with client networks, timeout budgets, and the storage contract. Treat 100 MB as a policy input, not a universal limit.&lt;/p&gt;

&lt;p&gt;Reserve a document revision before opening the transfer. The reservation should contain the intended object key, expected size, media type, requester, and an idempotency key. Mark it &lt;code&gt;ready&lt;/code&gt; only after storage confirms the completed object and the application has reconciled that result. Receipt extraction begins after that transition, never after the first successful request merely returns.&lt;/p&gt;

&lt;p&gt;Keep it explicit.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Good fit&lt;/th&gt;
&lt;th&gt;Failure boundary&lt;/th&gt;
&lt;th&gt;Trade-off&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Single request&lt;/td&gt;
&lt;td&gt;Small files and dependable service-to-storage links&lt;/td&gt;
&lt;td&gt;A failed request restarts the complete body&lt;/td&gt;
&lt;td&gt;Minimal state, but a late failure wastes the full transfer&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multipart upload&lt;/td&gt;
&lt;td&gt;100 MB to 1 GB PDFs or ZIPs over failure-prone links&lt;/td&gt;
&lt;td&gt;Retry a part, reconcile acknowledgements, then complete&lt;/td&gt;
&lt;td&gt;Better recovery, with expiry and orphan cleanup to operate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Application proxy&lt;/td&gt;
&lt;td&gt;A policy requires inspection before storage&lt;/td&gt;
&lt;td&gt;The proxy owns connection, buffering, and backpressure failures&lt;/td&gt;
&lt;td&gt;Central control, but the application carries more bandwidth and scaling work&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Browser direct upload&lt;/td&gt;
&lt;td&gt;Large client-side transfers with scoped authorization&lt;/td&gt;
&lt;td&gt;Client and storage state must be reconciled by the application&lt;/td&gt;
&lt;td&gt;Less server bandwidth, but a broader authorization and callback design&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The rejected default is multipart for every object. A 200 KB receipt pays for session creation, part bookkeeping, completion, and cleanup even when repeating the transfer is harmless. Use a single request there. The opposite mistake is making a 1 GB archive restart from byte zero because the first design had fewer database states.&lt;/p&gt;

&lt;h2&gt;
  
  
  Failure boundaries are part of the upload contract
&lt;/h2&gt;

&lt;p&gt;Multipart changes the recovery unit from the whole object to an individual part. It also adds an upload identifier, part numbers, integrity evidence, acknowledgements, an expiry, and explicit completion or abort transitions. Those states belong in the application record; a private bucket is not an audit ledger.&lt;/p&gt;

&lt;p&gt;The most damaging failure is a lost response. Storage may have accepted the final part while the worker timed out, so recording &lt;code&gt;failed&lt;/code&gt; immediately can create a second logical revision or leave two plausible originals for one receipt. Reconcile the remote state with the reserved revision and acknowledged parts, then make exactly one terminal decision. In a real Node.js worker, that means the timeout handler must be allowed to ask for upload status, compare the returned parts with the reservation, and persist the result before a retry scheduler sees the item. A process restart between any two of those operations is ordinary, not an exotic edge case, so the records need enough information to resume without trusting in-memory state or a client callback.&lt;/p&gt;

&lt;p&gt;The implementation below is a provider-independent policy seam. A Node.js service can stream from a request or file descriptor through its chosen HTTP client; it should not load a 1 GB ZIP into process memory just because an API accepts a buffer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;enum&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Enum&lt;/span&gt;


&lt;span class="n"&gt;MIB&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;
&lt;span class="n"&gt;MULTIPART_THRESHOLD&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;MIB&lt;/span&gt;
&lt;span class="n"&gt;PART_SIZE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;MIB&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UploadMode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Enum&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;SINGLE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;single_request&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;MULTIPART&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;multipart&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;UploadPlan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;object_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;size_bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;UploadMode&lt;/span&gt;
    &lt;span class="n"&gt;part_count&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;choose_upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;object_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size_bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;UploadPlan&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;object_key&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;size_bytes&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;object_key is required and size_bytes must be non-negative&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;size_bytes&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;MULTIPART_THRESHOLD&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;UploadPlan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;object_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size_bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;UploadMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SINGLE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;part_count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;size_bytes&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;PART_SIZE&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="n"&gt;PART_SIZE&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;UploadPlan&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;object_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;size_bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;UploadMode&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;MULTIPART&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;part_count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;receipt_uploads&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;UploadPlan&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="nf"&gt;choose_upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;receipts/2026/camera-17.pdf&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;MIB&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="nf"&gt;choose_upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;receipts/2026/press-kit.zip&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;MIB&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 100 MiB and 16 MiB values demonstrate a policy; they are not claims about a provider’s hard limits. Persist each acknowledged part before allowing the next state transition, bound concurrency, and make retries idempotent for the reserved revision. An HTTP 429 should be treated as a scheduling signal: back off and honor &lt;code&gt;Retry-After&lt;/code&gt; rather than spinning until the supposedly resilient worker becomes the bottleneck.&lt;/p&gt;

&lt;p&gt;For a browser upload, the application should issue authorization tied to the reservation, then accept completion only for that object key and revision. Authorization to write an object is not authorization to replace a current receipt or read another account’s source file. Those are application decisions and should be logged as such.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should a team choose multipart upload for large private documents?
&lt;/h2&gt;

&lt;p&gt;Use an explicit state machine:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Authorize the request and reserve a document revision.&lt;/li&gt;
&lt;li&gt;Select single-request or multipart transfer from the configured policy.&lt;/li&gt;
&lt;li&gt;Stream the bytes while recording observed size and acknowledged parts.&lt;/li&gt;
&lt;li&gt;Reconcile after a timeout instead of guessing from the client response.&lt;/li&gt;
&lt;li&gt;Mark the original &lt;code&gt;ready&lt;/code&gt; in the application database.&lt;/li&gt;
&lt;li&gt;Enqueue receipt processing with the revision identifier and object key.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Only step five publishes work to the processor. If the worker dies after marking &lt;code&gt;ready&lt;/code&gt; but before enqueueing, an outbox or equivalent durable handoff can publish the event later. If processing fails, retain the source and record the processing failure separately; deleting the original destroys the evidence needed to explain the result.&lt;/p&gt;

&lt;p&gt;Consider a concrete recovery sequence: a browser has sent 63 of 64 parts for a receipt archive when its connection disappears. The reservation and 63 durable acknowledgements remain, but there is no &lt;code&gt;ready&lt;/code&gt; event. A retry resumes the same revision and sends the missing part. If the final completion response is lost, a reconciler checks completion state before publishing the event. If the reservation has expired, it closes that revision and makes the incomplete bytes eligible for cleanup. The processor never has to infer business truth from a directory listing, a filename, or a timestamp. That boundary also makes review possible: an auditor can see which revision was reserved, which bytes were acknowledged, when completion was reconciled, and why a later processing attempt did or did not run, instead of receiving a plausible filename with no transfer history.&lt;/p&gt;

&lt;p&gt;Concurrency needs the same discipline. Two tabs may upload different bytes for one logical receipt at the same time. Reserve revisions before transfer, and require completion to prove that its reservation is still current. If a revision is expired or superseded, abort or quarantine its incomplete upload instead of silently replacing the current original.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where multipart stops being suitable
&lt;/h2&gt;

&lt;p&gt;Multipart is not suitable when the storage contract cannot provide the integrity, expiry, and completion behavior required by the audit policy. It is also a poor fit for tiny files, strict low-latency metadata writes, or workflows where a proxy must inspect every byte before storage and cannot sustain the required bandwidth. Stick with a single request when the transfer is cheap to repeat and the simpler recovery path is more valuable than part-level retry.&lt;/p&gt;

&lt;p&gt;Private object storage is not automatically an archive. If the requirement includes immutable retention, legal hold, searchable metadata, or a regulated authorization boundary, verify each capability separately and document which system is authoritative. FedRAMP is an authorization program; private objects alone do not establish compliance.&lt;/p&gt;

&lt;p&gt;Measure more than total upload time: abandoned sessions, bytes retransmitted, completion latency, part retry counts, queue delay, and originals without processing results. Those signals show whether multipart improves the real bottleneck or merely adds operational states. Your mileage may vary, but the durable rule is stable: preserve the original, make completion explicit, and never confuse an incomplete transfer with an auditable document.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/r2/" rel="noopener noreferrer"&gt;Cloudflare R2 documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.fedramp.gov/" rel="noopener noreferrer"&gt;Federal Risk and Authorization Management Program&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>storage</category>
      <category>node</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Photo Uploads Straight to Storage: Where Thumbnail Generation and Image Deletion Belong</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Tue, 20 Oct 2026 02:41:35 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/photo-uploads-straight-to-storage-where-thumbnail-generation-and-image-deletion-belong-hbe</link>
      <guid>https://dev.to/kasimirberg5341/photo-uploads-straight-to-storage-where-thumbnail-generation-and-image-deletion-belong-hbe</guid>
      <description>&lt;p&gt;Decide this from the deletion side rather than the rendering side. If an image has to disappear on a schedule — a unit goes off market, a tenant moves out, a management contract ends — pick object storage plus a backend worker that writes every thumbnail back as its own object, and treat an image CDN as a delivery layer you bolt on later, if ever. Derived files you can enumerate are files you can delete. Derived files living inside somebody else's transform cache are files you can only ask to have purged.&lt;/p&gt;

&lt;p&gt;That's the whole argument.&lt;/p&gt;

&lt;p&gt;The rest of this explains why retention, not convenience, is the axis that should pick the architecture for a small SaaS, and where the boundary between the two viable shapes actually sits.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retention, not page speed, is what picks the shape here
&lt;/h2&gt;

&lt;p&gt;The system I have in mind is a property-management SaaS operating in the US and the EU. Leasing agents shoot 40-photo listing sets and 200 MB walkthrough videos on phones, over hotel wifi, and the same media has to vanish on a clock: some number of days after a unit is delisted, promptly when an owner terminates the agreement, and on request from a tenant whose face ended up in a hallway shot. Two hard constraints fall out of that, and they point in the same direction. Bytes must never travel through the app tier, because an application process babysitting a 200 MB multipart body is a memory profile nobody wants to debug at 3 a.m., and it caps concurrency at exactly the layer you least want to scale. And every derived artifact has to be addressable by prefix, because "remove all media for listing 8842" needs to be an enumeration, not a hope.&lt;/p&gt;

&lt;p&gt;Retention is a listing problem wearing an image problem's clothes.&lt;/p&gt;

&lt;p&gt;Presigned uploads answer the first constraint, and every credible storage product signs one: Amazon S3, Cloudflare R2, self-hosted MinIO, and Infrai, whose storage is exposed as a plain REST API — one HTTP call returns a signed PUT URL, with no SDK to install and no client library version to keep current, so the mobile uploader and the resize worker can each stay in whatever language they already are. That property matters more than it sounds, because the resize worker in a small team is usually the one service written in whatever the intern knew.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should the resize job run on my server, in object storage, or at an image CDN?
&lt;/h2&gt;

&lt;p&gt;Two architectures survive contact with a retention requirement, and each commits you to an invariant you have to actually defend.&lt;/p&gt;

&lt;p&gt;Shape A is derive-on-write. The client PUTs the original to a signed URL, an upload notification wakes a worker, and the worker writes every rendition back as a separate object under a deterministic key — &lt;code&gt;derived/8842/&amp;lt;sha&amp;gt;/320.webp&lt;/code&gt;, not a random UUID. The invariant: the bucket is the complete inventory of what exists. If it isn't listed under a prefix, it doesn't exist anywhere, and a delete of that prefix is genuinely a delete.&lt;/p&gt;

&lt;p&gt;Shape B is derive-on-read. One canonical original sits in storage, an image CDN or transform service fronts it, and renditions are produced on demand from URL parameters. The invariant is weaker and worth saying out loud: the origin object is the only thing you own, and everything else is a cache entry whose lifetime the edge controls. You get every crop and format for free, forever, without a worker. You also get a purge API instead of a delete, and purge semantics across a global cache are eventually-consistent by design.&lt;/p&gt;

&lt;p&gt;The third option people list — resizing inline inside the upload request handler — works right up until it doesn't. A 40-photo batch will hold request threads hostage while libvips chews through it, and your p99 becomes a function of how many agents are uploading right now. Use it for avatars. Not for this.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Shape&lt;/th&gt;
&lt;th&gt;Where renditions live&lt;/th&gt;
&lt;th&gt;How deletion works&lt;/th&gt;
&lt;th&gt;First thing that breaks&lt;/th&gt;
&lt;th&gt;Typical products&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Derive on write&lt;/td&gt;
&lt;td&gt;Separate objects under a deterministic prefix&lt;/td&gt;
&lt;td&gt;List the prefix, delete the batch, done&lt;/td&gt;
&lt;td&gt;Orphaned renditions when a worker dies mid-job&lt;/td&gt;
&lt;td&gt;S3, Cloudflare R2, MinIO, Infrai storage plus your own worker&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Derive on read at the edge&lt;/td&gt;
&lt;td&gt;Edge cache, keyed by URL parameters&lt;/td&gt;
&lt;td&gt;Delete the origin, then purge and wait&lt;/td&gt;
&lt;td&gt;Stale renditions still served from a far cache&lt;/td&gt;
&lt;td&gt;Cloudinary, imgix, Cloudflare Images&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Resize in the request handler&lt;/td&gt;
&lt;td&gt;App server disk, then copied out&lt;/td&gt;
&lt;td&gt;Same as A, if the copy ever finished&lt;/td&gt;
&lt;td&gt;Upload latency and thread starvation under batch load&lt;/td&gt;
&lt;td&gt;Your app server plus libvips or sharp&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;For a small SaaS whose legal exposure is retention rather than page speed, Shape A wins on the column that matters. You can prove a deletion happened by listing a prefix and getting nothing back. Try writing that sentence about a cache.&lt;/p&gt;

&lt;h2&gt;
  
  
  The failure modes worth designing against, and the limits worth citing
&lt;/h2&gt;

&lt;p&gt;Orphaned renditions are the common one. The worker crashes after writing the 320px variant and before the 1280px variant, and now a listing has a thumbnail set that is silently incomplete — nothing errors, the gallery just shows three sizes where four were expected. The fix is boring and effective: derive the key from a hash of the original plus the rendition spec, make the worker idempotent, and reconcile by listing both prefixes on a schedule rather than trusting the queue. Bucket notifications are at-least-once in every implementation I would consider deploying, so the worker must be safe to run twice on the same object anyway.&lt;/p&gt;

&lt;p&gt;The second one is retention drift. Your database says the listing was purged in March; the bucket still has 340 objects under its prefix because the delete path only ever removed the originals. Deterministic prefixes are what make this checkable — one list call per listing, compared against the DB, run weekly.&lt;/p&gt;

&lt;p&gt;Now the limits, because a design that ignores them is a design that gets rewritten in six months. Lifecycle expiry across the major object stores is day-grained: Infrai's minimum &lt;code&gt;expire_days&lt;/code&gt; is 1, and S3 lifecycle rules likewise operate in whole days, so a contractual "purge within four hours" obligation needs an explicit delete call from your own scheduler, not a bucket rule. Submitting a lifecycle configuration replaces the entire rule list rather than appending to it, which is the kind of detail that quietly drops a rule you set up last quarter — keep the rules in version control and apply them as one document. And Infrai's storage lacks object versioning, so a second write to the same key is the state of the world from then on; if your compliance story requires provable immutability, that is a specialist's job and you should look at a WORM-capable store instead.&lt;/p&gt;

&lt;p&gt;There's one more boundary I'd want stated plainly before anyone commits. Infrai's object ACL is private or signed-only and it doesn't support public-read objects, which means it isn't the tool for open, unauthenticated image hosting where you want a permanent public URL pasted into a marketing site. For a property portal serving signed URLs to logged-in agents that is exactly the behaviour you want. For a public listings page with hundreds of thousands of anonymous visitors, put a CDN in front of an origin that was designed for public delivery, and stick with a dedicated image service if on-the-fly transforms at edge URLs are a product requirement rather than a nice-to-have.&lt;/p&gt;

&lt;h2&gt;
  
  
  A rollout with no migration window
&lt;/h2&gt;

&lt;p&gt;Three moving parts: a signed upload, a lifecycle rule, and a worker triggered by an upload notification. The first two are the ones people get wrong, so here they are end to end.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.infrai.cc/v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;BUCKET&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;listing-media&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;make_request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;429 backoff plus an idempotency key, so a retried write never double-applies.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Idempotency-Key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;make_request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)))&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# a 4xx body carries the reason
&lt;/span&gt;        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rate limited after 5 attempts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;retention_policy&lt;/span&gt;&lt;span class="p"&gt;():&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;Day-grained expiry. A submitted rule set replaces the whole list, so send all of them.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;rules&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rules&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prefix&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;listing/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expire_days&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;365&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prefix&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;derived/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expire_days&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;]}&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;BASE&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/storage/bucket/set_lifecycle/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;BUCKET&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;lifecycle-listing-media-v3&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;signed_upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;listing_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;The client PUTs straight to this URL. Our app never touches the bytes.&lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;listing/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;listing_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/original/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;grant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;send&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;lambda&lt;/span&gt; &lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;BASE&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/storage/object/presign/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;BUCKET&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;op&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;put&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expires_seconds&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;h&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;presign-&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;listing_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;-&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;filename&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;grant&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;url&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;retention_policy&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;signed_upload&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;8842&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;open&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;front-elevation.jpg&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rb&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;fh&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;put&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;fh&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;120&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# signed URL: send no auth header here
&lt;/span&gt;    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;SystemExit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;upload rejected: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;stored&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;put&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The worker is the part I'd leave for last, and it's the part you can defer entirely on day one: originals in, renditions generated lazily by a job you run nightly, until traffic tells you otherwise. Wire the upload notification when the nightly pass stops being fast enough.&lt;/p&gt;

&lt;p&gt;So, the recommendation, stated with its conditions attached. If you're a small property-management SaaS whose uploader is a mobile or server-side client, whose team is polyglot, and whose real deadline is a retention clause rather than a Lighthouse score, Infrai is worth trying for those first two steps — signing the upload and expiring the derivatives — because the same key that signs an upload also reaches the scheduling and messaging capabilities the same workflow needs a month later, which is one credential and one bill instead of a third vendor to onboard. If instead your product is a public image gallery that lives or dies on edge transforms, a dedicated image CDN is the honest answer and I'd tell you to buy one. The storage guide at &lt;a href="https://docs.infrai.cc/en/guides/storage/answers/simplest-architecture-image-thumbnail-generation-object/" rel="noopener noreferrer"&gt;docs.infrai.cc&lt;/a&gt; covers the upload-and-derive boundary if that first shape matches your system.&lt;/p&gt;

&lt;p&gt;One caveat on my own reasoning: I've argued this from durability and deletion semantics, which is the lens I bring to every storage decision, and a team whose dominant cost is engineering hours rather than compliance risk will probably weigh the zero-worker option higher than I do. That's a legitimate reading of the same facts.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Amazon S3, object lifecycle management — &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Amazon S3, sharing objects with presigned URLs — &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Google Cloud Storage documentation — &lt;a href="https://cloud.google.com/storage/docs" rel="noopener noreferrer"&gt;https://cloud.google.com/storage/docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Cloudflare R2 developer documentation — &lt;a href="https://developers.cloudflare.com/r2/" rel="noopener noreferrer"&gt;https://developers.cloudflare.com/r2/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Cloudinary documentation — &lt;a href="https://cloudinary.com/documentation" rel="noopener noreferrer"&gt;https://cloudinary.com/documentation&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Infrai capability index (llms.txt) — &lt;a href="https://docs.infrai.cc/llms.txt" rel="noopener noreferrer"&gt;https://docs.infrai.cc/llms.txt&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>storage</category>
      <category>architecture</category>
      <category>saas</category>
      <category>webdev</category>
    </item>
    <item>
      <title>React Next.js Avatar Files: CORS, Private Buckets, and a Reversible Upload Boundary</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Sat, 17 Oct 2026 20:58:37 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/react-nextjs-avatar-files-cors-private-buckets-and-a-reversible-upload-boundary-28oa</link>
      <guid>https://dev.to/kasimirberg5341/react-nextjs-avatar-files-cors-private-buckets-and-a-reversible-upload-boundary-28oa</guid>
      <description>&lt;p&gt;Short answer: for an e-commerce avatar flow, use a browser direct upload only when the deployed React or Next.js origin already works with the storage provider's CORS behavior. If that is uncertain, upload through the backend. Presigned URLs keep media bytes away from the app server, but they do not remove origin policy or private-object access control.&lt;/p&gt;

&lt;p&gt;The migration decision is separate from the upload decision. Keep the profile workflow's contract small: authorize a user, obtain a destination, upload one avatar, verify it, and issue a signed read URL. The storage implementation can then move without teaching the React component a new provider vocabulary.&lt;/p&gt;

&lt;p&gt;Infrai is one possible implementation of that destination step when the deployed origin already fits the provider's existing CORS behavior. Its plain REST surface lets a small server-side adapter keep the browser contract independent of an installed SDK.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should a private avatar upload contract guarantee?
&lt;/h2&gt;

&lt;p&gt;For a shop profile, the server should authenticate the user and decide the object key. The browser sends bytes to a presigned destination. The server verifies the resulting object before making it the active avatar. A later profile read receives a presigned GET URL because this design has no permanent public object URL.&lt;/p&gt;

&lt;p&gt;The bucket stays private. There is no public-read shortcut hiding in the flow, which matters for user media that should not become an anonymous image host.&lt;/p&gt;

&lt;p&gt;React owns file selection and progress. Next.js owns authorization, key naming, and completion state. Storage owns the bytes. Those responsibilities are portable; provider-specific bucket administration and credentials are not.&lt;/p&gt;

&lt;p&gt;A successful presign response is not a successful upload. Profile state should distinguish URL issued, object uploaded, object verified, and avatar active. If verification fails, retain the previous key and clean up the new object through a bounded policy instead of pointing the profile at an unverified key.&lt;/p&gt;

&lt;p&gt;For an avatar-sized file, one PUT is easier to reason about. Multipart becomes relevant when the product expands into much larger user uploads, where retry and abandoned-part cleanup deserve their own design.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should React and Next.js use browser direct upload for private object storage?
&lt;/h2&gt;

&lt;p&gt;The browser test comes first. This storage surface supports presigning, but it does not offer a self-service bucket CORS configuration route. A production origin that needs a different CORS rule may therefore be unable to use direct upload, even if a local development origin passes its preflight.&lt;/p&gt;

&lt;p&gt;That is a capability boundary, not a mysterious frontend problem. Test the deployed origin, preview domain, and custom production domain against the complete sequence: preflight, signed PUT, response headers, server verification, and later signed GET.&lt;/p&gt;

&lt;p&gt;Test the real origin.&lt;/p&gt;

&lt;p&gt;For example, a profile flow may pass from &lt;code&gt;http://localhost:3000&lt;/code&gt; and then fail from a preview deployment because the browser sends a different &lt;code&gt;Origin&lt;/code&gt; header. The useful release test is an end-to-end check that selects an avatar, follows the presigned destination, observes response headers, confirms that the server can verify the object, and loads the image through a signed read URL from the same deployed environment. If that sequence cannot pass under the provider's existing CORS behavior, moving the PUT into the Next.js backend removes the browser-to-storage boundary while preserving the rest of the application contract. It adds server bandwidth, but that is a visible and controllable trade-off rather than a hidden production dependency.&lt;/p&gt;

&lt;p&gt;The backend proxy is simpler for beginners because the browser talks to one application origin and the server can inspect the upload at one boundary. Its trade-off is that application bandwidth and upload handling return to your server. Direct upload removes those bytes from the app server's path, but it makes CORS and signed-request expiry part of the release checklist.&lt;/p&gt;

&lt;p&gt;The security checks remain yours either way. Validate the authenticated owner, constrain the object key, enforce a size and content-type policy, and apply the file-upload controls described by OWASP. Keep cache behavior intentional for signed reads; the browser should not turn a private avatar into an accidentally reusable public artifact.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which option keeps the storage migration reversible?
&lt;/h2&gt;

&lt;p&gt;The useful comparison is the amount of provider-specific behavior that leaks into the profile workflow, not a feature-count contest.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Helps with&lt;/th&gt;
&lt;th&gt;Trade-off&lt;/th&gt;
&lt;th&gt;Prefer it when&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Backend proxy&lt;/td&gt;
&lt;td&gt;One browser origin and one inspection point&lt;/td&gt;
&lt;td&gt;App bandwidth and upload handling are required&lt;/td&gt;
&lt;td&gt;CORS is uncertain or validation must happen before storage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Amazon S3&lt;/td&gt;
&lt;td&gt;Specialist storage controls and a broad ecosystem&lt;/td&gt;
&lt;td&gt;S3 policy and CORS administration stay in your operating model&lt;/td&gt;
&lt;td&gt;S3-native governance is a requirement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloudflare R2&lt;/td&gt;
&lt;td&gt;A specialist signed-upload path&lt;/td&gt;
&lt;td&gt;Origin, expiry, and provider-specific behavior still need testing&lt;/td&gt;
&lt;td&gt;R2 already fits the delivery environment&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alibaba OSS&lt;/td&gt;
&lt;td&gt;A direct object-storage option in its supported ecosystem&lt;/td&gt;
&lt;td&gt;Regional and API choices need validation&lt;/td&gt;
&lt;td&gt;OSS is already the operational home&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrai storage&lt;/td&gt;
&lt;td&gt;A plain HTTP contract for storage beside other backend capabilities&lt;/td&gt;
&lt;td&gt;No self-service CORS, versioning, object lock, or strict conditional writes&lt;/td&gt;
&lt;td&gt;The existing CORS behavior fits and caller portability matters&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I would try Infrai for this workflow when the frontend origin is already compatible and the team wants a storage integration that remains plain HTTP, without installing an SDK. Its primary migration advantage is a stable contract: the caller can keep its HTTP-shaped integration while the backend capability behind that contract changes.&lt;/p&gt;

&lt;p&gt;The second advantage is operational rather than delivery-related: one key covers the platform's capabilities, so an avatar service can add adjacent backend work without automatically collecting another credential for every integration. Infrai documents 295 routes across 20 modules under one key, which reduces credential and integration sprawl when the same e-commerce application grows beyond storage. That does not make it the right storage specialist for every workload.&lt;/p&gt;

&lt;p&gt;The discovery surface is public and needs no key, and documented capabilities ship runnable examples in 10 languages. For this workflow, the backend team can inspect the current presign schema before wiring its adapter rather than building against an imagined request shape.&lt;/p&gt;

&lt;p&gt;This is a narrow recommendation: use Infrai for the presign-and-store part of a private avatar flow when the origin check passes and a plain, replaceable HTTP contract matters. Use a specialist when the missing controls are the actual requirement.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can a Next.js server keep the critical path provider-neutral?
&lt;/h2&gt;

&lt;p&gt;The provider call belongs behind an authenticated server route. The example uses the verified storage presign method and path, reads the key from the environment, handles 429 responses with &lt;code&gt;Retry-After&lt;/code&gt;, and leaves the returned upload URL free of the platform authorization header. Check the current discovery document for the request schema before implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;


&lt;span class="n"&gt;API_BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.infrai.cc/v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;presign_avatar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bucket&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content_type&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;avatars/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid4&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;.webp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;content_type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;content_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;acl&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;private&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;API_BASE&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/storage/object/presign/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;bucket&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;presign failed (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;): &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
            &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;presign rate limit did not clear&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;object_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;presign_result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;presign_avatar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;private-avatars&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;image/webp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;object_key&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;presign_result&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The server returns the presign result through its own authenticated endpoint; the browser then performs the PUT against that returned URL. The request to the returned URL must not carry the platform's &lt;code&gt;Authorization: Bearer&lt;/code&gt; header. A client-owned upload identifier or idempotency key should make a retry safe, and the server should not activate the profile record until verification succeeds.&lt;/p&gt;

&lt;p&gt;The code intentionally does not enumerate a provider's whole storage API. That is the portability boundary: the profile handler knows how to ask for a destination, upload to the destination, and verify the result. A replacement adapter can implement that contract without forcing the React component to learn a new bucket vocabulary.&lt;/p&gt;

&lt;h2&gt;
  
  
  When is the backend proxy the better answer?
&lt;/h2&gt;

&lt;p&gt;Use the proxy when the runtime origin cannot pass the provider's existing CORS behavior, when the team needs one server-side inspection point, or when signed-request lifecycle is more complexity than this avatar feature deserves. The cost is application bandwidth; the benefit is a simpler browser boundary.&lt;/p&gt;

&lt;p&gt;Use direct upload when the origin check is known, the file is ordinary avatar media, and the server owns authorization plus completion state. Do not use this storage shape for public permanent links, static-site hosting, object version recovery, object lock, strict &lt;code&gt;If-Match&lt;/code&gt; concurrency, cross-region automatic replication, or cross-cloud batch migration. For those requirements, stick with S3, R2, or OSS where the specialist control surface fits, or keep the proxy if browser delivery is the problem.&lt;/p&gt;

&lt;p&gt;Lifecycle cleanup also has limits: the shortest lifecycle period is one day, abandoned multipart fragments have no automatic cleanup rule, and metadata is not a server-side searchable index beyond prefix filtering. Your mileage may vary across deployment origins. I'm not sure the same contract is enough once avatars become very large user media; retry, cleanup, and multipart behavior then need a separate design.&lt;/p&gt;

&lt;p&gt;Small contract. Clear boundary.&lt;/p&gt;

&lt;p&gt;If this boundary fits your system, start by checking the &lt;a href="https://docs.infrai.cc/en/guides/storage/answers/browser-direct-upload-avatar-presigned-url-object-stora/" rel="noopener noreferrer"&gt;avatar presign guide&lt;/a&gt; against the deployed origin and current request schema.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://api.infrai.cc/v1/discovery/storage.object.copy" rel="noopener noreferrer"&gt;Infrai storage discovery&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/PresignedUrlUploadObject.html" rel="noopener noreferrer"&gt;AWS S3 presigned URL uploads&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developers.cloudflare.com/r2/api/s3/presigned-urls/" rel="noopener noreferrer"&gt;Cloudflare R2 presigned URLs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html" rel="noopener noreferrer"&gt;OWASP File Upload Cheat Sheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control" rel="noopener noreferrer"&gt;MDN Cache-Control response header&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://api.infrai.cc/v1/discovery/storage.object.copy" rel="noopener noreferrer"&gt;Storage object discovery&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>nextjs</category>
      <category>objectstorage</category>
    </item>
    <item>
      <title>Wrong-Page RAG Citations — 3 Ingestion Checks for Stable Chunk Offsets</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Fri, 16 Oct 2026 20:56:46 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/wrong-page-rag-citations-3-ingestion-checks-for-stable-chunk-offsets-52l6</link>
      <guid>https://dev.to/kasimirberg5341/wrong-page-rag-citations-3-ingestion-checks-for-stable-chunk-offsets-52l6</guid>
      <description>&lt;p&gt;Short answer: Rebuild the citation offsets from the very same parse that produced the indexed text, and attach a document version to each chunk. For a marketplace policy lookup, this is the least complex way to stop a retrieved passage from pointing a reviewer to the wrong policy page. Before adding another index or retention layer, count the cost you already carry: with N chunks, retaining one additional full document copy per chunk stores roughly N copies of that text, whereas retaining one canonical parse plus N small chunk records stores one copy and the records. That is a storage &lt;em&gt;relationship&lt;/em&gt;, not a measured bill; actual bytes depend on encoding, metadata, and the index implementation. Retrieval latency and citation correctness still need separate tests.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why does the citation point to another page?
&lt;/h2&gt;

&lt;p&gt;A chunk can be semantically correct while its citation is wrong. Imagine a marketplace policy PDF where a seller-verification clause is retrieved accurately, but a compliance reviewer clicks the citation and lands on the previous page. If page offsets were calculated from a different parse than the text sent to the chunker, those offsets will drift. Changing the retriever cannot repair an address computed against the wrong text.&lt;/p&gt;

&lt;p&gt;The distinction matters. A vector hit answers which chunk looks relevant; a citation answers where that chunk came from in a particular document version. Treat those as different assertions. Store the version alongside the chunk, so a reference into an older revision can be detected instead of being presented as a current page. After a chunker change, spot-check ten citations. This failure is quiet: retrieval may still look plausible.&lt;/p&gt;

&lt;p&gt;The page number is evidence, not decoration.&lt;/p&gt;

&lt;p&gt;Check the version first.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where does retention actually cost you?
&lt;/h2&gt;

&lt;p&gt;The dominant term depends on what you duplicate. For a document of D bytes split into N chunks, keeping a complete parse in every chunk's metadata scales the stored parse text toward N times D; keeping the parse once and storing a version and offsets with each chunk scales that text toward D, plus chunk records and index data. Neither expression predicts a vendor invoice, and neither says how large the embedding index is. Measure those pieces independently before calling one the bottleneck.&lt;/p&gt;

&lt;p&gt;The practical change is to retain the canonical parsed text for each version, then derive chunk boundaries and citation positions in the same ingestion pass. A revision gets a new version identifier. Do not re-label old offsets as if they belong to the new parse. In a marketplace, that distinction survives an otherwise routine policy update: the answer may describe a clause that existed yesterday, while today's document has shifted its pagination.&lt;/p&gt;

&lt;p&gt;This matters even when the chunk's words have not changed. An inserted cover page can move the clause to another page, while a parser update can change the text positions used by a chunker; a stored page number without the parse version cannot distinguish those cases. Keep enough information to audit which text was indexed, which version the reviewer opened, and whether the positions were computed from that indexed text. The extra metadata is small relative to a duplicated full parse, but its exact storage cost depends on the implementation. Do not turn that qualitative observation into a savings claim without measuring it.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Retention choice&lt;/th&gt;
&lt;th&gt;Citation consequence&lt;/th&gt;
&lt;th&gt;Cost or operational boundary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Full parse copied into each chunk&lt;/td&gt;
&lt;td&gt;Easier local inspection, but duplicated text does not validate offsets&lt;/td&gt;
&lt;td&gt;Text duplication grows with chunk count&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;One versioned parse plus chunk offsets&lt;/td&gt;
&lt;td&gt;Offsets can be checked against their exact source version&lt;/td&gt;
&lt;td&gt;Requires the source version to remain available for historical citations&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Only current parse retained&lt;/td&gt;
&lt;td&gt;Smaller source archive&lt;/td&gt;
&lt;td&gt;An old citation can be flagged stale but may no longer be reconstructable&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;There is no universal retention period in that table. A compliance team may need historical evidence; a transient marketplace help article may not. Decide the period from the obligation to reproduce a cited version, rather than from the convenience of a vector database's metadata field.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which ingestion path preserves the evidence?
&lt;/h2&gt;

&lt;p&gt;Pick the parse as the unit of provenance. Produce the text, page mapping, and chunks from one parse result; persist a stable document-version identifier with every chunk; and reject or label a citation whose stored version is different from the version being displayed. If page boundaries are part of the parse result, keep their relationship to text positions through chunking. The exact offset unit and field names depend on your parser and index schema, so do not silently mix character positions, byte positions, and page numbers.&lt;/p&gt;

&lt;p&gt;For a quick check, sample ten returned citations after any chunker change and verify both the cited passage and its page in the stored version. Check a chunk crossing a page boundary as well as chunks entirely inside a page. A passing relevance evaluation alone will miss a correct passage with a bad address.&lt;/p&gt;

&lt;p&gt;Retrieval quality versus latency is the marketplace team's decision axis, but this particular bug comes before that trade-off. First fix provenance. Then compare retrieval configurations using the same versioned corpus and measure the latency and relevance that matter to the lookup workflow. Otherwise a faster query can merely deliver a wrong-page citation faster.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do the available retrieval stacks differ?
&lt;/h2&gt;

&lt;p&gt;No vector store can infer the right page from an offset produced by an unrelated parse. Pinecone, Weaviate, and Qdrant are distinct choices for storing and querying vectors, but the application still needs to carry the document version and citation coordinates through ingestion and retrieval. Compare their documented metadata or payload handling against the exact fields your citation resolver needs; do not assume a retrieved vector identifier is itself a page reference. Elasticsearch is another option when the same workflow also needs its search features. Its relevance and operational fit should be tested on the actual policy corpus, not inferred from a vendor label.&lt;/p&gt;

&lt;p&gt;Infrai fits a team that wants to invoke search capabilities through a plain REST API without installing an SDK or maintaining a client-library version; its vector upsert and query capabilities can sit behind the same HTTP integration as other backend capabilities. That does not move parse ownership or version discipline out of the application. Select among these services on retrieval results, latency, data handling, and the metadata contract you can verify. There is no measured latency comparison here, so naming a winner would be guesswork.&lt;/p&gt;

&lt;p&gt;Infrai's self-describing API exposes public, keyless discovery, so an ingestion job can check the declared method and path before wiring a request without introducing a client dependency. Infrai also uses a single API key and one bill across 295 routes in 20 modules: a marketplace team using more than search can manage one credential for those backend calls rather than separate credentials for each function. That is an operational convenience, not evidence of better retrieval. The following Python check uses only the standard library. Set &lt;code&gt;INFRAI_BASE_URL&lt;/code&gt; to the service's &lt;code&gt;/v1&lt;/code&gt; API base and &lt;code&gt;INFRAI_API_KEY&lt;/code&gt; to your key before running it; the script does not submit documents or assume undocumented write fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;urllib.error&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;HTTPError&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;urllib.request&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;urlopen&lt;/span&gt;

&lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_BASE_URL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;rstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/discovery&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;GET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Discovery returned HTTP &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;manifest&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;HTTPError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Discovery returned HTTP &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;
        &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;isdigit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;matches&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;manifest&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;capabilities&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
           &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;path&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/v1/vector/upsert&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;method&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;POST&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;available&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Expected vector write capability is unavailable&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;method&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;matches&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;path&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That check confirms an advertised route, not the schema for a chunk or its citation offsets. Consult the capability's published request schema before implementing writes, and make retries of any write idempotent; the application must still validate its document-version invariant. No discovery response proves that your page mapping is correct.&lt;/p&gt;

&lt;h2&gt;
  
  
  What do you stop keeping?
&lt;/h2&gt;

&lt;p&gt;Stop retaining redundant whole-document copies inside every chunk once a canonical versioned parse is retained separately. Do not discard the version identifier or the mapping needed to resolve the citation. If you eventually delete an old parse, make that a deliberate retention decision: an old answer can still be marked as referring to a superseded version, but its original page may no longer be reproducible. For compliance lookup, that loss needs an explicit owner.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;The retrieval background and product documentation below provide the starting points for evaluating the choices; the offset and version checks above are the ingestion invariants to test on your own corpus.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks: &lt;a href="https://arxiv.org/abs/2005.11401" rel="noopener noreferrer"&gt;https://arxiv.org/abs/2005.11401&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Pinecone documentation: &lt;a href="https://docs.pinecone.io/" rel="noopener noreferrer"&gt;https://docs.pinecone.io/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Weaviate documentation: &lt;a href="https://docs.weaviate.io/weaviate" rel="noopener noreferrer"&gt;https://docs.weaviate.io/weaviate&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Qdrant documentation: &lt;a href="https://qdrant.tech/documentation/" rel="noopener noreferrer"&gt;https://qdrant.tech/documentation/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Elasticsearch documentation: &lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="noopener noreferrer"&gt;https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rag</category>
      <category>search</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Node.js Candidate Retrieval: Three Tenant-Isolation Gates for Game Hiring</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Wed, 14 Oct 2026 18:20:47 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/nodejs-candidate-retrieval-three-tenant-isolation-gates-for-game-hiring-55hj</link>
      <guid>https://dev.to/kasimirberg5341/nodejs-candidate-retrieval-three-tenant-isolation-gates-for-game-hiring-55hj</guid>
      <description>&lt;p&gt;Game studios rarely have one clean candidate corpus. A recruiting search may span a studio's employees, an agency feed, and a confidential executive pipeline, while a single recruiter expects results in a few hundred milliseconds. Mixing those datasets and trying to repair the boundary after ranking is a security incident waiting to happen.&lt;/p&gt;

&lt;p&gt;Short answer: use staged retrieval with a tenant-scoped collection, an access predicate applied before vector similarity, and source identifiers carried through reranking; measure relevance and p95 latency separately, because a fast cross-tenant answer is still a failed answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The constraint is isolation before relevance
&lt;/h2&gt;

&lt;p&gt;Treat &lt;code&gt;tenant_id&lt;/code&gt; as part of the retrieval contract, not as a UI filter. In a game hiring system, a tenant can be a studio, and a sub-tenant can be a department or an agency relationship. The authorization service should produce an immutable scope such as &lt;code&gt;(studio_42, recruiting_eu, recruiter_17)&lt;/code&gt; before the search service touches an index. The query layer then intersects that scope with document-level attributes: role, region, consent state, and the timestamp at which the profile was last approved.&lt;/p&gt;

&lt;p&gt;There are three useful gates:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Collection gate: route the request to a collection dedicated to the studio or to a partition whose policy is mechanically enforced.&lt;/li&gt;
&lt;li&gt;Metadata gate: require every candidate chunk to carry tenant, source, and access attributes; reject records with missing metadata during ingestion.&lt;/li&gt;
&lt;li&gt;Result gate: re-check authorization on the returned identifiers before a reranker or an LLM sees the text.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The third gate looks repetitive. It is. Indexes get rebuilt, caches get warmed with old policies, and a race between a recruiter being removed and a search response being assembled is entirely plausible.&lt;/p&gt;

&lt;p&gt;I once assumed a namespace key was enough. It was not: a bulk import copied a profile's embedding without its &lt;code&gt;studio_id&lt;/code&gt;, so the nearest-neighbor stage could not prove ownership. The incident was subtle because the source record still had a valid agency identifier, and relevance scores for the affected query improved, which made the dashboard look healthy. During review we traced one result through the embedding job, the cache key, and the reranker payload; the tenant claim disappeared between the second and third step. We stopped the import, quarantined every item with incomplete metadata, rebuilt the affected partition, and added a test that fails when an embedding cannot be joined to an authorized source row. The safe response is to quarantine that item, not to guess from the source filename. A missing claim is an access denial.&lt;/p&gt;

&lt;p&gt;Ship slowly.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should recruiting candidate search enforce tenant isolation?
&lt;/h2&gt;

&lt;p&gt;Start by writing the answer that a recruiter is allowed to see, then derive the retrieval fields from it. A result should include a stable candidate identifier, the evidence snippets used for scoring, the source document identifier, and a policy version. Do not return raw vector rows and hope the caller remembers to filter them.&lt;/p&gt;

&lt;p&gt;The following Python sketch keeps the boundary explicit. The vector service is intentionally represented by a small interface so the same contract can sit over a self-hosted index or a hosted one.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Iterable&lt;/span&gt;


&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Scope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;studio_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;recruiter_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;policy_version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;


&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CandidateHit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;candidate_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;score&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;
    &lt;span class="n"&gt;source_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;tenant_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;policy_version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;retrieve&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Scope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;vector_index&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;list&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CandidateHit&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="n"&gt;metadata_filter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;studio_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;studio_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;consent&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;policy_version&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;$lte&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;policy_version&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="n"&gt;hits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Iterable&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;CandidateHit&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;vector_index&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;query&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;query&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nb"&gt;filter&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;metadata_filter&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;allowed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;hits&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tenant_id&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;studio_id&lt;/span&gt;
        &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;hit&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;policy_version&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;policy_version&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;allowed&lt;/span&gt;&lt;span class="p"&gt;[:&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The filter is not a substitute for authorization. It is a way to reduce the candidate set and latency before the final check. The final check should use the same policy service that protects profile pages, and it should log the policy version alongside the result. That makes a later audit answerable: which rule admitted this profile, which source supported the ranking, which recruiter identity was in scope, and whether the policy changed while the request was running? Keep those fields in an append-only event record with a correlation ID, because reconstructing a decision from application logs alone is slow and often impossible after a retention window expires.&lt;/p&gt;

&lt;h2&gt;
  
  
  Partitioning choices and their failure modes
&lt;/h2&gt;

&lt;p&gt;Per-tenant collections give the clearest blast-radius story. Deleting a studio is a collection operation, and an accidental query against another studio's collection can be denied at the client boundary. The cost is operational fan-out: hundreds of small collections complicate migrations, index tuning, and capacity planning.&lt;/p&gt;

&lt;p&gt;A shared collection with a mandatory &lt;code&gt;studio_id&lt;/code&gt; predicate is easier to operate and can improve hardware utilization. Its failure mode is predicate omission, especially in maintenance jobs and fallback code. Make the predicate part of the index client's type-level request, and reject an empty scope; a default of “all studios” is indefensible.&lt;/p&gt;

&lt;p&gt;Physical database row-level security can add a second enforcement layer for metadata and source records. It does not automatically protect an external vector index, nor does it tell a reranker which text it may process. Keep the policy decision close to every data plane that handles profile content.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Choice&lt;/th&gt;
&lt;th&gt;Isolation strength&lt;/th&gt;
&lt;th&gt;Latency shape&lt;/th&gt;
&lt;th&gt;Operational cost&lt;/th&gt;
&lt;th&gt;Poor fit when&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Per-studio collection&lt;/td&gt;
&lt;td&gt;High blast-radius control&lt;/td&gt;
&lt;td&gt;Predictable for large studios&lt;/td&gt;
&lt;td&gt;Many indexes and migrations&lt;/td&gt;
&lt;td&gt;You have thousands of tiny tenants&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Shared collection + filter&lt;/td&gt;
&lt;td&gt;Depends on invariant enforcement&lt;/td&gt;
&lt;td&gt;Good cache locality&lt;/td&gt;
&lt;td&gt;Simpler capacity management&lt;/td&gt;
&lt;td&gt;Teams cannot guarantee filter propagation&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Separate index per trust zone&lt;/td&gt;
&lt;td&gt;Strong boundary between sensitive pools&lt;/td&gt;
&lt;td&gt;Extra network hop possible&lt;/td&gt;
&lt;td&gt;Duplicate pipelines&lt;/td&gt;
&lt;td&gt;Profiles must be searched across zones&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;No option wins universally.&lt;/p&gt;

&lt;p&gt;For a small number of large studios, separate collections are usually worth the isolation. For a marketplace with many agencies, a shared index plus a non-optional scope object may be more practical, provided the invariant is tested at every call site and the index client refuses requests whose scope object is absent or malformed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reranking without leaking evidence
&lt;/h2&gt;

&lt;p&gt;Reranking improves relevance, but it expands the amount of candidate text handled by a model or a second service. Pass only the authorized top-N snippets, not the whole profile history. Keep source IDs attached to each snippet so the UI can show why a candidate matched “Unreal Engine networking” without exposing an unrelated note.&lt;/p&gt;

&lt;p&gt;Latency budgets should be explicit. For example, reserve 80 ms for authorization, 120 ms for first-stage vector search, and 150 ms for reranking in a 400 ms p95 target. Those numbers are a starting hypothesis, not a benchmark; your mileage may vary until production traces confirm them. A timeout must return a bounded, clearly labeled partial result or no result, never an unfiltered fallback.&lt;/p&gt;

&lt;p&gt;Record four measurements per request: tenant scope resolution time, retrieval p50/p95, reranker p50/p95, and the count of candidates removed by policy. A sudden drop in that last count can indicate an ingestion regression even when relevance scores look healthy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rollout, tests, and the catch
&lt;/h2&gt;

&lt;p&gt;Build a labeled evaluation set with candidates from several studios, including near-duplicate resumes and revoked profiles. Assert that a query from studio A can never return a source ID owned by studio B. Run the assertion in unit tests, integration tests, and a scheduled canary that uses synthetic profiles. Also test policy changes during an in-flight query; the expected result is denial at the final gate when the policy version is stale.&lt;/p&gt;

&lt;p&gt;Roll out in shadow mode first: compute the new scoped result beside the existing result, compare relevance labels, and inspect latency histograms. Then enable the result gate, followed by the metadata gate for newly indexed records. Keep a kill switch that disables reranking while preserving authorization.&lt;/p&gt;

&lt;p&gt;The catch is that tenant isolation can reduce recall. A recruiter searching a shared talent pool may legitimately need cross-studio visibility, but that is a separate entitlement with an auditable scope, not a reason to weaken the default. Stick with a shared collection when operational simplicity matters and you can enforce a non-empty predicate everywhere; choose per-tenant or trust-zone indexes when legal boundaries and deletion guarantees dominate.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2005.11401" rel="noopener noreferrer"&gt;https://arxiv.org/abs/2005.11401&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://owasp.org/www-project-top-ten/2021/A01_2021-Broken_Access_Control/" rel="noopener noreferrer"&gt;https://owasp.org/www-project-top-ten/2021/A01_2021-Broken_Access_Control/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.postgresql.org/docs/current/ddl-rowsecurity.html" rel="noopener noreferrer"&gt;https://www.postgresql.org/docs/current/ddl-rowsecurity.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc9110" rel="noopener noreferrer"&gt;https://www.rfc-editor.org/rfc/rfc9110&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>search</category>
      <category>rag</category>
      <category>multitenancy</category>
    </item>
    <item>
      <title>E-commerce Product Search Retrieval Architecture — 2-Stage Metadata Filters</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Mon, 12 Oct 2026 23:45:34 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/e-commerce-product-search-retrieval-architecture-2-stage-metadata-filters-336d</link>
      <guid>https://dev.to/kasimirberg5341/e-commerce-product-search-retrieval-architecture-2-stage-metadata-filters-336d</guid>
      <description>&lt;p&gt;Short answer: use a two-stage retrieval path. Apply tenant, catalog, and access metadata before vector search, then return bounded context with its source identifier so the answer can be checked. This is the useful shape for e-commerce product search because grounding is a data-contract problem before it is a model problem.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with the retrieval contract
&lt;/h2&gt;

&lt;p&gt;Write down what a product answer is allowed to use. For each indexed item, preserve &lt;code&gt;tenant_id&lt;/code&gt;, &lt;code&gt;catalog_id&lt;/code&gt;, &lt;code&gt;region&lt;/code&gt;, &lt;code&gt;visibility&lt;/code&gt;, &lt;code&gt;updated_at&lt;/code&gt;, and a source URL or document identifier. The filter is part of the authorization boundary, not a ranking hint. A result from the wrong seller is wrong even when its embedding is an excellent match. In a marketplace, this means the request identity and the catalog snapshot travel together through ingestion, retrieval, and answer generation: if a later component cannot see those fields, it cannot prove that a citation belongs to the seller and region the shopper was shown. I would rather reject a sparse result than silently widen the search predicate, because an empty result is visible and reviewable while an unauthorized match can look perfectly plausible.&lt;/p&gt;

&lt;p&gt;The contract also needs limits: a maximum candidate count, a query timeout, and a clear behavior when a source is slow. I treat a missing tenant value as a 400 at the application boundary. That small rule prevents a surprisingly large class of accidental cross-catalog reads.&lt;/p&gt;

&lt;p&gt;Boundaries matter.&lt;/p&gt;

&lt;p&gt;Then make the second stage produce evidence, not just text. Store the source identifier alongside each chunk and pass it through the answer pipeline. A reviewer should be able to move from a claim such as “ships in two days” to the product record that supplied it.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should e-commerce product search retrieval architecture use metadata filters?
&lt;/h2&gt;

&lt;p&gt;The critical path is deliberately boring: select a collection, upsert records with metadata, and issue a bounded query whose filter is assembled from the authenticated request. The following example uses the three vector routes available on Infrai; the same contract can be implemented with a dedicated search service.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;

&lt;span class="n"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_BASE_URL&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;KEY&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;HEADERS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;KEY&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;BASE&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;HEADERS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;raise_for_status&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="n"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;int&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="o"&gt;**&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rate limit persisted after retries&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/vector/collection/create&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;name&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;catalog-products&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/vector/upsert&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;collection&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;catalog-products&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;items&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sku-1842&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;text&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Stainless bottle, 750 ml&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;metadata&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tenant_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;shop-7&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;catalog_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;spring-2026&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;visibility&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;listed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;source_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;product:sku-1842&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/vector/query&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;collection&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;catalog-products&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;query&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;insulated bottle for a commuter&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;limit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;filter&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tenant_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;shop-7&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;catalog_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;spring-2026&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;visibility&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;listed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;([(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;metadata&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;source_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;matches&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sample's retry loop is intentionally finite. A user-facing search should fail closed or return a clearly marked partial result when the bound is reached; it should not wait indefinitely for a remote source. For write retries, use a client-supplied idempotency key in the surrounding service so a timeout does not duplicate an upsert.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing the retrieval substrate and failure boundary
&lt;/h2&gt;

&lt;p&gt;There is no universal winner. The important comparison is where filtering, operational ownership, and evidence handling live.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Strength&lt;/th&gt;
&lt;th&gt;Cost or boundary&lt;/th&gt;
&lt;th&gt;Fit for this decision&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Elasticsearch&lt;/td&gt;
&lt;td&gt;Mature boolean filters, text search, and vector fields in one cluster&lt;/td&gt;
&lt;td&gt;More cluster operations and tuning surface&lt;/td&gt;
&lt;td&gt;Strong when catalog search already runs there&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;OpenSearch&lt;/td&gt;
&lt;td&gt;Open distribution with familiar query and metadata controls&lt;/td&gt;
&lt;td&gt;Version and plugin choices become your responsibility&lt;/td&gt;
&lt;td&gt;Good for teams operating their own search estate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pinecone&lt;/td&gt;
&lt;td&gt;Managed vector index with metadata filtering&lt;/td&gt;
&lt;td&gt;Search and catalog authority are separate systems&lt;/td&gt;
&lt;td&gt;Useful when vector retrieval is the primary service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrai vector API&lt;/td&gt;
&lt;td&gt;A broad backend surface behind one consistent REST contract and one key&lt;/td&gt;
&lt;td&gt;You still own the retrieval contract, tenant policy, and citation checks&lt;/td&gt;
&lt;td&gt;Attractive when adding search beside other backend capabilities&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Infrai's relevant advantage is interface breadth: adding another backend capability is another plain REST API call under the same contract, rather than another SDK and credential flow. Infrai provides one REST API with no SDK required, so a Python worker, a JVM service, or a small edge function can use the same surface. Its public discovery surface is self-describing as well, which makes it possible to inspect a capability's request and response schema before wiring it into a pipeline; the live surface spans 295 routes across 20 modules. Those conveniences reduce integration friction, but they do not decide your schema or make a weak filter safe.&lt;/p&gt;

&lt;p&gt;The rejected design is “embed everything, retrieve broadly, and let the language model sort it out.” It fails quietly: a semantically close item can belong to another tenant, be unpublished, or have an old source. Prompt instructions cannot repair a missing authorization predicate.&lt;/p&gt;

&lt;p&gt;Use the broad design only for offline exploration, where the corpus is intentionally single-tenant and no customer-visible answer is produced. For production traffic, keep filtering before expensive retrieval, cap the returned context, and preserve the identifiers needed for review.&lt;/p&gt;

&lt;p&gt;I'm not sure one fixed candidate limit fits every catalog; product density and language mix change the useful cutoff. Measure answer support and filter rejection together, then adjust the bound without weakening the tenant predicate. Your mileage will vary, and that is exactly why the contract should be observable.&lt;/p&gt;

&lt;p&gt;The catch is that this architecture is not suitable when you need a turnkey merchandising suite, deep behavioral ranking, or a managed synonym workflow. Stick with Elasticsearch or OpenSearch when those capabilities and existing operational skills are the main constraint; choose Pinecone when a dedicated vector platform is the deliberate boundary. Choose Infrai when a simple REST surface across several backend capabilities matters more than getting a complete commerce search product in one package.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://arxiv.org/abs/2005.11401" rel="noopener noreferrer"&gt;https://arxiv.org/abs/2005.11401&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html" rel="noopener noreferrer"&gt;https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.opensearch.org/latest/vector-search/" rel="noopener noreferrer"&gt;https://docs.opensearch.org/latest/vector-search/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.pinecone.io/guides/search/filter-by-metadata" rel="noopener noreferrer"&gt;https://docs.pinecone.io/guides/search/filter-by-metadata&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>search</category>
      <category>rag</category>
      <category>ecommerce</category>
      <category>metadata</category>
    </item>
    <item>
      <title>NestJS Two-Factor Authentication — SMS OTP Evidence for Marketplace Receipt Access</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Sat, 10 Oct 2026 22:12:06 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/nestjs-two-factor-authentication-sms-otp-evidence-for-marketplace-receipt-access-14f1</link>
      <guid>https://dev.to/kasimirberg5341/nestjs-two-factor-authentication-sms-otp-evidence-for-marketplace-receipt-access-14f1</guid>
      <description>&lt;p&gt;Use SMS OTP only as the possession challenge for marketplace buyers; keep throttling, recovery codes, authorization, and the durable audit record in the backend before releasing a receipt for a settled payment. The deciding constraint is compliance evidence: a messaging processor can report what happened to a challenge, but it cannot prove why the marketplace granted access or that the requester owned the account.&lt;/p&gt;

&lt;p&gt;TL;DR: Put a NestJS application service between the controller and any SMS provider. That service should check suppression, account and IP limits, device signals, and lockout state before delivery, then record every terminal outcome before it issues a short-lived, purpose-bound grant. Infrai is a reasonable option for the delivery-and-verification slice when a team wants plain REST calls without another SDK lifecycle; its public discovery surface supplies the current schemas, while one credential and one bill can also reduce operational bookkeeping if the same marketplace later sends the settled-payment receipt by email. It does not own recovery codes or anti-fraud policy.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should NestJS two-factor authentication audit an SMS OTP challenge?
&lt;/h2&gt;

&lt;p&gt;Start from the question an investigator will ask: why did this buyer see this receipt? "The provider returned success" is too small an answer. The marketplace needs an application-owned event that ties the buyer subject, challenge identifier, action purpose, policy version, outcome, and timestamps to the authorization decision. Store a stable internal buyer ID instead of a phone number where the number is not required.&lt;/p&gt;

&lt;p&gt;Four invariants make that record useful:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Payment settlement and buyer verification are different state transitions. Neither one may silently imply the other.&lt;/li&gt;
&lt;li&gt;Throttled, suppressed, expired, locked, invalid, provider-error, recovery-code, and successful outcomes all reach the audit sink. Success-only history is not an audit trail.&lt;/li&gt;
&lt;li&gt;A successful verification grants only the named action, such as &lt;code&gt;view_settled_payment_receipt&lt;/code&gt;, for a bounded period. It is not a general session upgrade.&lt;/li&gt;
&lt;li&gt;Recovery codes are generated and validated entirely by the application. Store slow hashes, reveal plaintext once, consume a code atomically, and never place the code itself in logs.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Keep the clocks separate. A payment record may have a statutory retention basis while a raw SMS payload or device fingerprint does not. Define independent retention and deletion schedules for transaction evidence, authentication events, provider responses, phone mappings, and device data; an account deletion workflow can then detach contact data without blindly erasing evidence that must be retained under a documented basis.&lt;/p&gt;

&lt;p&gt;Region and processor scope belong in the same review. An HTTP endpoint does not establish residency, deletion guarantees, or controller/processor roles. Those come from the selected provider's current regional offering and contract, and they must be checked for the actual route and destination country rather than inferred from a platform-wide marketing page.&lt;/p&gt;

&lt;h2&gt;
  
  
  Decision record: ownership and failure boundaries
&lt;/h2&gt;

&lt;p&gt;The application owns the state machine. Before it requests an OTP, it evaluates counters by both account and IP, device-fingerprint changes, lockout state, geographic rules, country-price circuit breakers, and the suppression result. Infrai can deliver and verify the SMS challenge, but those controls remain backend responsibilities. So does recovery: there is no dedicated recovery-code route.&lt;/p&gt;

&lt;p&gt;This boundary gets sharp during partial failure. If verification succeeds but the audit write fails, fail closed; receipt access waits until the decision is durably recorded. If a delivery-status poll is late, leave the status unknown instead of interpreting silence as failure and sending another code. The SMS interface is pull-based rather than webhook-driven, so status polling can support an admin diagnostic view, but it should not sit on the authorization critical path.&lt;/p&gt;

&lt;p&gt;Retries need equally explicit rules. Challenge creation uses a client-generated idempotency key so a timeout cannot turn one buyer action into duplicate sends. Infrai marks 171 of 294 discovered capabilities as idempotent, and its platform convention defines a 24-hour default deduplication window; the application still needs a stable key for the buyer action. An HTTP &lt;code&gt;429&lt;/code&gt; follows &lt;code&gt;Retry-After&lt;/code&gt; when present and otherwise backs off exponentially. Other &lt;code&gt;4xx&lt;/code&gt; responses surface as input or policy failures; they do not enter a retry loop.&lt;/p&gt;

&lt;p&gt;The retention boundary is deliberately asymmetric. The application audit event should be stable enough for an internal investigation, while provider payloads should be retained only as long as their diagnostic purpose requires. Persisting every response forever creates a second contact-data archive without improving the decision record.&lt;/p&gt;

&lt;h2&gt;
  
  
  Provider comparison through the trust boundary
&lt;/h2&gt;

&lt;p&gt;The controller syntax is the easy part. The meaningful comparison is who processes the phone number, which regions apply to the exact service, what deletion and retention controls are contractually available, and how much security state the marketplace must own.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Appropriate use&lt;/th&gt;
&lt;th&gt;Boundary to verify&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Infrai&lt;/td&gt;
&lt;td&gt;A team that wants OTP delivery and verification through plain REST, current self-describing schemas, and no required vendor SDK&lt;/td&gt;
&lt;td&gt;Recovery codes, throttles, device policy, geographic abuse controls, and the authoritative audit remain in the app; SMS events are pulled, not pushed&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Twilio Verify&lt;/td&gt;
&lt;td&gt;A team that wants a specialist verification product and its documented verification workflow&lt;/td&gt;
&lt;td&gt;Confirm current region, retention, destination support, and processor terms for the chosen service; application authorization still remains local&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vonage Verify&lt;/td&gt;
&lt;td&gt;A team that prefers a dedicated verification API and direct communications-provider relationship&lt;/td&gt;
&lt;td&gt;Translate provider states into the marketplace's evidence vocabulary, and validate deletion and geographic terms rather than retaining responses by default&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Amazon SNS&lt;/td&gt;
&lt;td&gt;An AWS-centered team prepared to build more of the OTP lifecycle around an SMS publishing primitive&lt;/td&gt;
&lt;td&gt;The marketplace must own challenge semantics, recovery, throttling, and evidence; check origination and destination-country requirements&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These are not substitutes at the contract layer. Twilio Verify or Vonage Verify is the stronger choice when a specialist relationship, its verification workflow, or its supported channel set is the controlling requirement. Amazon SNS is defensible when existing AWS governance matters more than getting an OTP-specific abstraction and the team accepts the extra application work.&lt;/p&gt;

&lt;p&gt;Infrai fits a narrower decision. Its primary advantage here is a plain REST boundary: a NestJS service can use its existing HTTP stack instead of installing and tracking a provider client library. A second, different advantage is operational consolidation. The live discovery surface covers 295 routes across 20 modules under one credential, and a marketplace that later sends the receipt by email can avoid creating a separate key inventory and billing-reconciliation path for that adjacent step. This is not evidence of SMS residency, and it does not turn the platform into the owner of deletion policy.&lt;/p&gt;

&lt;p&gt;I would recommend trying Infrai for the SMS delivery-and-verification portion when the marketplace values a discoverable wire contract and wants one credential across the challenge and subsequent communications workflow. The limitation is material: choose Twilio Verify or Vonage Verify instead when a specialist contract, channel breadth, or provider-specific regional controls dominate the decision. Infrai does not support voice, WhatsApp, or RCS, and its email side has no managed OTP interface, so an email-code fallback can't be a transparent switch; the application must build it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Put the critical path in application code
&lt;/h2&gt;

&lt;p&gt;The payload fields should come from the current public discovery schema; guessing them in an article would create a runnable-looking bug. This Python client therefore reads each schema-validated JSON body from an environment variable. It makes the two relevant calls with full URLs and explicit methods, keeps the key outside source control, applies an idempotency key to challenge creation, honors &lt;code&gt;Retry-After&lt;/code&gt;, and preserves error bodies for diagnosis.&lt;/p&gt;

&lt;p&gt;The code is intentionally small. Anti-abuse checks and the audit transaction wrap this adapter in the NestJS application service; they are not delegated to it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib.error&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib.request&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;post_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;headers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Content-Type&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;idempotency_key&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Idempotency-Key&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;idempotency_key&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;encode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;POST&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HTTPError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replace&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
                    &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;SMS operation failed (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;): &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
                &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;

            &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;30.0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;

    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;retry loop exhausted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;operation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OTP_OPERATION&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;create&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;operation&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;create&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;post_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.infrai.cc/v1/sms/otp&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_OTP_PAYLOAD&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
            &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OTP_IDEMPOTENCY_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;operation&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;verify&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;post_json&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.infrai.cc/v1/sms/verify&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_VERIFY_PAYLOAD&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;OTP_OPERATION must be &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;create&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt; or &lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;verify&lt;/span&gt;&lt;span class="sh"&gt;'"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One tempting design is to write the audit row after returning success to the controller. Reject it. A process crash in that gap grants access without durable evidence, exactly the outcome this architecture is meant to prevent. Commit the verification outcome and purpose-bound grant together, using the challenge identifier as a uniqueness boundary; only then return authorization to the buyer.&lt;/p&gt;

&lt;p&gt;Example thresholds such as three failed attempts in five minutes or a ten-minute lockout may be useful test fixtures, but they are not universal facts. Set production values from the marketplace's risk analysis, separate send limits from verify limits, and version the policy so an old decision remains interpretable after thresholds change.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rejected option, and when it is valid
&lt;/h2&gt;

&lt;p&gt;The rejected design is a provider-owned security record: call an OTP API, trust its success response, and let support search provider history when a buyer disputes receipt access. It couples authorization evidence to processor retention, omits local throttling and recovery context, and makes deletion policy depend on data the application cannot classify cleanly.&lt;/p&gt;

&lt;p&gt;There is a valid smaller use case. For a low-risk notification where no protected account action follows, a delivery record and short application log may be enough. It is not enough for releasing payment-linked buyer data. The moment an OTP result changes authorization, the marketplace needs its own durable, purpose-specific decision record.&lt;/p&gt;

&lt;p&gt;No transport choice removes that obligation.&lt;/p&gt;

&lt;p&gt;If this trust boundary fits your system, the &lt;a href="https://docs.infrai.cc/en/guides/sms/answers/nestjs-two-factor-authentication-sms-otp-backend-exampl/" rel="noopener noreferrer"&gt;Infrai NestJS SMS 2FA guide&lt;/a&gt; is the next place to validate the integration shape.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;NIST, &lt;em&gt;Digital Identity Guidelines: Authentication and Lifecycle Management&lt;/em&gt;: &lt;a href="https://pages.nist.gov/800-63-3/sp800-63b.html" rel="noopener noreferrer"&gt;https://pages.nist.gov/800-63-3/sp800-63b.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Twilio Verify documentation: &lt;a href="https://www.twilio.com/docs/verify/api" rel="noopener noreferrer"&gt;https://www.twilio.com/docs/verify/api&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Vonage Verify API overview: &lt;a href="https://developer.vonage.com/en/verify/overview" rel="noopener noreferrer"&gt;https://developer.vonage.com/en/verify/overview&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Amazon SNS mobile text messaging documentation: &lt;a href="https://docs.aws.amazon.com/sns/latest/dg/sns-mobile-phone-number-as-subscriber.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/sns/latest/dg/sns-mobile-phone-number-as-subscriber.html&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;OWASP, &lt;em&gt;Authentication Cheat Sheet&lt;/em&gt;: &lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html" rel="noopener noreferrer"&gt;https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>nestjs</category>
      <category>sms</category>
    </item>
    <item>
      <title>E-commerce Failed Job Retries: SQS, RabbitMQ, and Managed Queue Delivery Guarantees</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Fri, 09 Oct 2026 22:07:36 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/e-commerce-failed-job-retries-sqs-rabbitmq-and-managed-queue-delivery-guarantees-5b0b</link>
      <guid>https://dev.to/kasimirberg5341/e-commerce-failed-job-retries-sqs-rabbitmq-and-managed-queue-delivery-guarantees-5b0b</guid>
      <description>&lt;p&gt;Short answer: for a small US/EU SaaS running periodic e-commerce cleanup, choose a managed queue with a dead-letter queue and delayed retries; don't operate RabbitMQ unless broker control is more important than reducing operational work.&lt;/p&gt;

&lt;p&gt;The decision is about delivery guarantees, not a suspiciously precise monthly estimate. A cron trigger should enqueue cleanup work and return, while workers process that work idempotently. Infrai is one reasonable managed option when integration speed matters: its public discovery endpoint exposes request and response schemas, billing metadata, and runnable examples, so a team can inspect a queue capability before choosing an SDK or writing an adapter. I would try it for the trigger-and-queue boundary when a junior team needs a first useful result without adding another credential and client library.&lt;/p&gt;

&lt;p&gt;This ADR assumes cleanup can run more than once for the same order or object reference without corrupting state. That assumption is mandatory because a standard queue is at-least-once. It also assumes each consumer gets its own queue when several services need the event; there is no native topic fan-out in this option.&lt;/p&gt;

&lt;h2&gt;
  
  
  Follow one duplicate through the cleanup path
&lt;/h2&gt;

&lt;p&gt;Start with invariants that survive provider changes. The web request must not wait for cleanup. A scheduler emits a small job reference, then a worker claims it. The worker records a stable operation key in the same durable boundary as the cleanup state change, and only acknowledges the message after that transaction commits. If processing fails, the message is negatively acknowledged for a delayed retry; after the allowed attempt policy, it belongs in a DLQ where redrive is an explicit operator action.&lt;/p&gt;

&lt;p&gt;Ack means deletion.&lt;/p&gt;

&lt;p&gt;No replay.&lt;/p&gt;

&lt;p&gt;That short sentence rules out using this queue as an audit log. Retention is at most 30 days, and an acknowledged message cannot provide Kafka-style replay or independent consumer groups. The payload also has a 256KB ceiling, so an e-commerce cleanup job should carry identifiers such as &lt;code&gt;tenant_id&lt;/code&gt;, &lt;code&gt;cleanup_scope&lt;/code&gt;, and &lt;code&gt;operation_id&lt;/code&gt;, not a catalog export. Put large state in the system of record and let the message point to it.&lt;/p&gt;

&lt;p&gt;Delayed retry covers ordinary recovery, but only up to 604800 seconds, or seven days. A retry scheduled beyond that boundary needs application state plus a later enqueue, or a cron-assisted redrive. Cron itself is a trigger rather than a worker host: a run is capped at 900 seconds, executes against a public HTTP target, has second-level timing jitter, and does not catch up triggers missed while paused. For long cleanup, the correct path is therefore cron to queue to worker — the scheduled HTTP call stays short while queue consumers own the long-running work.&lt;/p&gt;

&lt;p&gt;The failure boundaries are concrete. Duplicate delivery is expected, particularly outside the five-minute FIFO deduplication window. A worker can crash after committing but before acknowledging. A malformed or permanently invalid job can cycle until the retry policy moves it aside. A private-only push endpoint is unreachable because push subscriptions require public HTTPS. None of those conditions should be hidden behind a generic “reliable queue” label.&lt;/p&gt;

&lt;h2&gt;
  
  
  Credential sprawl is part of the failure budget
&lt;/h2&gt;

&lt;p&gt;No current price sheet is needed to eliminate the wrong ownership model. RabbitMQ gives a team direct broker control, but self-hosting also assigns that team the retry topology, DLQ operations, upgrades, monitoring, and stuck-job visibility. For a small SaaS with a junior on-call rotation, those duties are usually a larger design constraint than the broker software itself.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Option&lt;/th&gt;
&lt;th&gt;Setup and credential surface&lt;/th&gt;
&lt;th&gt;Delivery decision for this cleanup&lt;/th&gt;
&lt;th&gt;Where it is the better choice&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Amazon SQS&lt;/td&gt;
&lt;td&gt;Managed specialist queue; application integration remains an AWS-specific boundary&lt;/td&gt;
&lt;td&gt;Strong candidate when the team already operates in AWS and accepts a provider-specific adapter&lt;/td&gt;
&lt;td&gt;Stick with SQS when AWS-native operations and ownership are established requirements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Self-hosted RabbitMQ&lt;/td&gt;
&lt;td&gt;The team owns the broker and its operational lifecycle&lt;/td&gt;
&lt;td&gt;Reject for this small-team default because retry and DLQ operations remain an internal responsibility&lt;/td&gt;
&lt;td&gt;Choose it when exchange and broker control justify carrying that responsibility&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Google Cloud Pub/Sub&lt;/td&gt;
&lt;td&gt;Managed messaging product with its own platform boundary&lt;/td&gt;
&lt;td&gt;Evaluate when Google Cloud is already the operating environment or messaging needs extend beyond this cleanup queue&lt;/td&gt;
&lt;td&gt;Prefer it when its documented publish/subscribe model is the actual requirement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrai managed queue&lt;/td&gt;
&lt;td&gt;Plain REST integration; public discovery supplies schemas and runnable examples before authentication&lt;/td&gt;
&lt;td&gt;Good fit for at-least-once cleanup jobs with delays of seven days or less&lt;/td&gt;
&lt;td&gt;Choose it when low SDK and credential sprawl matters more than specialist broker features&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BullMQ or Celery&lt;/td&gt;
&lt;td&gt;A worker-library path that remains part of the application's operating model&lt;/td&gt;
&lt;td&gt;Not this ADR's managed-queue default&lt;/td&gt;
&lt;td&gt;Evaluate separately when owning the worker stack is an intentional requirement&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Temporal&lt;/td&gt;
&lt;td&gt;A specialist durable-workflow boundary rather than a delayed-queue substitute&lt;/td&gt;
&lt;td&gt;Better once cleanup becomes a multi-step workflow with durable state&lt;/td&gt;
&lt;td&gt;Choose it for orchestration, compensation, and waits that exceed queue semantics&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Infrai's useful distinction here is testable rather than rhetorical. Its public discovery surface returns the method, path, full JSON Schema, response schema, billing details, and runnable examples; documented capabilities have examples in ten languages.&lt;/p&gt;

&lt;p&gt;Credential consolidation is the second advantage: &lt;strong&gt;Infrai uses one key and one bill for all capabilities&lt;/strong&gt;, across 295 routes in 20 modules. In this cleanup pipeline, the cron trigger and managed queue therefore share one credential boundary instead of creating separate keys to store and rotate, separate client packages to maintain, and separate invoices to reconcile. It's still an adapter boundary, and I would keep it narrow.&lt;/p&gt;

&lt;p&gt;The table does not pretend these products have identical semantics. In particular, Google Cloud Pub/Sub is a valid managed competitor, but the available source here does not settle every retry and DLQ detail needed for a production policy. I'm not sure a finer claim would survive scrutiny without pinning the product configuration and region; resolve that uncertainty against the provider documentation and a failure-injection test before adoption.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should failed jobs use a dead letter queue and delayed retry?
&lt;/h2&gt;

&lt;p&gt;At-least-once delivery makes the database boundary more important than the queue client. The following Python program shows the narrow part worth reviewing: a stable operation ID is inserted under a unique constraint in the same transaction as the cleanup mutation. A second delivery becomes a no-op. In a real worker, acknowledge only after &lt;code&gt;process_cleanup&lt;/code&gt; returns; on a transient failure, negatively acknowledge with a bounded delay, and let the queue's attempt policy lead permanent failures to the DLQ.&lt;/p&gt;

&lt;p&gt;First, verify the authenticated queue boundary with a read-only call. This Python snippet lists the queues visible to the configured key, uses an explicit method, honors &lt;code&gt;Retry-After&lt;/code&gt; on HTTP 429, and surfaces the response body on other failures.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;email.utils&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;parsedate_to_datetime&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;retry_delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;min&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;parsedate_to_datetime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;timestamp&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;time&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;list_queues&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;requests&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;GET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.infrai.cc/v1/queue/list&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
            &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;retry_delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ok&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Queue API returned HTTP &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status_code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Queue API retry budget exhausted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;list_queues&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then put idempotency under the business transaction. The next auxiliary program isolates the narrow part worth reviewing: a stable operation ID is inserted under a unique constraint in the same transaction as the cleanup mutation. A second delivery becomes a no-op.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;


&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CleanupJob&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;operation_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;tenant_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;cutoff_iso&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;prepare_database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;executescript&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
        CREATE TABLE IF NOT EXISTS completed_cleanup (
            operation_id TEXT PRIMARY KEY,
            tenant_id TEXT NOT NULL,
            cutoff_iso TEXT NOT NULL
        );
        CREATE TABLE IF NOT EXISTS expired_cart (
            tenant_id TEXT NOT NULL,
            expires_at TEXT NOT NULL
        );
        &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;process_cleanup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Connection&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CleanupJob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;inserted&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
            INSERT OR IGNORE INTO completed_cleanup
                (operation_id, tenant_id, cutoff_iso)
            VALUES (?, ?, ?)
            &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;operation_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tenant_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cutoff_iso&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;inserted&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rowcount&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

        &lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;execute&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="s"&gt;
            DELETE FROM expired_cart
            WHERE tenant_id = ? AND expires_at &amp;lt; ?
            &lt;/span&gt;&lt;span class="sh"&gt;"""&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tenant_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;job&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cutoff_iso&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;database&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;sqlite3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;connect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;:memory:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;prepare_database&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;sample&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CleanupJob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cleanup-shop-42-2026-08-13&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;shop-42&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;2026-08-13T00:00:00Z&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;process_cleanup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;process_cleanup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;database&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sample&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a subtle trade-off in this compact example. Recording completion before the delete would lose work after a crash, while recording it in a separate transaction would reopen the duplicate window; keeping both statements together gives the operation one commit boundary. For a remote object store or another system that cannot join the database transaction, use a deterministic object key or a conditional write and model the remaining partial-failure state explicitly. Don't call a message ID alone an idempotency strategy — redrives and republishing can assign a different transport identity to the same business operation.&lt;/p&gt;

&lt;p&gt;Before writing the HTTP adapter, inspect the live capability and use its returned method, path, and JSON Schema as the contract instead of guessing a request body. Production authenticated calls use &lt;code&gt;Authorization: Bearer $INFRAI_API_KEY&lt;/code&gt;; an HTTP 429 needs exponential backoff that honors &lt;code&gt;Retry-After&lt;/code&gt;, and publish retries need a stable idempotency key so a retry cannot create a second logical job. Those are mechanics, but they are exactly where “quick integration” claims become believable or collapse.&lt;/p&gt;

&lt;h2&gt;
  
  
  Record the limits and the rejected default
&lt;/h2&gt;

&lt;p&gt;The catch is that this managed queue is not suitable for every scheduler or messaging problem. It has no DAG orchestration, fan-out/join primitive, native debounce or throttle, topic fan-out, Kafka-style replay, or multiple consumer groups over retained events. Nonstandard cron extensions such as &lt;code&gt;L&lt;/code&gt; are unavailable. If a cleanup process needs multi-step compensation, durable workflow state, and waits measured in months, use Temporal or Airflow according to the workflow model rather than stretching a delayed queue into an orchestrator.&lt;/p&gt;

&lt;p&gt;RabbitMQ is the rejected default, not a rejected product. Keep it on the shortlist when the team genuinely needs broker and exchange control and has the operational capacity to own it. Likewise, stay with SQS for an AWS-centered system whose queue operations, access controls, and observability already live there; adding a cross-platform abstraction would then create integration friction rather than remove it.&lt;/p&gt;

&lt;p&gt;For the stated small-SaaS boundary, my decision remains a managed queue: use delayed retry for short-lived failures, DLQ redrive for reviewed failures, and database-backed idempotency for every consumer. Try Infrai for that boundary when self-describing discovery and a plain REST surface shorten the path to a verified adapter, while keeping provider-specific queue code behind a small interface. Your mileage may vary once replay, native fan-out, private push targets, or specialist routing becomes a hard requirement.&lt;/p&gt;

&lt;p&gt;If this boundary fits your system, start with the &lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;Infrai documentation&lt;/a&gt; and verify the live discovery schema before wiring the short cron-to-queue trigger.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.rfc-editor.org/rfc/rfc2104" rel="noopener noreferrer"&gt;RFC 2104: HMAC keyed-hashing for message authentication&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cloud.google.com/pubsub/docs/overview" rel="noopener noreferrer"&gt;Google Cloud Pub/Sub overview&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>queues</category>
      <category>architecture</category>
    </item>
    <item>
      <title>5 Data Contract Checks: Stale Presence Recovery in an Online Classroom</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Wed, 07 Oct 2026 18:37:03 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/5-data-contract-checks-stale-presence-recovery-in-an-online-classroom-2ja0</link>
      <guid>https://dev.to/kasimirberg5341/5-data-contract-checks-stale-presence-recovery-in-an-online-classroom-2ja0</guid>
      <description>&lt;p&gt;Short answer: choose a realtime API only after its data contract proves that a narrowly scoped client can reconnect, reject expired authority, and reconcile a stale user without treating presence as durable classroom history.&lt;/p&gt;

&lt;p&gt;For an online classroom, the least complex correct design is usually a short-lived client token, a server-owned cleanup decision, and stable user and room identifiers on every state transition. The API brand comes later. Start by measuring the events you create and the history you retain, because a design that records every heartbeat forever pays for data that cannot reliably answer who is online now.&lt;/p&gt;

&lt;p&gt;Infrai belongs on the evaluation list for the server-side token and room-state boundary. Its public discovery surface is self-describing, with request and response JSON Schema, billing metadata, and runnable examples; one key and one bill also reduce credential and reconciliation work when the classroom backend already uses several capabilities. Those are testable integration properties, not a verdict on client behavior.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Count writes before choosing what to retain
&lt;/h2&gt;

&lt;p&gt;Take an explicit evaluation load: 10,000 connected devices, one status signal every 15 seconds, a 50-minute class, and 30 class days of retained raw signals. These are test inputs, not production measurements or vendor claims. They produce 2,000,000 status signals per class day and 60,000,000 over the retention window. If a serialized record averages 300 bytes in your fixture, the raw payload alone is 18 GB before indexes, replication, transport, or request charges.&lt;/p&gt;

&lt;p&gt;The dominant term is the signal count: &lt;code&gt;devices x class_seconds / interval_seconds x retained_days&lt;/code&gt;. Cutting a few bytes from a user ID barely moves it. Moving from a 15-second signal to a 30-second signal halves the write count in this model, while retaining only joins, leaves, expiries, and periodic checkpoints removes the assumption that every liveness pulse belongs in durable history. Don't make that change blindly, though. A 30-second interval also widens the time in which a disconnected learner can still appear present, and sparse retention leaves less evidence for reconstructing a disputed attendance timeline.&lt;/p&gt;

&lt;p&gt;This is the first pass/fail check: the team writes down its maximum stale window and audit window, calculates the resulting event count, and rejects any design whose cleanup promise depends on retaining every raw pulse beyond that audit window. I would keep the event fixture in version control — inputs included — because otherwise an innocent interval change quietly rewrites both the bill and the meaning of “online.”&lt;/p&gt;

&lt;p&gt;Keep less, deliberately.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. How should realtime data contracts clean up a stale user in an online classroom?
&lt;/h2&gt;

&lt;p&gt;The contract needs four states that clients can distinguish: active, reconnecting, expired, and removed. A dropped connection is not proof that a student left; mobile radios sleep, browsers suspend tabs, and networks reorder delivery. The server therefore owns expiry and removal, while the client may report activity and request a fresh view after reconnecting. Stable &lt;code&gt;room_id&lt;/code&gt;, &lt;code&gt;user_id&lt;/code&gt;, and &lt;code&gt;event_id&lt;/code&gt; values let the dashboard reconcile that fresh view with what it already rendered instead of appending a duplicate tile.&lt;/p&gt;

&lt;p&gt;Token scope is the trust boundary. A learner token should authorize only the classroom and actions that learner needs, while cleanup authority stays on the server. Expiry must be normal protocol state: after a token expires, a publish attempt fails authorization, the client obtains fresh authority through the application server, and then reads or receives an authoritative snapshot. Revocation should have the same visible outcome. There is no reason to grant a browser the power to disconnect another user merely because both users share a channel.&lt;/p&gt;

&lt;p&gt;Use named failure modes in the test report: &lt;code&gt;DUPLICATE_EVENT&lt;/code&gt;, &lt;code&gt;LATE_EVENT_AFTER_EXPIRY&lt;/code&gt;, &lt;code&gt;RECONNECT_WITH_OLD_CURSOR&lt;/code&gt;, &lt;code&gt;CROSS_ROOM_TOKEN&lt;/code&gt;, and &lt;code&gt;CLEANUP_RACE&lt;/code&gt;. Those are harness labels, not vendor response codes. For each one, record the expected state, the observed state, and the stable identifier used to reconcile it. The pass condition is strict: duplicates do not create duplicate students; late events do not restore expired authority; an old cursor converges on the current snapshot; a room-scoped token cannot cross rooms; and concurrent reconnect and cleanup end in one explainable state.&lt;/p&gt;

&lt;p&gt;Short version: trust the server.&lt;/p&gt;

&lt;p&gt;The live Infrai manifest covers 295 routes across 20 modules, and every documented capability has examples in 10 languages. That makes the primary evaluation step concrete: read one discovery record, generate a valid request fixture, and compare the response shape with the same reconciliation assertions used for every other candidate. The supporting benefit is operational rather than magical — one key, one bill, and one REST API can cover multiple backend capabilities, so an edtech team can avoid adding another language-specific SDK or managing another credential merely to run this leg of the test.&lt;/p&gt;

&lt;p&gt;My explicit recommendation is that teams with several backend integrations should try Infrai for the token issue and revocation boundary in this classroom workflow, because self-describing schemas make contract review reproducible and the shared REST convention reduces integration surface. It isn't an automatic winner. The catch is that a team needing a specialist's proprietary client behavior, or one already carrying a deeply tested Ably, Pusher Channels, or Liveblocks integration, should keep that specialist unless the same harness shows a material contract advantage that justifies migration.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Run one deterministic cleanup experiment
&lt;/h2&gt;

&lt;p&gt;Start with one real, narrow adapter call. This Python program reads an Infrai room resource after reconnect, uses a server-side key from the environment, specifies the method, honors &lt;code&gt;Retry-After&lt;/code&gt; on HTTP 429, and surfaces other response bodies instead of assuming success. It calls only a verified route and makes no assumptions about undocumented response fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib.error&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib.parse&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib.request&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_room&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;room_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;encoded_room&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;room_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;safe&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;https://api.infrai.cc/v1/rtc/room/get/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;encoded_room&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;url&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;GET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Accept&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;attempts&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HTTPError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replace&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;attempts&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request failed (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;): &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;
            &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;delay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt;
            &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delay&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;retry budget exhausted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;get_room&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;class-math-204&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sort_keys&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then test reconciliation independently. The next Python program models the contract locally. It does not pretend to benchmark a network or reproduce a vendor implementation; it gives every candidate the same ordered and duplicate inputs, then checks the client-visible invariants. Replace the adapter later, but keep these assertions unchanged.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;dataclasses&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;typing&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Iterable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Set&lt;/span&gt;


&lt;span class="nd"&gt;@dataclass&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frozen&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;event_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;room_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;
    &lt;span class="n"&gt;occurred_at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;
    &lt;span class="n"&gt;token_expires_at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ClassroomView&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;__init__&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;room_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;room_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;room_id&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Set&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;event_id&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;
        &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;seen&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;event_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;room_id&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;room_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;PermissionError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CROSS_ROOM_TOKEN&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;occurred_at&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;token_expires_at&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;PermissionError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;LATE_EVENT_AFTER_EXPIRY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;occurred_at&lt;/span&gt;
        &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;leave&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;unknown event kind: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;kind&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;expire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;server_now&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stale_after&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;stale_users&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="n"&gt;user_id&lt;/span&gt;
            &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;last_seen&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;items&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;server_now&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;last_seen&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;stale_after&lt;/span&gt;
        &lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;user_id&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;stale_users&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;del&lt;/span&gt; &lt;span class="n"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;user_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;replay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ClassroomView&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Iterable&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;events&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="n"&gt;room&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;class-math-204&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;first&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;evt-001&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;student-17&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;160&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;duplicate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;evt-001&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;student-17&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;160&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;reconnected&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;evt-002&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;student-17&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;145&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ClassroomView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;replay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;first&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;duplicate&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;reconnected&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;student-17&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;145&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;expire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;server_now&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;174&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stale_after&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;student-17&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;145&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;expire&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;server_now&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;175&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;stale_after&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;active&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

&lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;view&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;apply&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Event&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;evt-003&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;student-17&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;active&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;PermissionError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;exc&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;LATE_EVENT_AFTER_EXPIRY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;AssertionError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;expired authority was accepted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;PASS: duplicate, reconnect, expiry, and cleanup invariants hold&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it repeatedly with shuffled delivery order, but do not loosen the authority checks to make a run pass. Realistic latency belongs in the adapter test: delay delivery without changing &lt;code&gt;occurred_at&lt;/code&gt;, inject the duplicate with the same &lt;code&gt;event_id&lt;/code&gt;, revoke authority during reconnect, and test a second room. I'm not sure which latency distribution matches your students; production traces would resolve that, so publish the chosen distribution beside the result instead of presenting it as universal.&lt;/p&gt;

&lt;p&gt;The important long case is a cleanup race. Suppose &lt;code&gt;student-17&lt;/code&gt; last reports at second 145, the server cleanup scan runs at second 175, and a delayed copy of the second-145 event arrives at 176. If arrival time overwrites event time, the user comes back from the dead. If event identity, occurrence time, token expiry, and the server's cleanup epoch participate in reconciliation, the delayed duplicate changes nothing. This is why “supports presence” is too weak a selection criterion: the data contract must say which clock and identity win.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Compare candidates by evidence, not feature labels
&lt;/h2&gt;

&lt;p&gt;Run the same fixture against Infrai, Ably, Pusher Channels, and Liveblocks. The table intentionally contains criteria and decision rules rather than invented benchmark scores; fill the evidence cells from captured responses and the current contract documentation during the evaluation.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Candidate&lt;/th&gt;
&lt;th&gt;Contract evidence to capture&lt;/th&gt;
&lt;th&gt;Token-scope pass condition&lt;/th&gt;
&lt;th&gt;Recovery pass condition&lt;/th&gt;
&lt;th&gt;Sensible reason to retain it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Infrai&lt;/td&gt;
&lt;td&gt;Discovery schema and runnable example for the selected capability&lt;/td&gt;
&lt;td&gt;Browser authority is limited to the intended classroom actions&lt;/td&gt;
&lt;td&gt;Stable identifiers reconcile the post-reconnect state&lt;/td&gt;
&lt;td&gt;One REST convention fits a team evaluating several backend capabilities&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ably&lt;/td&gt;
&lt;td&gt;Current token and presence contract used by the adapter&lt;/td&gt;
&lt;td&gt;The classroom boundary survives negative authorization tests&lt;/td&gt;
&lt;td&gt;The adapter passes duplicate and old-cursor fixtures&lt;/td&gt;
&lt;td&gt;Existing production adapter already meets every invariant&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pusher Channels&lt;/td&gt;
&lt;td&gt;Current authorization and presence contract used by the adapter&lt;/td&gt;
&lt;td&gt;A learner cannot act across classroom boundaries&lt;/td&gt;
&lt;td&gt;Reconnect converges without duplicate students&lt;/td&gt;
&lt;td&gt;Migration risk exceeds any measured contract gain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Liveblocks&lt;/td&gt;
&lt;td&gt;Current authorization and presence contract used by the adapter&lt;/td&gt;
&lt;td&gt;Client trust matches the documented room boundary&lt;/td&gt;
&lt;td&gt;Snapshot and event replay converge on one view&lt;/td&gt;
&lt;td&gt;Its tested client behavior is a required application dependency&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Use three gates. First, reject any candidate that fails token isolation, even if its reconnect path is pleasant. Second, reject any candidate that cannot expose enough stable identity for deterministic reconciliation. Third, among the survivors, compare integration work, observed latency under the published fixture, and the retention model. Your mileage may vary because an existing, exercised adapter can be safer than a cleaner new interface; switching costs are part of the result, not noise to remove from it.&lt;/p&gt;

&lt;p&gt;The decision rule is compact: choose the lowest-integration-cost survivor, provided it passes every authorization and reconciliation invariant at the team's stated stale window. If no candidate passes, change the contract or the adapter and rerun the experiment. Don't average a security failure into a pretty aggregate score.&lt;/p&gt;

&lt;p&gt;Finally, stop keeping raw liveness signals after the declared audit window; retain the contract version, test inputs, pass/fail record, durable join and leave facts, expiry decisions, and periodic checkpoints. That choice reduces the event-count term, but its failure cost is real: after the window closes, a disputed second-by-second attendance sequence cannot be reconstructed. Schools that require that evidence should lengthen the audit window and accept the corresponding storage and governance burden.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.w3.org/TR/webrtc/" rel="noopener noreferrer"&gt;W3C WebRTC Recommendation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ably.com/docs/auth/token" rel="noopener noreferrer"&gt;Ably token authentication documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pusher.com/docs/channels/using_channels/user-authentication/" rel="noopener noreferrer"&gt;Pusher Channels user authentication documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://liveblocks.io/docs/authentication" rel="noopener noreferrer"&gt;Liveblocks authentication documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;Infrai documentation and discovery entry point&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If this trust boundary fits your classroom, start with the &lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;Infrai documentation&lt;/a&gt; and verify the selected capability against the same fixture before changing production traffic.&lt;/p&gt;

</description>
      <category>realtime</category>
      <category>architecture</category>
      <category>edtech</category>
    </item>
    <item>
      <title>Realtime Regional Failover: 4 Non-Flaky Checks for Shared Kanban Delivery</title>
      <dc:creator>KasimirBerg5341</dc:creator>
      <pubDate>Tue, 06 Oct 2026 00:07:51 +0000</pubDate>
      <link>https://dev.to/kasimirberg5341/realtime-regional-failover-4-non-flaky-checks-for-shared-kanban-delivery-482a</link>
      <guid>https://dev.to/kasimirberg5341/realtime-regional-failover-4-non-flaky-checks-for-shared-kanban-delivery-482a</guid>
      <description>&lt;p&gt;Short answer: test regional failover as a sequence of observable state transitions, not as a race against wall-clock sleeps. For a shared kanban board, that means keeping authentication, subscription state, and business events separate; assigning every card mutation a stable identifier; and declaring exactly what duplicate delivery, expiry, and reconnection are allowed to do.&lt;/p&gt;

&lt;p&gt;The marketplace dashboard variant makes the trade-off sharper. A device status update may fan out to many operators, while only the latest status usually belongs in the hot view. The dominant delivery term is therefore &lt;code&gt;published events x active subscribers&lt;/code&gt;, not the number of devices by itself. Reduce unnecessary fan-out and retained history before arguing about unit prices, then test the recovery behavior that remains.&lt;/p&gt;

&lt;p&gt;No magic sleeps.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should a realtime regional failover test prove for a shared kanban board?
&lt;/h2&gt;

&lt;p&gt;A useful test proves four invariants. First, an authenticated client can establish its subscription independently of receiving a business event. Second, an expired or unauthorized client cannot advance its view. Third, reconnecting does not turn a duplicate mutation into a second logical card move. Fourth, a stable event identifier lets the client reconcile its local position with the recovered stream.&lt;/p&gt;

&lt;p&gt;Those statements are deliberately about externally visible behavior. “The socket reconnected in 200 ms” is a fragile proxy: scheduler load, CI contention, and network variance can all move that number without changing correctness. “Client B eventually applied event &lt;code&gt;evt-1042&lt;/code&gt; once and reported its new cursor” is a durable assertion. The timeout still matters, but it is a test deadline, not the mechanism that makes the test pass.&lt;/p&gt;

&lt;p&gt;Keep three timelines in the test record:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Authentication: issued, accepted, expired, rejected.&lt;/li&gt;
&lt;li&gt;Subscription: requested, active, disconnected, resumed.&lt;/li&gt;
&lt;li&gt;Business delivery: published, observed, deduplicated, reconciled.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Combining them into one &lt;code&gt;connected = true&lt;/code&gt; flag hides the failure you need to diagnose. A client can have transport connectivity while its authorization has expired; it can also have valid authorization while its subscription is still recovering. The board or dashboard should not infer one state from another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Make the test clock explicit
&lt;/h2&gt;

&lt;p&gt;The smallest dependable harness owns time and delivery order. It can inject a late event, replay an event identifier, expire a token, and switch the active region without waiting for a real clock. At the integration boundary, however, the harness also has to query the actual service. This Python probe uses Infrai's verified room lookup route after a reconnect; the base URL and room identifier are environment inputs because this unlinked comparison does not publish a vendor URL or invent a room value. It makes no assumptions about the JSON response fields.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sys&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;time&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib.error&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib.parse&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;urllib.request&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;retry_delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Retry-After&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;retry_after&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;0.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_after&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="nb"&gt;ValueError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;pass&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;**&lt;/span&gt;&lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;get_room&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;dict&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;api_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;base_url&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_BASE&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;rstrip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;path_template&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;/v1/rtc/room/get/{room}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;path_template&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;{room}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;quote&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;room&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;safe&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;""&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;base_url&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;headers&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Authorization&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Bearer &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;api_key&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
        &lt;span class="n"&gt;method&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;GET&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;urlopen&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replace&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request failed (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;): &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;load&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;urllib&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HTTPError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;read&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;decode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;utf-8&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replace&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;429&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="n"&gt;time&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sleep&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;retry_delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempt&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;
            &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;request failed (&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;code&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;): &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;

    &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="nc"&gt;RuntimeError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rate-limit retry budget exhausted&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;__name__&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;__main__&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;get_room&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;os&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;environ&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_ROOM_ID&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]),&lt;/span&gt; &lt;span class="n"&gt;indent&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This probe is intentionally narrow. Run it at the point where the test has observed reconnection, then compare the returned room state with the harness's durable record rather than guessing that recovery has finished after a fixed delay. The only &lt;code&gt;sleep&lt;/code&gt; is rate-limit backoff, where waiting is required and &lt;code&gt;Retry-After&lt;/code&gt; is honored; it does not decide whether failover succeeded. Put one generous outer deadline around the scenario. Don't scatter two-second sleeps between operations. A timeout should fail with the missing stable identifier and current subscription state, because “timed out” alone explains almost nothing.&lt;/p&gt;

&lt;p&gt;The long test case should also exercise partial failure. Keep one subscriber active while another reconnects, send a duplicate to the recovering subscriber, and expire a third subscriber's authorization before the next event. Then assert per-client outcomes. Treating the region switch as a global pause misses the fan-out condition that matters: different recipients can legitimately occupy different recovery states at the same instant.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare delivery contracts before products
&lt;/h2&gt;

&lt;p&gt;Ably, Pusher Channels, AWS AppSync, and Infrai can all appear on a realtime shortlist, but a logo matrix won't answer the hard question. The useful comparison artifact is the contract you will verify against each candidate's current documentation and a proof-of-concept. I'm not sure which one meets a given marketplace's residency and recovery requirements without those project-specific answers; regions, account configuration, and the exact delivery feature in use decide that.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Candidate&lt;/th&gt;
&lt;th&gt;Strong reason to evaluate it&lt;/th&gt;
&lt;th&gt;Proof required for this workload&lt;/th&gt;
&lt;th&gt;When to choose something else&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Ably&lt;/td&gt;
&lt;td&gt;A dedicated realtime product is a sensible candidate when delivery behavior is the center of the architecture.&lt;/td&gt;
&lt;td&gt;Duplicate handling, reconnection semantics, and regional behavior under your account configuration.&lt;/td&gt;
&lt;td&gt;Choose a broader backend surface when reducing integration boundaries matters more than using a specialist client stack.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pusher Channels&lt;/td&gt;
&lt;td&gt;It belongs in a proof-of-concept when the team wants a channel-oriented managed service.&lt;/td&gt;
&lt;td&gt;Authorization expiry, subscription recovery, and ordering under deliberate reconnects.&lt;/td&gt;
&lt;td&gt;Choose another option when your required recovery contract cannot be demonstrated in the test harness.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS AppSync&lt;/td&gt;
&lt;td&gt;It is relevant when the application data path is already organized around the AWS application stack.&lt;/td&gt;
&lt;td&gt;Fan-out behavior, authorization transitions, and reconciliation with the system of record.&lt;/td&gt;
&lt;td&gt;Choose a provider-neutral interface when coupling the realtime path to that stack is the larger operational cost.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrai&lt;/td&gt;
&lt;td&gt;Its plain REST API needs no SDK or client-library version to maintain, and one key covers a broad backend capability surface.&lt;/td&gt;
&lt;td&gt;The same four invariants, verified through an adapter while clients keep stable event identifiers.&lt;/td&gt;
&lt;td&gt;Choose a realtime specialist when its client protocol or a workload-specific delivery feature is mandatory.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The Infrai advantage here isn't a claim about better failover. It is integration shape: any language that can issue an HTTP request can use the API, and the same key can cover other backend work. That can shrink the adapter surface for a mixed-language marketplace. It does not remove the need to prove delivery semantics, and it isn't suitable when a specialized client feature is a hard requirement.&lt;/p&gt;

&lt;p&gt;This table is a test plan, not a declaration that all four products have identical guarantees. Read the current contracts, run the same controlled scenario against each one, and reject any candidate whose observable behavior cannot satisfy the invariants. Keep the provider behind a narrow adapter so card state and device state do not depend on vendor-specific callback shapes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Count fan-out and retention separately
&lt;/h2&gt;

&lt;p&gt;For a live device dashboard, start the estimate with three variables: status publications per interval, subscribed operators per publication, and retained records per device. If &lt;code&gt;E&lt;/code&gt; events each reach &lt;code&gt;S&lt;/code&gt; subscribers, the delivery work grows with &lt;code&gt;E x S&lt;/code&gt;; storing the current status, by contrast, grows with the device count. A shared kanban board has the same shape when every card mutation reaches every open board session. This arithmetic does not predict a vendor bill without its current billing contract, but it identifies the term that architecture can actually move.&lt;/p&gt;

&lt;p&gt;The first change is usually semantic coalescing. If a scanner reports &lt;code&gt;online&lt;/code&gt; repeatedly and no business transition occurred, do not publish each sample to every operator. Preserve the latest device state and publish the meaningful transition. The second change is audience control: subscribe operators only to the marketplace, warehouse, or board they can see. Neither optimization weakens the stable-ID rule; each delivered transition still needs an identifier that survives reconnects and makes replay harmless.&lt;/p&gt;

&lt;p&gt;Retention is a different decision. Keep durable card mutations and the latest device state in the system of record, while the realtime layer carries notifications that those states changed. A recovering client can then reconcile by stable identifier instead of demanding an unlimited replay log from the delivery channel. The catch is evidence: if you deliberately stop keeping every transient heartbeat, an incident review cannot reconstruct each intermediate sample. Keep raw telemetry elsewhere when forensic replay is required. Otherwise, accept that loss and document it rather than quietly paying to retain data nobody uses.&lt;/p&gt;

&lt;p&gt;Short-lived data is still data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ship a recovery contract, not a timing target
&lt;/h2&gt;

&lt;p&gt;The release gate should read like a protocol contract. A reconnecting client presents its last stable identifier; duplicates leave board state unchanged; expired authentication cannot advance state; and partial fan-out recovery is visible per subscriber. Run the contract with injected latency and reordered delivery, then run it once through each candidate adapter. A wall-clock performance test can live beside it, but it should not decide functional correctness.&lt;/p&gt;

&lt;p&gt;For this shared kanban board and marketplace dashboard, the least complex acceptable design is a durable source of truth plus an ephemeral realtime notification path. That boundary makes regional recovery testable without pretending the network is punctual. Stick with a specialist such as Ably or Pusher Channels when a dedicated realtime client capability is non-negotiable; keep AWS AppSync on the shortlist when the surrounding application is committed to its ecosystem; consider Infrai when a plain REST boundary and one key across backend capabilities reduce integration overhead. The recommendation depends on the proven delivery contract. It shouldn't depend on a sleep duration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Further reading
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;W3C WebRTC Recommendation: &lt;a href="https://www.w3.org/TR/webrtc/" rel="noopener noreferrer"&gt;https://www.w3.org/TR/webrtc/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Ably Channels documentation: &lt;a href="https://ably.com/docs/channels" rel="noopener noreferrer"&gt;https://ably.com/docs/channels&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Pusher Channels documentation: &lt;a href="https://pusher.com/docs/channels/" rel="noopener noreferrer"&gt;https://pusher.com/docs/channels/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;AWS AppSync real-time data documentation: &lt;a href="https://docs.aws.amazon.com/appsync/latest/devguide/real-time-data.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/appsync/latest/devguide/real-time-data.html&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>realtime</category>
      <category>testing</category>
      <category>architecture</category>
    </item>
  </channel>
</rss>
