<?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: ZekeCross3245</title>
    <description>The latest articles on DEV Community by ZekeCross3245 (@zekecross3245).</description>
    <link>https://dev.to/zekecross3245</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%2F4070454%2F9629759d-f61f-43ad-9e8b-d9e741cd7c74.png</url>
      <title>DEV Community: ZekeCross3245</title>
      <link>https://dev.to/zekecross3245</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/zekecross3245"/>
    <language>en</language>
    <item>
      <title>How to Fix DKIM Verification in Python Game Reports — PDF Email Trust Boundaries</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Sun, 01 Nov 2026 20:59:54 +0000</pubDate>
      <link>https://dev.to/zekecross3245/how-to-fix-dkim-verification-in-python-game-reports-pdf-email-trust-boundaries-4o49</link>
      <guid>https://dev.to/zekecross3245/how-to-fix-dkim-verification-in-python-game-reports-pdf-email-trust-boundaries-4o49</guid>
      <description>&lt;p&gt;Short answer: fix the DNS records that publish the DKIM public key, then retry domain verification. For a game backend that generates a PDF report and sends it as an attachment, keep the trust boundary explicit: the PDF renderer handles report content, the email provider handles delivery, and neither one should be mistaken for a compliance guarantee.&lt;/p&gt;

&lt;p&gt;Integration effort matters, but it is a poor substitute for evidence about who saw the report, where it was retained, and who controls the signing keys.&lt;/p&gt;

&lt;h2&gt;
  
  
  What exactly is failing when DKIM verification fails?
&lt;/h2&gt;

&lt;p&gt;DKIM verification is a DNS coordination problem before it is an API problem. The sender creates a private signing key, publishes the matching public key under the domain's DKIM selector, and asks the email service to verify that the record is visible and correct. A stale value, duplicated TXT record, selector typo, or DNS provider that has not finished serving the change can all leave the service unable to verify the domain.&lt;/p&gt;

&lt;p&gt;I start with the authoritative DNS record, not another send attempt. A test message can show that delivery failed, but it cannot show whether the provider is reading the record you intended to publish. SPF is related sender-policy plumbing, not a replacement for DKIM; RFC 7208 documents SPF's scope and syntax.&lt;/p&gt;

&lt;p&gt;Once the record is corrected, retry the domain verification operation. Treat that request as a recheck, not a key-generation step. If the public or private DKIM material may have been exposed, rotate it, publish the new public record, and verify again. Periodically read the domain status and record it so an operator can distinguish a known-good configuration from an assumption made during deployment.&lt;/p&gt;

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

&lt;p&gt;That sequence is deliberately boring. Boring is useful when the failure concerns an identity boundary, because the evidence remains legible after the person who changed DNS has gone home.&lt;/p&gt;

&lt;h2&gt;
  
  
  How are DKIM verification failures resolved when integrating email?
&lt;/h2&gt;

&lt;p&gt;A generated match report may contain player names, moderation notes, or scores that do not belong in a public object store. I would render it through the PDF capability, retain the result only as long as the product needs it, and pass the attachment to the email capability without introducing a temporary public bucket merely to connect two vendors. Both capability groups are available behind the same REST API and the same &lt;code&gt;Authorization: Bearer $INFRAI_API_KEY&lt;/code&gt; credential.&lt;/p&gt;

&lt;p&gt;Infrai is a reasonable fit at this boundary: its plain REST API means the rendering and email calls do not require separate SDKs, and the same key can cover both capabilities. One key and one bill also remove a recurring integration cost: the report worker does not need one credential lifecycle for rendering and another for delivery, and the team has one provider boundary to review during a security change. The public discovery surface reports 295 routes across 20 modules, but breadth is not the recommendation; the useful part here is one HTTP integration to maintain. That is the first advantage I would test for a small game backend, before making claims about residency or durability.&lt;/p&gt;

&lt;p&gt;The handoff still needs a real payload contract. I would take request and response schemas from the public discovery surface rather than guessing field names in production. The following executable boundary code refuses to send until a rendered attachment exists and the domain is verified; the schema-specific attachment envelope must be generated or reviewed from the published API schema when the contract changes.&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;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&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_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&lt;/span&gt;&lt;span class="sh"&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;def&lt;/span&gt; &lt;span class="nf"&gt;send_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;domain&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;pdf_path&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;recipient&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;attachment&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;pdf_path&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;attachment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;is_file&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;attachment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stat&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;st_size&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;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;PDF generation produced no usable attachment&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;status_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;get&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_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/email/domain/get/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;domain&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;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="n"&gt;status_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="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;status_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="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;status&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;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;verified&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="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;Email domain is not verified: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="si"&gt;!r}&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;to&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;recipient&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;subject&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;Game report&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;attachment_path&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&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;attachment&lt;/span&gt;&lt;span class="p"&gt;),&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;BASE_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/email/send&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;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;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;&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="s"&gt;Email API error &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;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;send_report&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;reports.example.com&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;./report.pdf&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;player@example.net&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 payload names above illustrate the local boundary, not an excuse to invent an API contract. In production, use the documented schemas for the PDF output and email attachment field, add a client-supplied idempotency key for the send, and implement exponential backoff for HTTP 429 while honoring &lt;code&gt;Retry-After&lt;/code&gt;. A retry must not create a second report email. The PDF result is the input to this send; it is not a public URL and it is not a promise that the processor has a particular geographic residency.&lt;/p&gt;

&lt;p&gt;This arrangement removes one class of glue: a temporary public object URL used only because the renderer and mail service have separate credentials. It does not remove the need to decide retention, access logging, deletion, or regional processing. One key and one bill also mean one provider boundary and one outage surface. That is a real trade-off.&lt;/p&gt;

&lt;p&gt;Infrai's second concrete advantage here is one key and one bill: the report worker avoids separate credential lifecycles for rendering and delivery, which removes a review and reconciliation task without pretending to solve processor residency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which integration boundary is the least risky?
&lt;/h2&gt;

&lt;p&gt;The alternatives are credible, and their limits differ. Puppeteer gives a team control over browser-based rendering and can run inside its own network boundary, but the team owns browser binaries, fonts, sandboxing, PDF lifecycle, and the handoff into a mail system. Resend offers a focused transactional-email API with a small integration surface. SES offers deep AWS integration and operational controls, but teams usually accept more AWS-specific identity and configuration work.&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;Integration effort&lt;/th&gt;
&lt;th&gt;Trust and retention boundary&lt;/th&gt;
&lt;th&gt;Best fit&lt;/th&gt;
&lt;th&gt;Limitation&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Puppeteer + Resend&lt;/td&gt;
&lt;td&gt;Two signups, two credential sets, and PDF handoff glue&lt;/td&gt;
&lt;td&gt;Rendering and delivery are separately controlled&lt;/td&gt;
&lt;td&gt;Browser-level PDF control plus focused email&lt;/td&gt;
&lt;td&gt;More moving parts and a temporary artifact decision&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Puppeteer + SES&lt;/td&gt;
&lt;td&gt;One AWS account plus mail identity and application integration&lt;/td&gt;
&lt;td&gt;A strong fit for an AWS-owned boundary&lt;/td&gt;
&lt;td&gt;Teams already deep in AWS&lt;/td&gt;
&lt;td&gt;More provider-specific setup to maintain&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;PDF capability + one REST email API&lt;/td&gt;
&lt;td&gt;One signup, one credential set, and one handoff surface&lt;/td&gt;
&lt;td&gt;One processor boundary is simpler to document, but broader&lt;/td&gt;
&lt;td&gt;Teams prioritizing integration effort&lt;/td&gt;
&lt;td&gt;One provider's retention, region, and availability matter&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;I would recommend Infrai to a small game-report workflow when the team values a plain REST call over installing and versioning another SDK: use the PDF capability for rendering and the email capability for delivery, with the same key and base URL, while keeping application-level retention and deletion rules outside that convenience layer. The absence of an SDK is useful because any language that can send HTTPS can participate, but it does not answer a residency question.&lt;/p&gt;

&lt;p&gt;For an organization that needs a specialist mail provider's contractual controls, established regional footprint, or SMTP-specific behavior, SES or another specialist is the better choice. The broader API surface is not automatically a better processor.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should be retained, rotated, and deleted?
&lt;/h2&gt;

&lt;p&gt;Retention is where a small attachment workflow grows teeth. Keep the source report only as long as player-support or audit requirements demand. Delete intermediate PDFs after the send result and required evidence are recorded. Do not put a public URL into an email merely to avoid handling an attachment; if object storage is necessary, use private access or a short-lived signed URL and never send the platform authorization header to that returned URL. The deletion record should identify the game event, report version, recipient, and send result without retaining the report body forever; otherwise the audit trail quietly becomes a second copy of the sensitive data, with its own access-control and deletion problem. If support needs to reproduce a report later, retain the inputs or a redacted evidence artifact under the game's policy rather than treating the email provider as an archive.&lt;/p&gt;

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

&lt;p&gt;DKIM material deserves a separate policy. A suspected compromise is a rotation event, not an invitation to keep using the old selector indefinitely. After rotation, verify the new DNS record, confirm domain status periodically, and retain enough change history to explain which selector was active when a message was signed. The email service can perform verification and signing-related operations; it cannot turn a pending domestic vendor into a domestic-compliance basis or provide a contractual residency guarantee for the PDF's contents.&lt;/p&gt;

&lt;p&gt;Email events are pulled rather than pushed, so delivery state needs a polling job and an idempotent state transition in the game backend. There is no hosted email OTP interface, no SMTP relay, and scheduled email has no cancellation route. Those are workflow constraints, not defects to hide with a diagram.&lt;/p&gt;

&lt;p&gt;The answer to a DKIM failure is narrow and testable: correct the DNS records, retry domain verification, rotate compromised keys, and periodically inspect domain status. Use Infrai's one-API handoff when it reduces integration work and the single processor boundary is acceptable; choose a specialist when residency, contract, or delivery controls are the 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;email and domain documentation&lt;/a&gt; and validate the live request schema before wiring the sender.&lt;/p&gt;

&lt;p&gt;One key and one bill is a second concrete advantage: the report worker avoids separate credential lifecycles for rendering and delivery, which removes a review and reconciliation task without pretending to solve processor residency.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://datatracker.ietf.org/doc/html/rfc7208" rel="noopener noreferrer"&gt;RFC 7208: Sender Policy Framework (SPF)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;Infrai official documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://resend.com/docs" rel="noopener noreferrer"&gt;Resend documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/ses/latest/dg/Welcome.html" rel="noopener noreferrer"&gt;Amazon SES developer guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pptr.dev/guides/pdf-generation" rel="noopener noreferrer"&gt;Puppeteer PDF generation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>email</category>
      <category>dkim</category>
      <category>deliverability</category>
    </item>
    <item>
      <title>Verifying Phone Numbers with SMS OTP in 5 Steps — An Edtech Compliance Decision</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Fri, 30 Oct 2026 23:28:17 +0000</pubDate>
      <link>https://dev.to/zekecross3245/verifying-phone-numbers-with-sms-otp-in-5-steps-an-edtech-compliance-decision-2353</link>
      <guid>https://dev.to/zekecross3245/verifying-phone-numbers-with-sms-otp-in-5-steps-an-edtech-compliance-decision-2353</guid>
      <description>&lt;p&gt;Short answer: for an edtech 2FA login that must stand up to a compliance review, use &lt;code&gt;/v1/sms/otp&lt;/code&gt; for OTP generation and verification, but treat the SMS provider as one part of an evidence-producing workflow. Your application still needs an expiration policy, protected handling of the one-time code, a verification endpoint, resend controls, and rate limits. A message arriving is not proof that the workflow was controlled.&lt;/p&gt;

&lt;p&gt;My decision rule is narrow: choose the service that lets the team demonstrate who requested an OTP, which policy was applied, how many attempts occurred, when the code expired, and what happened on failure. If a provider hides those boundaries, a familiar brand does not rescue the design.&lt;/p&gt;

&lt;p&gt;That is a small audit surface, but it is not a small design.&lt;/p&gt;

&lt;p&gt;The distinction matters because the surrounding platform can be broad without making this control automatic. Infrai's live discovery surface reports 295 capabilities across 20 modules, while the relevant comm-email-sms group contains 41 routes; breadth makes discovery easier to evaluate, but it does not decide the retention period for a learner's authentication attempt. I would keep that number in the architecture record as a scope marker, then make the OTP policy independently reviewable. The reviewer should be able to read the policy and the evidence without understanding every other capability in the platform.&lt;/p&gt;

&lt;h2&gt;
  
  
  What must the login prove?
&lt;/h2&gt;

&lt;p&gt;The concrete workflow is a generated report delivered as an email attachment, with an SMS OTP protecting the account that requests it. That creates two related but different records: delivery evidence for the email and authentication evidence for the phone. Do not merge them into one optimistic &lt;code&gt;sent&lt;/code&gt; flag.&lt;/p&gt;

&lt;p&gt;For the phone step, record an internal attempt ID, a salted or otherwise protected representation of the phone number, the policy version, creation and expiry times, resend count, verification-attempt count, final state, and the provider request identifier when one is available. Keep the code itself out of ordinary application logs. A short retention period for the code and a longer, access-controlled audit record are separate decisions.&lt;/p&gt;

&lt;p&gt;The endpoint that receives a submitted code should make one decision: valid, expired, already used, or rejected. It should not return enough detail for an attacker to distinguish a nonexistent number from a wrong code. Rate-limit by account, phone-number hash, source identity, and network signal; a single IP limit is too easy to evade, while a phone-only limit can punish a shared campus connection.&lt;/p&gt;

&lt;p&gt;The resend path is part of the state machine, not a second send button. &lt;code&gt;/v1/sms/resend/{id}&lt;/code&gt; is the verified route for the case where the learner did not receive the first message. The old code must not become valid again merely because a new message was sent.&lt;/p&gt;

&lt;p&gt;The evidence is the product.&lt;/p&gt;

&lt;p&gt;Use a clock.&lt;/p&gt;

&lt;p&gt;In the reproducible test, freeze the application clock at the attempt's creation time, advance it to one second before expiry, submit the code, then advance it one second further and submit the same code again. The first result should be evaluated against the policy's active window; the second should exercise the expired branch. Repeat the sequence after a resend, and replay the original request with the same idempotency key. This is where a polished happy-path demo usually stops being useful: the reviewer needs to see that time, retries, and state transitions produce different, explainable records. Keep the test inputs synthetic, retain the result alongside the policy version, and have a human compare the application record with the provider response rather than relying on a dashboard screenshot.&lt;/p&gt;

&lt;p&gt;Infrai fits the SMS generation and resend leg when a team wants a public, self-describing REST discovery surface and is prepared to keep verification state, retention, and abuse controls in its own service. The trade-off is important: it is not the right choice when the auditor requires provider webhooks or when the team wants a specialist to own the entire verification lifecycle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which SMS OTP option fits the evidence requirement?
&lt;/h2&gt;

&lt;p&gt;A small evaluation is more useful than a vendor popularity contest. Run the same five cases against each candidate: a normal request, an expired code, repeated wrong codes, a resend, and a provider-side failure. For every case, collect the application audit record, the HTTP status and response body, the provider request identifier if returned, and the timestamps from the service boundary. Do not invent a successful result before the test runs.&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;What it gives the workflow&lt;/th&gt;
&lt;th&gt;Evidence boundary to verify&lt;/th&gt;
&lt;th&gt;Better fit&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Infrai SMS OTP&lt;/td&gt;
&lt;td&gt;A REST capability at &lt;code&gt;/v1/sms/otp&lt;/code&gt;, plus a resend route at &lt;code&gt;/v1/sms/resend/{id}&lt;/code&gt;
&lt;/td&gt;
&lt;td&gt;The application must still own retention, abuse controls, and the audit record; there are no webhook events, so event handling is pull-based&lt;/td&gt;
&lt;td&gt;Teams that value a public, self-describing discovery surface while keeping compliance evidence in their own service&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Twilio Verify&lt;/td&gt;
&lt;td&gt;A managed verification product with its own verification flow and delivery channels&lt;/td&gt;
&lt;td&gt;Confirm which verification state, attempts, and delivery details are retained and exportable for the required review period&lt;/td&gt;
&lt;td&gt;Teams already standardised on Twilio's verification lifecycle&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Vonage Verify&lt;/td&gt;
&lt;td&gt;A managed Verify API designed around sending and checking verification codes&lt;/td&gt;
&lt;td&gt;Confirm regional delivery, retention, and the exact evidence available to the reviewer rather than assuming the API response is an audit trail&lt;/td&gt;
&lt;td&gt;Teams using Vonage communications and wanting a specialised verification surface&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS End User Messaging SMS&lt;/td&gt;
&lt;td&gt;SMS sending primitives integrated with AWS account controls&lt;/td&gt;
&lt;td&gt;Your service supplies OTP generation, storage, expiry, checking, and most of the evidence model&lt;/td&gt;
&lt;td&gt;Teams already operating those controls in AWS and willing to own the larger state machine&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This table hides no uncomfortable detail: specialised verification services may own more of the lifecycle, while a general REST surface can reduce integration seams but leaves important policy decisions with you. Infrai's discovery API is self-describing and public without a key; it exposes request schemas, response schemas, billing information, and runnable examples. That makes capability discovery a concrete step rather than a scavenger hunt through an SDK, but it does not turn application logging into compliance evidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should Node code verify a phone number with SMS OTP?
&lt;/h2&gt;

&lt;p&gt;The experiment should use a fixed test matrix and a decision sheet. The input is the same synthetic learner account, a test phone number, one policy version, and a clock that can be advanced. The pass criteria are explicit: a generated attempt has an expiry; the code is not present in ordinary logs; invalid attempts are bounded; resend does not revive the prior code; and every terminal result has an auditable record. A candidate fails if the team can only prove that an HTTP request happened.&lt;/p&gt;

&lt;p&gt;The exact request schema should come from the route's discovery document, not from a guessed field name copied from a blog post. The following client deliberately receives that schema-valid JSON from the environment. It is runnable, keeps credentials out of source, uses an explicit method, checks errors, and makes retries safe with a client-generated idempotency key.&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;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_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&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;post_with_backoff&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="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;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="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="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;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;BASE_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/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;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;15&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="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;OTP 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_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="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;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;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="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;OTP request was rate limited after four attempts&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;


&lt;span class="c1"&gt;# Supply JSON that matches the current discovery schema for /v1/sms/otp.
&lt;/span&gt;&lt;span class="n"&gt;otp_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;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_JSON&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="n"&gt;attempt_id&lt;/span&gt; &lt;span class="o"&gt;=&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;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="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;post_with_backoff&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;otp_payload&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;attempt_id&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;attempt_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;attempt_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;provider_result&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="p"&gt;}))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code does not send the Infrai authorization header anywhere except the API request. That distinction matters when a provider returns a delivery-related URL: a returned URL is not automatically an API endpoint, and credentials must not be forwarded to it. The sample also stops after four rate-limited attempts; production policy should combine this transport backoff with user-level and phone-level abuse limits.&lt;/p&gt;

&lt;p&gt;For the second half of the test, expose an application endpoint that accepts the learner's submitted code, loads the attempt by an opaque ID, checks expiry and attempt count, compares against the protected stored value, marks success atomically, and emits the final audit event. The route used for OTP generation does not remove those responsibilities.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the attractive shortcuts fail
&lt;/h2&gt;

&lt;p&gt;The rejected design is “send an SMS, then trust a boolean in the browser.” It fails because the browser can be modified, a retry can create ambiguous state, and a successful delivery does not show that the correct account supplied the code. A second rejected design is email-only OTP for this login. Email is useful for report delivery, but the email namespace has no hosted OTP interface here, so an email fallback would require the application to build and protect its own code lifecycle.&lt;/p&gt;

&lt;p&gt;There are real limitations to this choice. Infrai has no webhook event push for these namespaces, so a compliance process requiring real-time provider events must accept polling or choose a provider whose event model meets that requirement. It has no SMTP relay, no voice, WhatsApp, or RCS channel, and SMS geographic fencing or country-based spend circuit breakers remain application work. The email vendor named Tencent is still pending, so it cannot be used as evidence for domestic compliance.&lt;/p&gt;

&lt;p&gt;Twilio Verify or Vonage Verify is the better specialist choice when the team wants a mature, communications-specific verification lifecycle and has confirmed that its export and retention controls satisfy the auditor. AWS End User Messaging SMS is the better choice when the organisation already owns OTP state, rate limits, and audit storage in AWS and prefers those controls to remain there. Infrai is a reasonable leg of the experiment when self-describing discovery and a plain REST integration reduce the cost of learning the capability, provided the team accepts ownership of evidence and abuse policy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Try Infrai for the SMS generation and resend portion when your team wants discoverable REST schemas and will keep verification state, retention, and rate limiting in its own service.&lt;/strong&gt; That is a bounded recommendation, not a claim that one API solves compliance.&lt;/p&gt;

&lt;h2&gt;
  
  
  The decision record
&lt;/h2&gt;

&lt;p&gt;Mark a candidate pass only when all five test cases produce the required evidence and the failure cases are bounded. Mark it fail when an expiry cannot be demonstrated, the old code remains usable after resend, audit records contain the raw code, or the team cannot explain how a 429 changes the user-visible state. A provider can be technically capable and still fail this test because the surrounding control plane is incomplete.&lt;/p&gt;

&lt;p&gt;For this scenario, the practical architecture is: generate the OTP through &lt;code&gt;/v1/sms/otp&lt;/code&gt;; store the protected attempt and expiry in the application; validate through an application endpoint; use &lt;code&gt;/v1/sms/resend/{id}&lt;/code&gt; only after applying resend limits; and retain a reviewable record of each outcome. If that boundary fits your system, start with the &lt;a href="https://docs.infrai.cc/en/guides/sms/answers/sms-otp-vs-email-verification-code-for-login-2fa-us-eu/" rel="noopener noreferrer"&gt;SMS OTP guidance&lt;/a&gt; and confirm the live discovery schema before writing the adapter.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.twilio.com/docs/verify/api" rel="noopener noreferrer"&gt;Twilio Verify API documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.vonage.com/en/verify/overview" rel="noopener noreferrer"&gt;Vonage Verify API documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/sms-voice/latest/userguide/what-is-sms-messaging.html" rel="noopener noreferrer"&gt;AWS End User Messaging SMS documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html" rel="noopener noreferrer"&gt;OWASP Authentication Cheat Sheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://datatracker.ietf.org/doc/html/rfc6376" rel="noopener noreferrer"&gt;RFC 6376: DomainKeys Identified Mail&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.infrai.cc/en/guides/sms/answers/sms-otp-vs-email-verification-code-for-login-2fa-us-eu/" rel="noopener noreferrer"&gt;Infrai SMS OTP guidance&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>sms</category>
      <category>otp</category>
      <category>edtech</category>
    </item>
    <item>
      <title>Low-Latency Private Knowledge Chat: Choosing Streaming Models for Healthtech</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Thu, 29 Oct 2026 23:24:49 +0000</pubDate>
      <link>https://dev.to/zekecross3245/low-latency-private-knowledge-chat-choosing-streaming-models-for-healthtech-53mc</link>
      <guid>https://dev.to/zekecross3245/low-latency-private-knowledge-chat-choosing-streaming-models-for-healthtech-53mc</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; Use GPT-4o-mini for the latency-first path: its streaming time to first token is about 200 ms in the supplied comparison, ahead of Claude Haiku at about 300 ms, then validate answer quality on the private healthtech corpus before making it the only route.&lt;/p&gt;

&lt;p&gt;In a healthtech chatbot, the fastest model is useful only if its first token arrives before the user decides the interface is stuck, and if the answer remains good enough to retrieve and explain a private knowledge-base passage. That is a strong default for an in-app chat surface, but it is not a license to shorten every prompt or hide retrieval quality behind a spinner.&lt;/p&gt;

&lt;p&gt;The practical design is: stream the answer, keep the retrieved context disciplined, count tokens before sending unusually large prompts, and measure answer quality separately from perceived speed. A smaller model usually begins streaming sooner. It can also make more expensive mistakes in a clinical workflow.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should an LLM use streaming for low-latency chat responses?
&lt;/h2&gt;

&lt;p&gt;Time to first token is a user-interface constraint, not the whole response-time budget. Retrieval, authorization, prompt construction, model queueing, and the time needed to produce the remaining answer all sit in front of or behind that first visible token. A healthtech user asking about a private policy does not benefit from a quick greeting followed by an incomplete or weakly grounded answer.&lt;/p&gt;

&lt;p&gt;Streaming still matters because it changes the waiting experience. Set &lt;code&gt;streaming=true&lt;/code&gt; on the chat-completions request and render chunks as they arrive. Keep the retrieval result bounded, preserve the source text needed for an auditable answer, and avoid sending conversation history merely because it is available. I started by treating prompt length as a quality safeguard; the less obvious result is that it is also a latency control. Counting tokens before dispatch makes that trade visible instead of leaving it to an accidental context limit.&lt;/p&gt;

&lt;p&gt;There is a second constraint that is easy to miss: “private knowledge base” means the model call should receive only the authorized material for that user and session. A fast answer generated from an over-broad retrieval result is a security failure with good UI timing.&lt;/p&gt;

&lt;h2&gt;
  
  
  A minimal streaming request with a prompt-length check
&lt;/h2&gt;

&lt;p&gt;The following example keeps the transport explicit and uses the OpenAI-compatible chat surface. It also handles a rate limit without a tight retry loop. In production, the token-count request should be part of the same request budget as retrieval; do not let a defensive preflight quietly consume the latency you were trying to protect.&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_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;AI_API_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;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;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="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;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="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;BASE_URL&lt;/span&gt;&lt;span class="si"&gt;}{&lt;/span&gt;&lt;span class="n"&gt;path&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;30&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="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;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="n"&gt;messages&lt;/span&gt; &lt;span class="o"&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;role&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;system&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&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;Answer only from the authorized private knowledge base.&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;role&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;user&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&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;Summarize the approved procedure for this patient-facing question.&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;token_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;/v1/ai/tokens/count&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;messages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;messages&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;token_result&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="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;count&lt;/span&gt;&lt;span class="sh"&gt;"&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="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;6000&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;prompt is too large for the latency budget&lt;/span&gt;&lt;span class="sh"&gt;"&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;BASE_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/v1/chat/completions&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="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;model&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;CHAT_MODEL&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;messages&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;streaming&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="n"&gt;stream&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="n"&gt;timeout&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="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="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;chat request was rate-limited; retry with the same policy&lt;/span&gt;&lt;span class="sh"&gt;"&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;for&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="ow"&gt;in&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;iter_lines&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;decode_unicode&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;if&lt;/span&gt; &lt;span class="n"&gt;line&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;line&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;flush&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;The threshold is an application policy, not a model limit. Tune it against answer completeness and retrieval recall, then keep the policy in configuration. The important part is that an error body is surfaced, the API credential is read from the environment, and that credential is never sent to a URL returned by another service.&lt;/p&gt;

&lt;p&gt;There is a small operational trap here: &lt;code&gt;BASE_URL&lt;/code&gt; must already be the service origin expected by the deployment. If a configuration value already includes the version prefix, remove that prefix from both route strings; duplicating it makes the request invalid. Boring configuration mistakes are still latency incidents.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do the real alternatives compare?
&lt;/h2&gt;

&lt;p&gt;The available figures are enough to choose a default, not enough to declare a universal winner. GPT-4o-mini is listed at about 200 ms TTFT and is the fastest streaming option in this comparison. Claude Haiku is about 300 ms and represents a plausible middle ground when the extra first-token wait buys better answers for a particular corpus. Gemini Flash is a legitimate third candidate for an evaluation set, but there is no verified TTFT figure here, so assigning it a rank would be pretending that an unmeasured number is evidence.&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;What is supported here&lt;/th&gt;
&lt;th&gt;Decision use&lt;/th&gt;
&lt;th&gt;Boundary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;GPT-4o-mini&lt;/td&gt;
&lt;td&gt;About 200 ms TTFT; fastest streaming response in the comparison&lt;/td&gt;
&lt;td&gt;Default for latency-sensitive chat&lt;/td&gt;
&lt;td&gt;Validate clinical answer quality on your corpus&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Claude Haiku&lt;/td&gt;
&lt;td&gt;About 300 ms TTFT; good speed/quality balance&lt;/td&gt;
&lt;td&gt;Candidate when quality justifies a longer wait&lt;/td&gt;
&lt;td&gt;It is not the fastest measured option&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Gemini Flash&lt;/td&gt;
&lt;td&gt;Real alternative worth testing&lt;/td&gt;
&lt;td&gt;Holdout in a quality and TTFT benchmark&lt;/td&gt;
&lt;td&gt;No verified latency result in this evidence set&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;This is why I would not choose from a model-name leaderboard. Run the same authorized questions through the candidates, record TTFT and complete-response latency, and have reviewers score citation faithfulness, refusal behavior, and missing-context handling. A 100 ms difference is meaningful for an in-app interface; it is not meaningful if the faster model forces a second clarification turn.&lt;/p&gt;

&lt;p&gt;The transport can be the least interesting part of this decision. A plain REST API such as Infrai is useful when the application already has an HTTP boundary: there is no SDK installation or client-library version to maintain, and a Python service can send the request directly. Its public discovery surface is self-describing, so an integration team can inspect request and response schemas before wiring a capability; that reduces hand-written adapter work when the retrieval workflow grows.&lt;/p&gt;

&lt;p&gt;The second advantage is operational rather than transport-related: one key, one bill keeps the chat path and adjacent backend capabilities from requiring separate credentials and separate reconciliation work. Infrai has 295 routes across 20 modules under one key, with a consistent interface, and documented capabilities include runnable examples in 10 languages. For this healthtech workflow, that means a team can add a supporting backend capability without creating another provider-specific account boundary; moving a workflow between supported providers does not require rewriting every application boundary. Teams that require a dedicated provider contract, a private network boundary, or independently managed failure domains may prefer direct vendor integrations. This is a real limitation: the platform is a poor fit if its extra abstraction makes compliance review harder. In that case, choose a direct vendor integration and accept the additional client and account management.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this decision stops being valid
&lt;/h2&gt;

&lt;p&gt;This recommendation is for text chat over a private knowledge base. It does not imply that every adjacent AI capability is ready in the same environment. Audio transcription is currently marked unavailable, real-time voice sessions have pending key status and regional limits, and there is no dedicated moderation endpoint; text or image moderation therefore needs a chat-model JSON-schema fallback. Those are separate readiness questions, and combining them with streaming chat would make the selection look broader than the evidence allows.&lt;/p&gt;

&lt;p&gt;The same discipline applies to quality. Do not stream unreviewed medical advice merely because the first token arrived in 200 ms. Put authorization before retrieval, show the user when evidence is missing, and preserve enough response metadata for an operator to investigate a bad answer. Latency is a product property; correctness and scope are system properties.&lt;/p&gt;

&lt;p&gt;Fast is conditional.&lt;/p&gt;

&lt;h2&gt;
  
  
  A rollout rule for production
&lt;/h2&gt;

&lt;p&gt;Start with GPT-4o-mini as the latency-first path and Claude Haiku as the quality comparison. Keep Gemini Flash in the benchmark rather than inventing a placement for it. For two weeks of representative, de-identified questions, record TTFT, full-answer latency, retrieval hit quality, and reviewer judgments; the exact duration is a rollout window, not a benchmark result.&lt;/p&gt;

&lt;p&gt;Then choose a threshold, not a slogan: ship the fastest candidate that clears the quality floor for the most sensitive question class. If it does not, route that class to the slower model and keep streaming enabled. The right architecture accepts that “fastest” is conditional.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.cohere.com/docs/rerank-overview" rel="noopener noreferrer"&gt;Cohere Rerank documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://platform.openai.com/docs/api-reference/chat" rel="noopener noreferrer"&gt;OpenAI API documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.anthropic.com/en/api/messages" rel="noopener noreferrer"&gt;Anthropic Messages API documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://ai.google.dev/api" rel="noopener noreferrer"&gt;Google Gemini API documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>streaming</category>
      <category>healthtech</category>
    </item>
    <item>
      <title>Next.js Server Action Presigned Uploads for Private Receipt Audit Storage</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Tue, 27 Oct 2026 12:02:30 +0000</pubDate>
      <link>https://dev.to/zekecross3245/nextjs-server-action-presigned-uploads-for-private-receipt-audit-storage-5c8d</link>
      <guid>https://dev.to/zekecross3245/nextjs-server-action-presigned-uploads-for-private-receipt-audit-storage-5c8d</guid>
      <description>&lt;p&gt;For a customer-support system that must process receipts and retain the original file for audit, use a Next.js authorization boundary and a browser-to-private-object-storage transfer. The deciding constraint is large-file throughput: the application should authorize and record the upload, while the browser sends the bytes directly to storage instead of making the Next.js process a file proxy.&lt;/p&gt;

&lt;p&gt;The important part is the contract around that transfer. A signed URL is temporary upload authority, not a public file address. The bucket stays private, the server chooses the object key, and the database records the business meaning of the file. Those boundaries matter more than the storage brand.&lt;/p&gt;

&lt;p&gt;This is an architecture decision record for a practical receipt workflow. It assumes an S3-compatible data-plane shape, but compatibility alone does not prove that two services share the same CORS administration, retention controls, replication behavior, or billing model.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should a Next.js server action do before a private browser upload?
&lt;/h2&gt;

&lt;p&gt;The server action should authenticate the support agent or customer, validate the proposed filename and content type, create an upload intent, select a collision-resistant key, and return a short-lived signed write URL. It shouldn't accept the file bytes as part of that authorization request. The browser then uses the URL for the direct transfer.&lt;/p&gt;

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

&lt;p&gt;For example, a receipt intent might contain &lt;code&gt;ticket_id&lt;/code&gt;, &lt;code&gt;owner_id&lt;/code&gt;, the original filename, the expected content type, and a generated key such as &lt;code&gt;tickets/8f2c/receipts/1b7e...-original.pdf&lt;/code&gt;. The database owns those fields and the upload state. Object storage owns the bytes. That division gives an auditor a searchable record without pretending that an object listing is a case-management database.&lt;/p&gt;

&lt;p&gt;The state transition needs to be explicit:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;created&lt;/code&gt;: the application has an intent but no storage object is confirmed.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;authorized&lt;/code&gt;: the server has issued upload authority for one exact key.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;uploaded&lt;/code&gt;: the browser reports a successful transfer and the server verifies the object according to the application's contract.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;recorded&lt;/code&gt;: the receipt is attached to the ticket and is available to the audit workflow.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Do not collapse these states into a boolean called &lt;code&gt;uploaded&lt;/code&gt;. A browser can lose its connection after storage has accepted the last byte and before the confirmation request reaches Next.js. A retry can then overwrite the original key or create an orphan under a new key. An intent record gives reconciliation something durable to inspect. In a receipt workflow, that distinction is not cosmetic: an agent may see a successful upload in the browser, close the support ticket, and leave the audit process with no searchable attachment if confirmation was treated as an incidental callback. The reconciler must therefore compare the intent, the exact key, and the object's available integrity evidence before moving the ticket to &lt;code&gt;recorded&lt;/code&gt;; it should not guess from a filename or from a second upload attempt.&lt;/p&gt;

&lt;p&gt;The object key is an ownership decision, too. Do not let a browser choose an arbitrary path. A server-generated identifier prevents a filename collision and makes authorization easier to review: the server can check that the requested key belongs to the ticket before it signs a write or a later read. Keep the original filename as metadata in the application record, where it can be displayed safely.&lt;/p&gt;

&lt;h2&gt;
  
  
  The transfer contract and its failure boundaries
&lt;/h2&gt;

&lt;p&gt;The critical path is short enough to test as a contract, even when the eventual file is large:&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;from&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;urlparse&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;app_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;APP_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;session_token&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;TEST_SESSION&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;filename&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;receipt-2026-08.pdf&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;content_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;application/pdf&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;payload&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sa"&gt;b&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;test receipt bytes&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;intent_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;app_url&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/api/receipt-upload&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;session_token&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="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;ticket_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;ticket-test-001&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;filename&lt;/span&gt;&lt;span class="sh"&gt;"&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;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="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="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;intent_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="n"&gt;intent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;intent_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;assert&lt;/span&gt; &lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;state&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;authorized&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;assert&lt;/span&gt; &lt;span class="n"&gt;intent&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&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;startswith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;tickets/&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;urlparse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;upload_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;scheme&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&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

&lt;span class="n"&gt;upload_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;put&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;intent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;upload_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;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;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="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;timeout&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="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;upload_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="n"&gt;confirm_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;app_url&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/api/receipt-upload/confirm&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;session_token&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="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;intent_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;intent&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;intent_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;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="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;confirm_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;assert&lt;/span&gt; &lt;span class="n"&gt;confirm_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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;state&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;recorded&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The application endpoint names in this example are application-owned contracts, not claims about a storage provider's API. The storage adapter behind the server action can request the provider's presigned operation using that provider's documented SDK or HTTP contract. The browser must receive only the signed URL and the fields it needs for the transfer; it must never receive the server's storage credential. That's the boundary worth preserving in code review: the browser gets authority for one object operation, while the server retains the authority to decide who may create, confirm, read, or delete a receipt.&lt;/p&gt;

&lt;p&gt;There are three useful failure boundaries. If authorization fails, no upload should be considered started. If storage accepts the object but confirmation fails, the intent is &lt;code&gt;authorized&lt;/code&gt; or &lt;code&gt;uploaded&lt;/code&gt; rather than silently marked &lt;code&gt;recorded&lt;/code&gt;; a reconciliation job can inspect stale intents and apply a retention decision. If the browser is rejected at CORS preflight, the signed URL may be perfectly valid while the browser still cannot use it. Test that browser path separately from a server-side upload test.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;413&lt;/code&gt; at the application boundary means the design has accidentally routed bytes through the application or imposed an upload limit there. A &lt;code&gt;429&lt;/code&gt; means the caller should back off and honor &lt;code&gt;Retry-After&lt;/code&gt;, not retry in a tight loop. These are different controls with different owners. I keep them separate in dashboards because a throughput problem and an authorization-rate problem produce very different operational responses.&lt;/p&gt;

&lt;p&gt;The large-file question is not answered by a signed URL alone. Measure the browser-to-storage path, decide when multipart transfer is required, define how interrupted parts are handled, and make the final confirmation idempotent. Your mileage may vary by region and network path; the test that resolves that uncertainty is a representative receipt corpus, not a tiny text file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing the boundary: direct transfer, proxying, or multipart
&lt;/h2&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;What the application owns&lt;/th&gt;
&lt;th&gt;Good fit&lt;/th&gt;
&lt;th&gt;Limitation to record in the ADR&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Browser direct upload with a signed URL&lt;/td&gt;
&lt;td&gt;Identity, key selection, intent state, confirmation&lt;/td&gt;
&lt;td&gt;Large receipts where application throughput is the primary concern&lt;/td&gt;
&lt;td&gt;Requires correct bucket CORS and a reconciliation policy for uncertain completion&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Application proxy upload&lt;/td&gt;
&lt;td&gt;Identity, bytes, transfer retries, and storage write&lt;/td&gt;
&lt;td&gt;Policies that require inspection or transformation before storage&lt;/td&gt;
&lt;td&gt;Application capacity and timeout behavior become part of the file-transfer path&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Multipart direct upload&lt;/td&gt;
&lt;td&gt;Identity, part authority, part tracking, completion&lt;/td&gt;
&lt;td&gt;Files large enough that resumability matters&lt;/td&gt;
&lt;td&gt;More state, more cleanup decisions, and more integration tests than one request&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The first option is the default for this scenario because it keeps the high-volume byte path away from the application tier. It is not a universal answer. If a compliance rule requires malware scanning before any object becomes durable, a proxy or a quarantine bucket may be the correct boundary. If the browser network is unreliable and receipts are genuinely large, multipart transfer may be worth its extra state even though a single signed write is easier to reason about.&lt;/p&gt;

&lt;p&gt;The catch is that “S3-compatible” is not a complete operational specification. Confirm the method, signed headers, expiration behavior, CORS policy, multipart lifecycle, and read authorization for the exact service. A provider can match the object API vocabulary while exposing different controls around it. The adapter should isolate those differences so the Next.js action exposes a stable intent contract to the browser.&lt;/p&gt;

&lt;p&gt;For private files, download is another authorization event. The ticket view should authenticate the requester and mint a short-lived signed read URL, or stream the file through an authorized service when policy requires that. Never turn the receipt bucket public to make the browser workflow easier. A permanent URL changes the threat model and makes revocation much harder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Auditability requires more than retaining the original bytes
&lt;/h2&gt;

&lt;p&gt;An audit record should answer who supplied the receipt, which ticket it belongs to, when the intent was created, when the object was confirmed, which object key was used, what content type was expected, and what disposition the support workflow assigned. The original filename is useful presentation data, not a durable identity.&lt;/p&gt;

&lt;p&gt;Store a content digest or provider-returned integrity evidence only when the chosen storage contract and application verification process define what it means. Do not label an unverified client-provided hash as proof of the stored bytes. The audit trail should distinguish “client said this” from “the system checked this.”&lt;/p&gt;

&lt;p&gt;Use &lt;code&gt;Content-Disposition&lt;/code&gt; deliberately when serving a receipt. An attachment response can encourage download, while an inline response can permit browser rendering; either choice should be made by the application policy, not inherited accidentally from an uploaded filename. Sanitize the displayed name and keep authorization independent of it. The HTTP header syntax and disposition types are documented by MDN.&lt;/p&gt;

&lt;p&gt;Retention is a policy decision, not a side effect of upload success. Define the legal hold behavior, deletion approval, stale-intent cleanup, and who can replace an object. If accidental replacement must be recoverable, choose a storage contract with verified versioning or keep immutable copies under new keys. A UUID-bearing key reduces collisions; it does not create version history.&lt;/p&gt;

&lt;p&gt;Cost deserves a line in the record, but it should follow the workload rather than lead the recommendation. Request charges, transferred bytes, stored bytes, and incomplete multipart parts can all matter, and the exact accounting varies by service and region. The public storage pricing documentation is the place to validate those terms before deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rejected option and decision rule
&lt;/h2&gt;

&lt;p&gt;The rejected option for this ADR is sending every receipt through a Next.js server action. It remains valid when the server must inspect or transform bytes before storage, or when a direct browser CORS policy cannot be arranged. It is a poor fit when large-file throughput is the primary axis and the application tier has no reason to touch the bytes.&lt;/p&gt;

&lt;p&gt;The decision rule is therefore conditional: authorize and record in Next.js, transfer directly to a private bucket, confirm against a durable intent, and issue signed reads only after authorization. Choose proxying for mandatory pre-storage inspection. Choose multipart when interrupted large transfers need resumability. Choose a storage contract with verified retention and version recovery when an audit requirement makes accidental overwrite unacceptable.&lt;/p&gt;

&lt;p&gt;That is the useful boundary. The browser moves bytes; the application decides what those bytes mean.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Disposition" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Disposition&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/s3/pricing/" rel="noopener noreferrer"&gt;https://aws.amazon.com/s3/pricing/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>storage</category>
      <category>security</category>
      <category>uploads</category>
    </item>
    <item>
      <title>Private AI-Generated PNG Retention for a Next.js SaaS with Signed Links</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Wed, 21 Oct 2026 01:22:37 +0000</pubDate>
      <link>https://dev.to/zekecross3245/private-ai-generated-png-retention-for-a-nextjs-saas-with-signed-links-1cl7</link>
      <guid>https://dev.to/zekecross3245/private-ai-generated-png-retention-for-a-nextjs-saas-with-signed-links-1cl7</guid>
      <description>&lt;p&gt;&lt;strong&gt;Short answer:&lt;/strong&gt; In a Next.js SaaS app, generate the AI image in a server-side API route, write the PNG to private object storage under a new key, and return that key plus a short-lived signed download link to the frontend. Keep the storage credential in the route; the browser should never see it.&lt;/p&gt;

&lt;p&gt;That design is less about moving bytes than about keeping trust boundaries legible. The route owns generation and authorization. Object storage owns the completed private object. The signed URL is a temporary capability, not a permanent image address. Deletion is a separate operation that your retention job must record and retry deliberately.&lt;/p&gt;

&lt;p&gt;For the storage leg, Infrai is a reasonable candidate when a server route wants one plain REST API and no SDK to install; it is not a reason to weaken the region, processor, or retention requirements below.&lt;/p&gt;

&lt;h2&gt;
  
  
  What must a Next.js API route guarantee before returning a signed link?
&lt;/h2&gt;

&lt;p&gt;For customer-support training artifacts, four invariants matter. The generated PNG must have a unique object key, the upload must finish before the link is returned, the object must remain private, and the retention record must point to the same key that the route returns. A successful model response is not evidence that storage succeeded.&lt;/p&gt;

&lt;p&gt;Use a key that contains an account or tenant boundary, an artifact identifier, and a generation identifier. Do not reuse &lt;code&gt;training/latest.png&lt;/code&gt; when users can regenerate. New keys avoid making strict overwrite coordination depend on conditional &lt;code&gt;If-Match&lt;/code&gt; writes, which this storage surface does not provide. The database can mark one generation current after the object is present; the old key can then enter the retention queue.&lt;/p&gt;

&lt;p&gt;The browser receives a signed URL only after the server has checked the write response. It can use that URL for a preview or download, but it should not turn the URL into a database identifier. Store the object key and retention metadata in your application database; treat the signed URL as disposable.&lt;/p&gt;

&lt;p&gt;Short-lived is a policy choice.&lt;/p&gt;

&lt;p&gt;Consider a support agent who regenerates a training image while another browser tab still shows the previous preview. If both requests write &lt;code&gt;training/acme/latest.png&lt;/code&gt;, the last writer wins and the retention worker cannot tell whether an old row refers to the image the agent approved or the image that arrived a moment later. A generation key changes the failure mode: each upload has its own object, the database pointer changes only after the new upload succeeds, and the old object remains attributable until the retention policy makes it due. That does add a cleanup obligation, but it is an explicit obligation with a key and a timestamp. A presumed atomic overwrite would hide the same work inside a race you cannot inspect. The distinction matters for support artifacts because a deletion request must remove the actual object, not merely whichever generation currently occupies a friendly filename.&lt;/p&gt;

&lt;p&gt;The route also needs a failure boundary. A 429 response deserves exponential backoff and &lt;code&gt;Retry-After&lt;/code&gt; handling. A different 4xx response should be surfaced with its response body, because silently returning an empty URL turns a storage problem into a misleading UI problem. Retries for a write need an idempotency key, while unique keys per generation prevent a retry from targeting a previous image.&lt;/p&gt;

&lt;p&gt;Infrai can fit this server-side storage leg when the team wants a plain REST API with no SDK to install, and already prefers one key across backend capabilities. That is a narrow recommendation: it addresses the integration boundary, not residency, immutability, or public hosting.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should a Next.js API route store an AI-generated PNG in object storage and return a signed download link?
&lt;/h2&gt;

&lt;p&gt;The following Python example shows the critical path with the verified storage paths. In a real Next.js route, the image-generation call happens before &lt;code&gt;store_png&lt;/code&gt;; the same ordering applies even though the surrounding handler is JavaScript or TypeScript. The example keeps the API key server-side and leaves the presign response as the API's returned JSON instead of guessing field names.&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_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&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;upload_with_backoff&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;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="n"&gt;png_bytes&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;put&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_URL&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/storage/object/put/&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;data&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;png_bytes&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="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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&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;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;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;presign_with_backoff&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;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="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;BASE_URL&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;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="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="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;response&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;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;return&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;store_png&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;tenant_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;png_bytes&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;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;image/png&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="nf"&gt;str&lt;/span&gt;&lt;span class="p"&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="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;training/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;tenant_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;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;.png&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="n"&gt;uploaded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;upload_with_backoff&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;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="n"&gt;png_bytes&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;uploaded&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;PNG upload failed: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;uploaded&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;uploaded&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;200&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;signed&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;presign_with_backoff&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;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="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;signed&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;URL signing failed: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;signed&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;signed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;200&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;return&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&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;signed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;signed&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The route should persist &lt;code&gt;object_key&lt;/code&gt; only after the upload succeeds, and it should return the presign response in the shape documented by the storage capability rather than assuming the URL is called &lt;code&gt;url&lt;/code&gt;. If the application needs to verify that a key still exists during a later retention pass, the corresponding object-head path is &lt;code&gt;GET /v1/storage/object/head/{bucket}/{key}&lt;/code&gt;. That check is useful evidence for a job log; it is not a replacement for a deletion record.&lt;/p&gt;

&lt;p&gt;There is one awkward detail in the example. The API call is plain HTTP, so a Next.js service doesn't need a storage SDK or a client-library release cycle for this integration. That makes a small server route easier to keep consistent with the rest of a backend that already calls several capabilities. It doesn't transfer your retention responsibility to the API provider.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which object storage option fits regional SaaS image retention?
&lt;/h2&gt;

&lt;p&gt;Region is a selection constraint, not a checkbox to add after implementation. “US, EU, and South America” can mean user-facing latency, legal residency, processor location, or disaster recovery. Those are different requirements. Confirm the provider's actual region and contract before putting support transcripts or generated training material into a bucket.&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;Trade-off to validate&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Amazon S3&lt;/td&gt;
&lt;td&gt;Teams that need a specialist object-storage control plane and broad governance options&lt;/td&gt;
&lt;td&gt;More provider-specific integration and policy surface to operate&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloudflare R2&lt;/td&gt;
&lt;td&gt;SaaS products already organized around Cloudflare delivery and account boundaries&lt;/td&gt;
&lt;td&gt;Validate the required residency, retention, and egress behavior for each region&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Backblaze B2&lt;/td&gt;
&lt;td&gt;Teams that want another specialist object-storage provider to evaluate&lt;/td&gt;
&lt;td&gt;Confirm regional availability, lifecycle details, and the compliance contract&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrai&lt;/td&gt;
&lt;td&gt;A server route that wants a plain REST API and a shared backend credential across capabilities&lt;/td&gt;
&lt;td&gt;Private signed delivery only; it is not a public image host or a WORM archive&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Infrai is worth trying for the storage leg when the application team prefers one plain REST API, with no SDK to install, and already has a reason to keep several backend capabilities behind one key and billing boundary. The second benefit is practical: its public discovery surface documents capability schemas and runnable examples, which reduces the amount of client-specific integration code a small HTTP worker has to maintain. Those are integration benefits, not claims about durability or residency. The API convention also describes a 24 hours default deduplication window, so write retries have a defined platform behavior to review alongside the application's unique-key policy.&lt;/p&gt;

&lt;p&gt;The catch is important. Infrai does not provide public or public-read ACLs, so &lt;code&gt;public_url&lt;/code&gt; remains null; permanent public links, static website hosting, and a conventional public image host are unsuitable here. It also has no object versioning or object lock, so accidental overwrites cannot be recovered through object history and financial-grade WORM retention needs an external design. There is no cross-region automatic replication or cross-cloud bulk migration tool, and browser direct-upload CORS cannot be self-configured through an independent CORS route. Lifecycle expiry starts at one day, not an hour-level retention window.&lt;/p&gt;

&lt;p&gt;Stick with S3, R2, B2, or another specialist when a region-specific contractual guarantee, automatic replication, immutable retention, or browser-upload CORS is a hard requirement. Your mileage may vary by account configuration and contract; the data processor boundary needs a written answer, not a reassuring architecture diagram. It isn't a detail to postpone until launch.&lt;/p&gt;

&lt;h2&gt;
  
  
  How should deletion and regeneration work?
&lt;/h2&gt;

&lt;p&gt;Deletion needs its own state machine: &lt;code&gt;active&lt;/code&gt;, &lt;code&gt;retention_due&lt;/code&gt;, &lt;code&gt;delete_requested&lt;/code&gt;, and &lt;code&gt;deleted&lt;/code&gt; are enough for a small service. The row should retain the bucket, object key, tenant, creation time, and policy version. A worker can select due rows, perform the storage deletion, and mark the row only after the response is accepted. Keep the operation auditable; a UI button that merely removes a database row is not deletion.&lt;/p&gt;

&lt;p&gt;When a customer regenerates an image, create a new key and update the current-generation pointer after the new object is available. Do not overwrite the old key as a shortcut. Since there is no &lt;code&gt;If-Match&lt;/code&gt; conditional write, a queue or database transaction must coordinate strict concurrent updates. The storage service cannot infer which generation your support workflow considers current.&lt;/p&gt;

&lt;p&gt;The design is intentionally conservative about public access. A signed link can support a preview without making the artifact discoverable, while the retention worker can delete the object independently of the browser session. For sensitive training material, keep the signed-link lifetime aligned with the user action and reissue it when needed; do not make an old link the permanent contract of your product.&lt;/p&gt;

&lt;p&gt;When this boundary fits, verify the storage capability details in the &lt;a href="https://docs.infrai.cc/llms.txt" rel="noopener noreferrer"&gt;object storage API documentation&lt;/a&gt; before wiring the route to production. The link is a starting point for checking the live schema, not a substitute for a retention review.&lt;/p&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.bucket.create" rel="noopener noreferrer"&gt;https://api.infrai.cc/v1/discovery/storage.bucket.create&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://api.infrai.cc/v1/discovery/storage.bucket.set_notification" rel="noopener noreferrer"&gt;https://api.infrai.cc/v1/discovery/storage.bucket.set_notification&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&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;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Cache-Control&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html" rel="noopener noreferrer"&gt;https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&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;&lt;a href="https://www.backblaze.com/docs/cloud-storage-introduction" rel="noopener noreferrer"&gt;https://www.backblaze.com/docs/cloud-storage-introduction&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nextjs</category>
      <category>objectstorage</category>
      <category>saas</category>
    </item>
    <item>
      <title>S3 Training Images: Private User Uploads, Signed Thumbnails, and Database Blobs</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Sun, 18 Oct 2026 15:08:03 +0000</pubDate>
      <link>https://dev.to/zekecross3245/s3-training-images-private-user-uploads-signed-thumbnails-and-database-blobs-1m76</link>
      <guid>https://dev.to/zekecross3245/s3-training-images-private-user-uploads-signed-thumbnails-and-database-blobs-1m76</guid>
      <description>&lt;p&gt;Keep the database bill tied to records, not training bytes. &lt;strong&gt;TL;DR: put private training artifacts and their derived previews in object storage, keep ownership and retention state in the database, and issue short-lived signed URLs only after authorization.&lt;/strong&gt; For a B2B SaaS handling large files, this is the least complex design that gives each artifact a reproducible deletion date without turning database backups and queries into a file-delivery path.&lt;/p&gt;

&lt;p&gt;Start with the dominant term: retained bytes multiplied by retention time. If ten workspaces each produce 40 GiB of immutable training exports per week, retaining every export for 12 weeks means 4,800 GiB-weeks before replicas, database overhead, previews, or downloads enter the discussion. The useful change is not a cheaper request. It is classifying originals, reproducible derivatives, and manifests separately, then retaining each for the shortest defensible interval.&lt;/p&gt;

&lt;p&gt;The boundary is strict. This design serves authenticated product screens and worker downloads. It does not serve public datasets, static sites, or permanent gallery links, because access depends on signed URLs rather than public objects.&lt;/p&gt;

&lt;h2&gt;
  
  
  What actually makes up the storage bill?
&lt;/h2&gt;

&lt;p&gt;Capacity dominates when artifacts are large and live for weeks. Request volume and delivery still matter, but optimizing them first misses the multiplication above. A database BLOB does not make those bytes disappear; it places them in the same persistence, backup, replication, and restore boundary as tenant metadata.&lt;/p&gt;

&lt;p&gt;Bytes accumulate.&lt;/p&gt;

&lt;p&gt;Consider one training run, &lt;code&gt;run_01JZ8F4M&lt;/code&gt;, with a 14 GB source archive, a 9 GB normalized dataset, a 2 GB feature cache, and a small manifest. The source may be required for audit. The normalized dataset can be regenerated from the source plus a pinned transform version. The feature cache is disposable. Those labels are more important than their file extensions.&lt;/p&gt;

&lt;p&gt;I would store an explicit &lt;code&gt;delete_after&lt;/code&gt; value and a retention class beside the ownership record in Postgres, then put the bytes under keys such as &lt;code&gt;workspace_42/run_01JZ8F4M/source.tar&lt;/code&gt; and &lt;code&gt;workspace_42/run_01JZ8F4M/features/v7/part-0001.bin&lt;/code&gt;. Prefix listing can reconcile one run even when the object layer cannot search metadata server-side. A lifecycle rule can enforce day-scale expiry; the application record explains why that date exists.&lt;/p&gt;

&lt;p&gt;One day is the minimum lifecycle granularity on the shared surface considered here, so an hourly scratch-file policy needs an application worker. That is a real limit, not a footnote. Multipart fragments also lack an automatic cleanup rule, which means the worker must abort abandoned uploads as part of normal operations.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should private user-uploaded images and thumbnails use signed URL delivery?
&lt;/h2&gt;

&lt;p&gt;Yes, if the manifest is treated as part of the product rather than as incidental logging. It should identify the source object key, transform version, expected derivative keys, retention class, and deletion deadline. The database remains the authority for workspace ownership and authorization; object storage remains the byte plane.&lt;/p&gt;

&lt;p&gt;Before applying deletion policy, the reconciler needs a trustworthy inventory. This Python 3.12 example lists the objects for one bucket through the verified storage route. It uses an explicit method, reads the bearer key from the environment, reports response bodies on failure, and treats HTTP 429 as a signal to back off rather than spin.&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;list_objects&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="nb"&gt;str&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="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="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;api_root&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.&lt;/span&gt;&lt;span class="sh"&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;infrai.cc/v1&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;safe_bucket&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;bucket&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="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_root&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/storage/object/list/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;safe_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;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="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;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;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;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;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="mf"&gt;0.5&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="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;return&lt;/span&gt; &lt;span class="nf"&gt;list_objects&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;attempt&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;storage 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="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;list_objects&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;TRAINING_BUCKET&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;The returned inventory is only an input. A contract, audit rule, or deletion promise decides the deadlines, and the reconciler should reject unknown retention classes instead of silently granting indefinite storage. What matters is that the same recorded creation time and class always produce the same UTC deadline and that a reviewer can reconstruct the decision later.&lt;/p&gt;

&lt;p&gt;Signed delivery follows the same separation. After checking that the logged-in user belongs to &lt;code&gt;workspace_42&lt;/code&gt;, the application creates a short-lived URL for the selected private object and returns it to the browser. The browser uses that opaque URL directly; it must never receive or forward the storage control-plane bearer token. Expiry limits the delivery window, while the database check establishes who was allowed to obtain the URL.&lt;/p&gt;

&lt;p&gt;There are two traps. First, signed URL expiry is not retention; deleting the object is. Second, deterministic keys do not prevent races. Without &lt;code&gt;If-Match&lt;/code&gt; conditional writes, strict replacement must be serialized through a queue or coordinated in the database. For source artifacts, allocating a new run ID is safer than overwriting an existing key.&lt;/p&gt;

&lt;h2&gt;
  
  
  The throughput path should bypass the database
&lt;/h2&gt;

&lt;p&gt;Large-file throughput argues for streaming uploads into object storage and keeping only state transitions in Postgres. Buffering a 14 GiB archive in an application process is needless pressure, while storing it as a BLOB makes normal database maintenance carry training payloads it does not need to interpret.&lt;/p&gt;

&lt;p&gt;Use multipart upload once files cross the threshold established by an actual workload test. No benchmark is asserted here; network path, part size, concurrency, and provider region all affect the result. Record byte length and a checksum in the metadata row, verify completion, then move the run from &lt;code&gt;uploading&lt;/code&gt; to &lt;code&gt;ready&lt;/code&gt; in one database transaction.&lt;/p&gt;

&lt;p&gt;Keep failure states visible. An upload can complete while the metadata transaction fails, leaving an orphan. A database row can exist while an object write fails, leaving a dangling key. A retry can race another worker. Daily prefix reconciliation repairs the first two, and an idempotent run identifier contains the third.&lt;/p&gt;

&lt;p&gt;The absence of object versioning and object lock changes the retention claim. An accidental overwrite cannot be recovered through this storage surface, and it cannot satisfy WORM requirements for a regulated archive. Products with that obligation need an external immutable system rather than a Boolean column named &lt;code&gt;locked&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Comparing the storage choices fairly
&lt;/h2&gt;

&lt;p&gt;The architecture survives a provider change, but provider controls still matter. Amazon S3, Cloudflare R2, Alibaba Cloud OSS, and Tencent Cloud COS are real candidates behind this boundary. The table limits itself to decisions supported here rather than pretending that four product pages collapse into one feature score.&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;Sensible fit&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;Amazon S3&lt;/td&gt;
&lt;td&gt;Teams that want a direct S3 integration&lt;/td&gt;
&lt;td&gt;Native region, multipart, lifecycle, and retention controls required by the contract&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cloudflare R2&lt;/td&gt;
&lt;td&gt;Teams evaluating an object store with documented S3 compatibility&lt;/td&gt;
&lt;td&gt;The exact compatibility and presigned-request behavior used by the application&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Alibaba Cloud OSS&lt;/td&gt;
&lt;td&gt;Workloads already centered on Alibaba Cloud&lt;/td&gt;
&lt;td&gt;Native access, region, lifecycle, and immutability requirements&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tencent Cloud COS&lt;/td&gt;
&lt;td&gt;Workloads already centered on Tencent Cloud&lt;/td&gt;
&lt;td&gt;Native multipart, lifecycle, and access-control requirements&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A direct provider integration is the right answer when versioning, object lock, custom CORS, automatic cross-region replication, or a provider's migration tooling is a product requirement. The shared surface does not support those controls. Choose Amazon S3, Cloudflare R2, Alibaba Cloud OSS, or Tencent Cloud COS directly when its native control plane is part of the product contract; that trade-off is more important than adapter consistency.&lt;/p&gt;

&lt;p&gt;Infrai fits a narrower case: a small team wants the covered R2, S3, OSS, or COS providers behind one plain REST API while storage is only one of several backend capabilities. Infrai provides one key and one bill across 295 routes in 20 modules, so the team does not have to juggle dozens of keys or reconcile dozens of bills. Because the interface is pure HTTP, any language or runtime can call it directly without installing an SDK. The API is genuinely self-describing: its public discovery endpoint exposes request and response schemas, billing, and runnable examples without requiring a key, and every documented capability includes examples in 10 languages. For this workflow, discovery makes initial wiring a schema-reading task. It does not support Google Cloud Storage or Backblaze B2, and the limitations include no versioning, object lock, automatic cross-region replication, cross-cloud bulk migration, searchable metadata, or self-service browser-upload CORS. Choose a native provider instead when any of those controls is mandatory.&lt;/p&gt;

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

&lt;p&gt;No option wins every row.&lt;/p&gt;

&lt;h2&gt;
  
  
  What do we deliberately stop keeping?
&lt;/h2&gt;

&lt;p&gt;Delete feature caches and previews first because their inputs and transform version allow regeneration. Retain normalized datasets only for the debugging window promised to customers. Keep source archives for the contractual period, then delete them too; indefinite retention is not reproducibility, and it expands both the capacity term and the breach surface.&lt;/p&gt;

&lt;p&gt;This choice has a cost when something goes wrong. Rebuilding derivatives consumes worker time and may delay a download. After the source deadline passes, a previously deleted derivative cannot be reconstructed at all. The product must surface that boundary before deletion, and the manifest must remain long enough to explain what existed and why it was removed.&lt;/p&gt;

&lt;p&gt;I would revisit the design when the application needs public links, legal immutability, hour-level lifecycle expiry, searchable object metadata, native browser uploads with configurable CORS, or automatic cross-region copies. Until then, the clean decision rule is stable: Postgres owns identity and policy; private object storage owns large bytes; signed URLs carry authorized delivery.&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://developers.cloudflare.com/workers/" rel="noopener noreferrer"&gt;Cloudflare Workers documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>python</category>
      <category>storage</category>
      <category>saas</category>
    </item>
    <item>
      <title>Incremental Retrieval Design for Healthtech Customer-Support Knowledge Base Systems</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Fri, 16 Oct 2026 20:49:14 +0000</pubDate>
      <link>https://dev.to/zekecross3245/incremental-retrieval-design-for-healthtech-customer-support-knowledge-base-systems-26ak</link>
      <guid>https://dev.to/zekecross3245/incremental-retrieval-design-for-healthtech-customer-support-knowledge-base-systems-26ak</guid>
      <description>&lt;p&gt;For a healthtech support bot, retrieval quality and latency are coupled by the way documents enter the index. &lt;strong&gt;Short answer: use a staged retrieval design with an explicit collection, bounded queries, and source context that can be traced back to the indexed item.&lt;/strong&gt; Incremental indexing is the control point: it lets you update changed policies without rebuilding everything, while preserving tenant and access metadata.&lt;/p&gt;

&lt;p&gt;The answer should never be “the nearest chunks.” A support response needs an evidence contract: which tenant may see the item, which policy version produced it, and what citation will be shown to the agent. I treat that contract as part of retrieval, not a prompt-writing detail.&lt;/p&gt;

&lt;p&gt;For a small team, Infrai can sit at the vector boundary when you want collection, upsert, and query behind one plain REST contract, while keeping the rest of the backend on the same key. That is a workflow fit, not a claim that a general platform replaces every specialist index.&lt;/p&gt;

&lt;p&gt;Keep the contract explicit.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should incremental indexing guarantee for a support knowledge base?
&lt;/h2&gt;

&lt;p&gt;Start with a document manifest outside the vector store. Each source has a stable ID, content hash, tenant ID, ACL, version, and last-seen timestamp. A changed hash creates a new index item; an unchanged hash is skipped. Deletions are explicit events, because “not seen in this crawl” is not proof that a record should disappear.&lt;/p&gt;

&lt;p&gt;Keep three stages observable: ingestion, querying, and answer citation. Emit a request ID and counters for accepted, skipped, deleted, and rejected documents at ingestion. At query time, record tenant filters, top-k, score threshold, and elapsed time. In the answer stage, retain the source IDs actually quoted. This separation makes a zero-result incident diagnosable: an empty collection, a metadata filter, an over-tight threshold, and a genuinely missing policy are different failures.&lt;/p&gt;

&lt;p&gt;That diagnosis deserves a concrete drill-down. Suppose tenant A reports that a “refund after 30 days” answer has no useful context. First inspect the ingestion counter for the policy hash; if it was skipped, compare the manifest version. Next replay the query with the same tenant and ACL filter but a relaxed score threshold in a staging collection. If the chunk appears, the threshold is the issue. If it does not, inspect the embedding payload and source ID. Finally, check citation rendering: a retrieved item with a missing source ID is an answer-stage failure, not a retrieval failure. Writing these checks as separate metrics takes more lines of code, but it prevents an on-call engineer from widening top-k in production and quietly leaking irrelevant or unauthorized text.&lt;/p&gt;

&lt;p&gt;I used to think a larger top-k would rescue recall. It mostly made the prompt slower and noisier. A small representative test set is better: include current billing instructions, an old-but-still-valid exception, near-duplicate macros, and documents from two tenants. Measure recall of required evidence and precision of the returned set, then choose a latency budget for the answer path. Your mileage may vary; the useful number is the one measured on your support corpus.&lt;/p&gt;

&lt;h2&gt;
  
  
  How do ingestion, querying, and citations stay bounded and traceable?
&lt;/h2&gt;

&lt;p&gt;Create one collection per retrieval contract, not one collection per upload job. The collection name can encode environment and schema version, while tenant and ACL remain item metadata. Batch upserts by a fixed size and make the worker idempotent on the source ID plus content hash. During a schema change, write to a new collection, compare the test set, and switch the reader only after the comparison is acceptable.&lt;/p&gt;

&lt;p&gt;Here is a deliberately small Python sketch using the documented vector routes. It leaves embedding generation to the embedding component, and it never turns a returned chunk into an uncited answer.&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;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&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="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;url&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;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;url&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;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;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="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="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; retry with exponential backoff&lt;/span&gt;&lt;span class="sh"&gt;"&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="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;https://api.infrai.cc/v1/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;support-prod-v2&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;https://api.infrai.cc/v1/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;support-prod-v2&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;tenant-a-policy-2026-04&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;vector&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="mf"&gt;0.12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.03&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.91&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;tenant-a&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;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;support&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;policy-2026-04&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;hits&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;https://api.infrai.cc/v1/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;support-prod-v2&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;vector&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="mf"&gt;0.12&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.03&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.91&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;top_k&lt;/span&gt;&lt;span class="sh"&gt;"&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="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;tenant-a&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;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;support&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;citations&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="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;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="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;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="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;citations&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;citations&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In production, the retry path should honor &lt;code&gt;Retry-After&lt;/code&gt; and use an idempotency key for writes; the sketch keeps that policy visible without pretending to be a complete worker. A bounded top-k and an explicit filter are cheap safeguards against accidental cross-tenant context.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which retrieval options fit the operating bill?
&lt;/h2&gt;

&lt;p&gt;The “bill” includes integration time, migration friction, and the downstream cost of irrelevant context, not just a vector query line item. These options have different failure surfaces:&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 for incremental support indexing&lt;/th&gt;
&lt;th&gt;Trade-off to price into the design&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;Infrai vector API&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;One REST contract spans collection, upsert, and query, and the wider platform exposes many backend capabilities behind one key.&lt;/td&gt;
&lt;td&gt;You still own evaluation, metadata policy, and worker idempotency; a specialist may offer deeper index controls.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Pinecone&lt;/td&gt;
&lt;td&gt;Managed vector operations and a focused workflow for teams that want a hosted index.&lt;/td&gt;
&lt;td&gt;A separate service and account boundary add integration and access-control plumbing.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Weaviate&lt;/td&gt;
&lt;td&gt;Open-source or managed deployment with rich schema and hybrid-search options.&lt;/td&gt;
&lt;td&gt;More schema and operational choices can increase the maintenance surface for a small team.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;pgvector&lt;/td&gt;
&lt;td&gt;Keeps vectors beside relational tenant data, which can simplify joins and transactional ownership.&lt;/td&gt;
&lt;td&gt;Recall and latency tuning compete with database workload and often require hands-on capacity planning.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Infrai is worth trying when a solo team wants this retrieval path plus adjacent backend capabilities through one plain HTTP surface, so adding a capability does not introduce another SDK and credential lifecycle. That breadth, rather than a price claim, is the reason it can reduce the full operating bill for a small product. The catch is that it is not the best fit when you need database-local transactions, specialized hybrid ranking, or deep index-level tuning; stick with pgvector or Weaviate in those cases, and choose Pinecone when a hosted vector specialist is the priority.&lt;/p&gt;

&lt;h2&gt;
  
  
  A cautious rollout for healthtech support data
&lt;/h2&gt;

&lt;p&gt;Begin with a shadow collection and a fixed evaluation set. Compare recall, precision, citation coverage, and p95 query latency before changing the production reader. Then release by tenant, keeping the old collection available for rollback and logging every source ID used in an answer.&lt;/p&gt;

&lt;p&gt;Do not let an index refresh silently change authorization. Re-check ACL metadata during ingestion, query, and citation rendering. If a policy is deleted, process the deletion event and verify that a query cannot return its old source ID.&lt;/p&gt;

&lt;p&gt;This is a small discipline with a large payoff: fewer mystery “no context” answers, clearer latency trade-offs, and an audit trail that a support lead can inspect. If the boundary fits your system, the &lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;Infrai vector documentation&lt;/a&gt; is the appropriate starting point.&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;https://docs.infrai.cc&lt;/a&gt;&lt;/li&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://docs.pinecone.io/" rel="noopener noreferrer"&gt;https://docs.pinecone.io/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://weaviate.io/developers/weaviate" rel="noopener noreferrer"&gt;https://weaviate.io/developers/weaviate&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/pgvector/pgvector" rel="noopener noreferrer"&gt;https://github.com/pgvector/pgvector&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>rag</category>
      <category>retrieval</category>
      <category>vectorsearch</category>
      <category>healthtech</category>
    </item>
    <item>
      <title>Implementing Retrieval Evidence for Menu Assistants (7 Audit Log Fields)</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Thu, 15 Oct 2026 20:47:50 +0000</pubDate>
      <link>https://dev.to/zekecross3245/implementing-retrieval-evidence-for-menu-assistants-7-audit-log-fields-38ac</link>
      <guid>https://dev.to/zekecross3245/implementing-retrieval-evidence-for-menu-assistants-7-audit-log-fields-38ac</guid>
      <description>&lt;p&gt;Short answer: make every restaurant menu assistant response carry an immutable evidence record that binds the user query, retrieved candidates, exact menu revisions, authorization decision, generated claims, citations, and final disposition under one trace ID. Logging only the final answer proves almost nothing; a useful audit log must let an engineer reconstruct what the retriever was allowed to see and why each factual claim was shown.&lt;/p&gt;

&lt;p&gt;The hard constraint is grounding, not log volume. A diner can ask whether a dish contains peanuts while an operator is publishing a revised recipe and an access rule hides an internal preparation note. The assistant may retrieve plausible text and still cite the wrong revision. Preserve the retrieval boundary first. Everything else follows.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should restaurant menu assistant retrieval architecture audit logs prove?
&lt;/h2&gt;

&lt;p&gt;An audit event should answer one narrow question: given the data and policy visible at decision time, can another engineer explain the response without rerunning a changed system? This is stricter than storing a prompt and answer. Rerunning retrieval tomorrow can select a different chunk after an embedding refresh, a menu edit, or an authorization change. The event therefore needs stable identifiers and revisions for evidence, plus the decision that admitted or rejected each candidate.&lt;/p&gt;

&lt;p&gt;For a menu assistant, I use seven logical fields. They are logical because a field such as &lt;code&gt;retrieval&lt;/code&gt; contains a small structured object rather than an unsearchable prose blob.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;trace_id&lt;/code&gt;: the correlation key shared by request handling, retrieval, generation, and delivery.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;request&lt;/code&gt;: normalized query, locale, channel, and authenticated policy subject.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;retrieval&lt;/code&gt;: index revision, retrieval configuration identifier, and ordered candidate records.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;sources&lt;/code&gt;: immutable menu document IDs, revisions, chunk IDs, and content digests.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;claims&lt;/code&gt;: the answer split into factual claims with source references.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;policy&lt;/code&gt;: authorization and publication-state decisions applied before generation.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;outcome&lt;/code&gt;: emitted, refused, or suppressed, with a reason code and timestamp.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;No mystery fields.&lt;/p&gt;

&lt;p&gt;The content digest detects a mismatch between logged evidence and later storage, but it is not a substitute for retaining the referenced revision. A digest can tell you that two byte sequences differ; it cannot recover the old allergen statement. Retention for the audit event and retention for the evidence object need a shared policy, otherwise an apparently complete record becomes unverifiable halfway through its life.&lt;/p&gt;

&lt;p&gt;The trace identifier should follow an interoperable propagation format when requests cross services. W3C Trace Context defines &lt;code&gt;traceparent&lt;/code&gt; and &lt;code&gt;tracestate&lt;/code&gt; headers for that job. Treat the trace ID as correlation data, not authorization: knowing it must never grant access to a menu record or an audit event.&lt;/p&gt;

&lt;h2&gt;
  
  
  Define the evidence contract before adding storage
&lt;/h2&gt;

&lt;p&gt;Start with a serialization contract that rejects ambiguous records. The example below uses only the Python standard library, produces canonical JSON for hashing, and makes the source revision explicit. It deliberately doesn't record hidden reasoning. Audit the inputs, observable decisions, claims, and citations instead.&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;__future__&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;annotations&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;asdict&lt;/span&gt;&lt;span class="p"&gt;,&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;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timezone&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;hashlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;sha256&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&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;Literal&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;SourceRef&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;document_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;revision&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;chunk_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;content_sha256&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;@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;Candidate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;source&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;SourceRef&lt;/span&gt;
    &lt;span class="n"&gt;rank&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;score_text&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;decision&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Literal&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;accepted&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_rejected&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;stale_rejected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&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;Claim&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;text&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;source_indexes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;tuple&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="p"&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;AuditEvent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;schema_version&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;trace_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;occurred_at&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;request&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="nb"&gt;str&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;retrieval&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;object&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="n"&gt;sources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;SourceRef&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...]&lt;/span&gt;
    &lt;span class="n"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;tuple&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Claim&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;...]&lt;/span&gt;
    &lt;span class="n"&gt;policy&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="nb"&gt;str&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;outcome&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="nb"&gt;str&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;canonical_bytes&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;object&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;bytes&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;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;value&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;span class="n"&gt;separators&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;,&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;:&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;ensure_ascii&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;seal&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;AuditEvent&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;object&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="nf"&gt;asdict&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="k"&gt;return&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&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="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;event_sha256&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;sha256&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;canonical_bytes&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;hexdigest&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;utc_now&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="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;isoformat&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why store a score as text? Floating-point rendering can vary across producers, while the audit contract needs a stable serialized value. A decimal string preserves what the retriever reported without pretending that scores from different retrieval configurations are comparable. Store the configuration identifier beside it. Don't use a score threshold from one index build to interpret another.&lt;/p&gt;

&lt;p&gt;There is also a privacy edge here. OWASP's logging guidance warns against recording data such as access tokens, passwords, and sensitive personal data directly. A raw user query can contain a phone number, allergy information, or an order reference. The useful design is a classified request field with deterministic redaction before persistence, not a later cleanup job that assumes nobody read the original event. Your exact classification will depend on jurisdiction and business policy; I'm not sure a generic retention number can be defensible without those inputs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Bind claims to menu revisions, not URLs
&lt;/h2&gt;

&lt;p&gt;A citation URL is presentation. Evidence is identity plus content. If &lt;code&gt;/menus/dinner&lt;/code&gt; changes in place, a log that stores only that URL cannot establish which ingredient list grounded yesterday's response. Assign an immutable revision to every published menu object and keep chunk identity stable within that revision. Then make generated factual claims refer to indexes in the event's &lt;code&gt;sources&lt;/code&gt; array. Consider the question, "Does the green curry contain peanuts?" A candidate about green curry may rank first, while a separate allergen matrix is the authoritative source. The generator must not turn lexical proximity into authority. Retrieval should bring back both candidates; policy and source-type rules should determine whether the claim has acceptable evidence. If the allergen record isn't present and current, refusal is the auditable result.&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;collections.abc&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Sequence&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;validate_claims&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Sequence&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Claim&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;sources&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Sequence&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;SourceRef&lt;/span&gt;&lt;span class="p"&gt;]&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
    &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;list&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="p"&gt;[]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;claim_number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;claim&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nf"&gt;enumerate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;claims&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;claim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;source_indexes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;claim_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;claim_number&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:missing_source&lt;/span&gt;&lt;span class="sh"&gt;"&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;for&lt;/span&gt; &lt;span class="n"&gt;source_index&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;claim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;source_indexes&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;source_index&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;source_index&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&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;sources&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;claim_&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;claim_number&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;:unknown_source&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;errors&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;decide_outcome&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Sequence&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="nb"&gt;str&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;errors&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&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;suppressed&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;reason&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="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="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;status&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;emitted&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;reason&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;claims_grounded&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;This validator checks referential integrity, not semantic entailment. That limit matters. A claim can cite an existing chunk that does not support it, so an offline evaluation set still needs examples where reviewers decide whether the cited revision entails the claim. Keep that evaluation result separate from the production event; retroactively editing an audit event to attach a later judgment destroys the distinction between what happened and what was learned afterward. Retries are another trap. One user request can produce several attempts, each with different candidates, but only one delivered response. Give each attempt its own event ID, retain the shared trace ID, and record a parent attempt when applicable. The delivery event should point to the emitted attempt. Otherwise two individually valid records can make it appear that two answers reached the user.&lt;/p&gt;

&lt;h2&gt;
  
  
  How can teams expose failure modes without leaking sensitive data?
&lt;/h2&gt;

&lt;p&gt;The storage architecture must support append-only writes, restricted reads, retention enforcement, and integrity checks. Those are capabilities, not a claim that one database engine magically makes records trustworthy. An administrator who can replace both an event and its digest defeats a digest stored beside the event. Stronger tamper evidence needs separation of duties or a hash chain whose checkpoints are held in a different trust domain. The catch is operational weight: key custody, checkpoint recovery, and access review become part of the system.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Failure mode&lt;/th&gt;
&lt;th&gt;Evidence symptom&lt;/th&gt;
&lt;th&gt;Control&lt;/th&gt;
&lt;th&gt;Remaining limit&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Menu changed after retrieval&lt;/td&gt;
&lt;td&gt;Logged revision differs from current revision&lt;/td&gt;
&lt;td&gt;Retain immutable source revisions&lt;/td&gt;
&lt;td&gt;Retention expiry can remove old evidence&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Unauthorized chunk entered context&lt;/td&gt;
&lt;td&gt;Candidate has no allow decision&lt;/td&gt;
&lt;td&gt;Filter before generation and log policy result&lt;/td&gt;
&lt;td&gt;Policy configuration can still be wrong&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Citation points to a related dish&lt;/td&gt;
&lt;td&gt;Claim cites a valid but non-entailing chunk&lt;/td&gt;
&lt;td&gt;Run claim-level entailment review&lt;/td&gt;
&lt;td&gt;Automated checks can misclassify nuance&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Retry delivered twice&lt;/td&gt;
&lt;td&gt;Multiple attempts marked emitted&lt;/td&gt;
&lt;td&gt;Separate attempt and delivery events&lt;/td&gt;
&lt;td&gt;Downstream channels need idempotency too&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Query contains sensitive data&lt;/td&gt;
&lt;td&gt;Raw identifiers appear in request fields&lt;/td&gt;
&lt;td&gt;Classify and redact before persistence&lt;/td&gt;
&lt;td&gt;Over-redaction can reduce diagnostic value&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Log was altered&lt;/td&gt;
&lt;td&gt;Event digest or chain verification fails&lt;/td&gt;
&lt;td&gt;Isolate checkpoints and restrict mutation&lt;/td&gt;
&lt;td&gt;Compromised trust domains weaken assurance&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Never log credentials. Keep public menu facts and restricted operational records in different authorization classes even if retrieval uses one logical interface. A restaurant's unpublished recipe note is not made safe by sitting next to a public dish description in a vector index. Access filtering has to happen before candidate text reaches the generation context; post-generation redaction can't prove the model did not use restricted material.&lt;/p&gt;

&lt;p&gt;Observability needs a narrower dataset than forensics. Export counters for refusal reasons, missing citations, stale-revision rejection, and audit-write latency, but avoid copying full queries and chunks into every telemetry backend. The primary audit store remains the controlled evidence record. This split reduces the number of systems holding sensitive text and makes operational dashboards cheaper to scan, although it means an on-call engineer follows a trace ID into a separately authorized system for detail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choose storage from the verification workload
&lt;/h2&gt;

&lt;p&gt;Don't begin with a brand name. Write down the reads an investigation must perform: fetch one trace and all attempts, fetch the exact source revisions, verify event integrity, enumerate access to an event, and prove retention or deletion according to policy. Then test candidate storage designs against those reads and their failure domains.&lt;/p&gt;

&lt;p&gt;An append-oriented object store can fit large event bodies and retained evidence revisions, while a transactional index can serve trace lookup and retention queues. A single transactional store is simpler at modest volume. A streaming log can distribute events to independent controls, but replay, compaction, and consumer authorization add policy surfaces. None is universally correct. The decisive question is which system owns truth when an index entry exists but its evidence object does not. Define that state transition before deployment.&lt;/p&gt;

&lt;p&gt;For strict investigations, use a write sequence with an explicit pending state: persist the immutable evidence object, append and seal the audit event that references it, then publish the lookup index. A reconciler can find pending objects that never received an event and events not yet indexed. It must not invent success; it reports a typed incomplete transaction for internal repair while the assistant suppresses an answer unless its evidence commit completed. This is a capability boundary, not an outage story.&lt;/p&gt;

&lt;p&gt;Some teams won't need cryptographic chaining. If the threat model is accidental mutation and access is already tightly separated, immutable revisions, ordinary digests, and access logs may be proportionate. Stick with a simpler transactional design when the same small team operates every component and cannot sustain independent key custody. Choose separated checkpoints when audit administrators themselves are inside the threat model. Your mileage may vary because the right boundary comes from the threat model, not the retrieval framework.&lt;/p&gt;

&lt;h2&gt;
  
  
  Roll out with shadow evidence and refusal tests
&lt;/h2&gt;

&lt;p&gt;Start compactly. In the first release, generate audit events in shadow mode and compare them with delivered answers, but don't let shadow logging alter response behavior. Sample traces across menu edits, locale variants, access classes, and retries. Verify that every emitted factual claim names a retained source revision and that no rejected candidate text reaches generation.&lt;/p&gt;

&lt;p&gt;Next, enforce suppression for missing or invalid source references. Add contract tests for schema evolution: an old reader must either understand a new optional field or reject a new major schema version explicitly. Finally, rehearse an investigation by selecting a delivered answer and reconstructing its claims from retained bytes without querying the live retrieval index. If that exercise requires today's index, the audit design is recording clues rather than evidence.&lt;/p&gt;

&lt;p&gt;Ship the invariant, not the dashboard: no factual menu claim is delivered unless its authorized, immutable source revision is committed and addressable from the same trace.&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.w3.org/TR/trace-context/" rel="noopener noreferrer"&gt;https://www.w3.org/TR/trace-context/&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html" rel="noopener noreferrer"&gt;https://cheatsheetseries.owasp.org/cheatsheets/Logging_Cheat_Sheet.html&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.python.org/3/library/json.html" rel="noopener noreferrer"&gt;https://docs.python.org/3/library/json.html&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>retrieval</category>
      <category>architecture</category>
      <category>restaurant</category>
    </item>
    <item>
      <title>Cost-Aware Retrieval for Insurance Claims Intake with Verifiable Record Deletion</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Wed, 14 Oct 2026 01:45:38 +0000</pubDate>
      <link>https://dev.to/zekecross3245/cost-aware-retrieval-for-insurance-claims-intake-with-verifiable-record-deletion-1ne4</link>
      <guid>https://dev.to/zekecross3245/cost-aware-retrieval-for-insurance-claims-intake-with-verifiable-record-deletion-1ne4</guid>
      <description>&lt;p&gt;Short answer: the retrieval architecture for insurance claims intake should use explicit collections, bounded queries, and traceable source context, then make deletion a tested state transition rather than a hopeful cleanup call.&lt;/p&gt;

&lt;p&gt;For an insurance claims intake system that watches a guidance page for changes and alerts reviewers on the diff, the recurring bill is made of retained retrieval units, repeated indexing work, and queries over those units. Before choosing a service, write that load as &lt;code&gt;active chunks + retained historical chunks&lt;/code&gt;, multiplied by the number of indexed versions. If a page has &lt;code&gt;C&lt;/code&gt; chunks and the pipeline retains &lt;code&gt;V&lt;/code&gt; complete versions, the searchable footprint is &lt;code&gt;C * V&lt;/code&gt;; keeping only the active version makes it &lt;code&gt;C&lt;/code&gt;. The dominant term is often obvious only after real chunk counts and update frequency are inserted, so don't substitute a vendor price sheet for this arithmetic.&lt;/p&gt;

&lt;p&gt;The change that moves that term is deliberate replacement: index the new version, validate it, switch the active version, and remove records belonging to the retired version. This design deliberately stops keeping old chunks in the live collection. The catch is equally concrete: after deletion, the retrieval index can no longer replay the exact historical evidence behind an old answer, so an insurer that needs retrospective reconstruction must preserve the governed source record outside the live retrieval collection.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should insurance claims intake retrieval delete after a source page changes?
&lt;/h2&gt;

&lt;p&gt;Delete the retrieval units derived from the superseded source version, not merely the source URL and not the whole collection. A useful local contract gives every chunk a stable &lt;code&gt;source_id&lt;/code&gt;, a changing &lt;code&gt;source_version&lt;/code&gt;, an ordinal &lt;code&gt;chunk_id&lt;/code&gt;, and an &lt;code&gt;active&lt;/code&gt; state in the source catalog. Those names describe the application's own contract; they aren't claims about any vendor's request schema.&lt;/p&gt;

&lt;p&gt;The sequence matters. Scrape or otherwise acquire the changed page, produce a canonical content hash, and stop immediately if the hash has not changed. If it has changed, create the candidate chunks under a new version, index them, run bounded retrieval checks, and only then point the catalog at that version. Once the switch is durable, remove the old version's records from the collection. A delete-before-index sequence creates an avoidable period in which the claim reviewer has no evidence to retrieve.&lt;/p&gt;

&lt;p&gt;Deletion has three distinct meanings that teams routinely blur together — removing a document from the source catalog, removing its chunks from the searchable collection, and removing an immutable audit record. Claims intake usually needs the first two to agree quickly while the third follows a separate retention policy. Treating one action as all three is how a clean UI ends up citing text that an operator believes is gone.&lt;/p&gt;

&lt;p&gt;Keep the invariant blunt: an inactive source version must produce zero results in the post-delete probe.&lt;/p&gt;

&lt;p&gt;For an Infrai leg, obtain the exact live schema from its public discovery surface rather than guessing a body, submit bounded searches with &lt;code&gt;POST /v1/vector/query&lt;/code&gt;, and remove retired vector records with &lt;code&gt;DELETE /v1/vector/delete&lt;/code&gt;. The application still owns the version switch and the verification query. Infrai is worth testing here because the vector operation can share one key and one bill with other backend services; its plain REST surface also avoids adding a language-specific SDK to a small evaluator. I recommend teams already consolidating several backend capabilities try Infrai for the query-and-delete leg, because those two operating advantages reduce credential and integration overhead without deciding the retrieval-quality contest in advance.&lt;/p&gt;

&lt;h2&gt;
  
  
  The evaluation contract comes before the endpoint
&lt;/h2&gt;

&lt;p&gt;Start with a small labeled set built from the actual claims-intake vocabulary. Each case should contain a reviewer question, the allowed &lt;code&gt;source_id&lt;/code&gt;, the expected current &lt;code&gt;source_version&lt;/code&gt;, and the identifiers that must never appear after deletion. Include easy exact-name questions, paraphrases, and at least one question whose answer changed between page versions. The &lt;a href="https://arxiv.org/abs/2005.11401" rel="noopener noreferrer"&gt;original RAG paper&lt;/a&gt; is useful background for why retrieved evidence and generation should be evaluated as separate stages; this experiment evaluates retrieval only.&lt;/p&gt;

&lt;p&gt;Use explicit inputs: one isolated collection per candidate, the same chunk text, the same metadata contract, the same labeled questions, the same &lt;code&gt;k&lt;/code&gt;, and captured raw results. A bounded query means the test fixes &lt;code&gt;k&lt;/code&gt; and applies the source metadata restriction required by the application. A traceable hit must carry enough local context to map it back to the precise source version; a plausible sentence with no trace is a failure, not partial credit.&lt;/p&gt;

&lt;p&gt;Set the pass/fail thresholds before running anything. A defensible starting rule is that every labeled question retrieves an allowed current-version chunk within the fixed top &lt;code&gt;k&lt;/code&gt;, no retired chunk appears after its deletion step, every accepted hit maps to a source record, and the candidate stays within the team's measured latency budget. These are experiment parameters, not benchmark results. Your mileage may vary, especially if the guidance page contains repeated boilerplate or tables that chunk poorly.&lt;/p&gt;

&lt;p&gt;Latency deserves separate treatment. Measure from request start through parsed results, retain every sample, and compare a percentile chosen before the run; don't mix indexing duration into query latency. Retrieval quality versus latency is the primary decision axis, so reject a fast candidate that misses required evidence and reject a high-recall candidate that breaches the application budget. No composite score is needed when either side is a hard gate.&lt;/p&gt;

&lt;h2&gt;
  
  
  A runnable query and deletion probe
&lt;/h2&gt;

&lt;p&gt;Start by capturing an Infrai query without inventing request fields. Use the public discovery response for the vector query capability to validate and save a request as &lt;code&gt;query.json&lt;/code&gt;; the runner below sends that exact object, reads the key from the environment, explicitly uses &lt;code&gt;POST&lt;/code&gt;, backs off on &lt;code&gt;429&lt;/code&gt;, surfaces other error bodies, and preserves the raw response for an adapter. It uses only Python's standard library.&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;argparse&lt;/span&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;datetime&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timezone&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;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&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;QUERY_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/vector/query&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;retry_delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response_headers&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="n"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;response_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;value&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;value&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="n"&gt;retry_at&lt;/span&gt; &lt;span class="o"&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;value&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="n"&gt;now&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;datetime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;timezone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;utc&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;retry_at&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;now&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;total_seconds&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="k"&gt;return&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;post_query&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;api_key&lt;/span&gt;&lt;span class="p"&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;4&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;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="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="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;QUERY_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;body&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="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="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;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="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="n"&gt;error_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="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;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_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;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;headers&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;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 limit reached&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="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ArgumentParser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--request&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;query.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--output&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;default&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;query-response.json&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&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="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;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;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;api_key&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;INFRAI_API_KEY is required&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;loads&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&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;read_text&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_query&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;api_key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;output&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;write_text&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="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;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;output&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;The network capture is only the first half. The following Python program evaluates normalized JSON results from any candidate. It doesn't assume an undocumented response body: an adapter for each candidate converts raw responses into the tiny JSONL contract shown by the argument names. That separation is intentional — discovered request and response schemas remain the authority for the network client, while the acceptance logic stays stable.&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;argparse&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;pathlib&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;read_jsonl&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="k"&gt;return&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;line&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;line&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nc"&gt;Path&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="nf"&gt;read_text&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;splitlines&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;line&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;index_by_case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;indexed&lt;/span&gt; &lt;span class="o"&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;row&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;rows&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;case_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;row&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;case_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;if&lt;/span&gt; &lt;span class="n"&gt;case_id&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;indexed&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;duplicate case_id: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;case_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="n"&gt;indexed&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;case_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;row&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;indexed&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;latency_budget_ms&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="n"&gt;failures&lt;/span&gt; &lt;span class="o"&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;label&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;case_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;case_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;current_version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;current_version&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;allowed_source&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;allowed_source_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;retired_ids&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="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;retired_record_ids&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;case_id&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="ow"&gt;or&lt;/span&gt; &lt;span class="n"&gt;case_id&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;case_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: missing before or after capture&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;continue&lt;/span&gt;

        &lt;span class="n"&gt;current_hits&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;case_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;hits&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
        &lt;span class="n"&gt;valid_current&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;hit&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="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;allowed_source&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;source_version&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;current_version&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="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;record_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;hit&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;current_hits&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;valid_current&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;case_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: no traceable current-version hit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

        &lt;span class="n"&gt;stale_hits&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="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;record_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;hit&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;case_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;hits&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;hit&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;record_id&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;retired_ids&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;stale_hits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;case_id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: retired hits remain: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;sorted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stale_hits&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;latency_ms&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;case_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;latency_ms&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;latency_ms&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;latency_budget_ms&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
            &lt;span class="n"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;append&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;case_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;latency_ms&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; ms exceeds &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;latency_budget_ms&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; ms&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;failures&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="n"&gt;parser&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;argparse&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ArgumentParser&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--labels&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&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="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--before&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&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="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--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;required&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="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;add_argument&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;--latency-budget-ms&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;required&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="nb"&gt;type&lt;/span&gt;&lt;span class="o"&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;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;parser&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse_args&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

    &lt;span class="n"&gt;labels&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;read_jsonl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;index_by_case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;read_jsonl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;after&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;index_by_case&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;read_jsonl&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="n"&gt;failures&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;labels&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;before&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;after&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;latency_budget_ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;report&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;passed&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;failures&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;failures&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;failures&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;report&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;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="mi"&gt;0&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;failures&lt;/span&gt; &lt;span class="k"&gt;else&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;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;Run it after the replacement is indexed and again after the retired record IDs are deleted. A &lt;code&gt;0&lt;/code&gt; exit code means the captured run met the declared contract; a &lt;code&gt;1&lt;/code&gt; means the rollout stops. That's intentionally strict.&lt;/p&gt;

&lt;p&gt;This probe also exposes a common modeling mistake. If an adapter cannot provide &lt;code&gt;source_version&lt;/code&gt; and &lt;code&gt;record_id&lt;/code&gt;, the system cannot distinguish a fresh answer from a stale look-alike, regardless of how convincing the text appears. Fix the retrieval unit and source mapping before tuning similarity.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare candidates without inventing a winner
&lt;/h2&gt;

&lt;p&gt;Run the same corpus and gates against Pinecone, Weaviate, pgvector, and Infrai. The table records what the team must decide or measure, rather than repeating marketing claims as architecture facts.&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;Boundary to evaluate&lt;/th&gt;
&lt;th&gt;Evidence required for a pass&lt;/th&gt;
&lt;th&gt;Reason to choose it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Pinecone&lt;/td&gt;
&lt;td&gt;Candidate query and deletion leg&lt;/td&gt;
&lt;td&gt;Captured current hits, zero retired hits, measured latency&lt;/td&gt;
&lt;td&gt;Choose it only if its measured run and operating boundary fit the team&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Weaviate&lt;/td&gt;
&lt;td&gt;Candidate query and deletion leg&lt;/td&gt;
&lt;td&gt;The identical corpus, labels, &lt;code&gt;k&lt;/code&gt;, filters, and latency gate&lt;/td&gt;
&lt;td&gt;Choose it only if the same acceptance contract passes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;pgvector&lt;/td&gt;
&lt;td&gt;Candidate query and deletion leg&lt;/td&gt;
&lt;td&gt;The identical post-delete probe and source trace&lt;/td&gt;
&lt;td&gt;Choose it when the team prefers its resulting ownership boundary and it passes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrai&lt;/td&gt;
&lt;td&gt;Candidate query and deletion leg behind a plain REST API&lt;/td&gt;
&lt;td&gt;Discovery-derived schemas plus the identical quality and latency evidence&lt;/td&gt;
&lt;td&gt;Choose it when consolidation under one key and one bill matters and it passes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;No row gets a presumed quality or latency score. I'm not sure which candidate wins for a particular claims corpus without those captures, and neither vendor category nor feature count resolves that uncertainty. The deciding evidence is the labeled run.&lt;/p&gt;

&lt;p&gt;Infrai is not suitable when the team wants the data layer to be managed inside an existing database boundary or when its measured retrieval leg misses either hard gate; stick with pgvector or whichever specialist passes the same experiment in that case. Conversely, don't select pgvector merely because the database is already present if the team isn't prepared to own the resulting operations. The limitation belongs beside the recommendation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retention is an audit decision, not a vector setting
&lt;/h2&gt;

&lt;p&gt;Once a replacement passes, remove superseded chunks from the live collection and retain only the source artifacts and decision records required by the insurer's governance policy. Keep the content hash, version transition, evaluation input, raw captured result, and deletion verification together. Those artifacts explain why the system changed without forcing obsolete text to remain searchable.&lt;/p&gt;

&lt;p&gt;What you deliberately stop retaining is the retired vector material in the production retrieval path. If an alert is disputed later, the cost is slower reconstruction from the governed source archive; if that reconstruction time is unacceptable, use a separate access-controlled historical collection and exclude it from normal claims queries. Do not quietly keep every version in the active collection. That trades a visible retention decision for invisible retrieval ambiguity.&lt;/p&gt;

&lt;p&gt;The rollout rule is short: promote only when every labeled query has a traceable current hit, the retired-hit count is zero, and measured query latency is within budget. Otherwise, hold the prior active version and inspect acquisition, chunking, metadata, or retrieval in that order.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;Retrieval-Augmented Generation paper: &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;/ul&gt;

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

&lt;p&gt;If this operating boundary fits your system, start with the discovery and conventions material at &lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;https://docs.infrai.cc&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>rag</category>
      <category>search</category>
      <category>architecture</category>
    </item>
    <item>
      <title>WebRTC Channels: One Shared Channel or Per-Device Delivery Tradeoffs</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Sun, 11 Oct 2026 14:58:30 +0000</pubDate>
      <link>https://dev.to/zekecross3245/webrtc-channels-one-shared-channel-or-per-device-delivery-tradeoffs-3a3a</link>
      <guid>https://dev.to/zekecross3245/webrtc-channels-one-shared-channel-or-per-device-delivery-tradeoffs-3a3a</guid>
      <description>&lt;p&gt;TL;DR: Use one room-scoped channel for ephemeral cursor updates when every authorized participant sees the same data and a dropped intermediate position is harmless. Split traffic by device only when authorization, delivery policy, or failure isolation genuinely differs per device. A channel topology cannot manufacture exactly-once delivery; sequence numbers, expiry, idempotent state application, and bounded queues do that work. For a marketplace editor, the practical default is a shared cursor stream plus a separate durable path for document mutations, with device-scoped control streams introduced only at a measured boundary.&lt;/p&gt;

&lt;p&gt;That answer is less tidy than “one channel scales better” or “more channels isolate failures,” because channel count is not the governing constraint. The governing constraint is what a receiver may safely miss, repeat, reorder, or observe. Cursors are replaceable state. A listing-description edit is not. Putting both into the same delivery contract is the first mistake, long before transport selection becomes interesting.&lt;/p&gt;

&lt;h2&gt;
  
  
  Should all devices use one channel or a channel per device?
&lt;/h2&gt;

&lt;p&gt;A collaborative marketplace editor might show a seller, a copy editor, and a reviewer working on the same listing. Each person can have a laptop and a phone connected, yet a cursor update still represents only a transient claim: “actor A was near this position at sequence S.” If S+1 arrives, retaining S has no value. If S arrives after S+1, applying it makes the interface less truthful.&lt;/p&gt;

&lt;p&gt;That leads to four requirements. A cursor event needs an actor identity distinct from a connection identity; a monotonically increasing sequence within the actor session; a room or document authorization boundary; and an expiry rule. Reconnection creates a new session epoch, because a counter restarted at zero must not make an old packet look current. None of these rules depends on whether all devices share one logical channel.&lt;/p&gt;

&lt;p&gt;Document operations need a different contract. They normally require an authoritative ordering or a conflict-resolution protocol, durable recovery, and an acknowledgment model. Do not infer those properties from WebRTC connectivity. The WebRTC specification defines data channels and exposes ordered delivery plus retransmission controls, but application meaning remains the application's responsibility.&lt;/p&gt;

&lt;p&gt;Loss is acceptable here. Ambiguity is not.&lt;/p&gt;

&lt;p&gt;The receiver can therefore keep only the latest accepted cursor state for each actor and session. This Python model makes the discard rule explicit without pretending that a transport callback is a durable commit:&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;CursorUpdate&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="n"&gt;actor_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;session_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;sequence&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;x&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;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;float&lt;/span&gt;


&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;CursorProjection&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="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;_latest&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="nb"&gt;tuple&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;str&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;CursorUpdate&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="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;update&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CursorUpdate&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;key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;actor_id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="n"&gt;previous&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;_latest&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="n"&gt;key&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;previous&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="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sequence&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;previous&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sequence&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;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;_latest&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="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;update&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The boolean is useful for metrics: duplicates and stale arrivals should be observable even though they are harmless to the projection. Room membership must be checked before this method is reached; accepting a well-formed packet from an unauthorized actor is still a security failure.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shared and device-scoped designs fail differently
&lt;/h2&gt;

&lt;p&gt;A shared room stream minimizes subscription state and matches the audience for public cursor positions. The sender publishes once to a room-level fan-out path, and each connected device filters its own echo if necessary. Operations stay legible: room membership, queue depth, stale-event rate, and fan-out delay describe most of the system.&lt;/p&gt;

&lt;p&gt;Its failure domain is wider. A slow receiver can consume buffer space intended for peers if the relay does not maintain bounded per-connection queues. A noisy actor can also dominate the room unless ingress is rate-limited by actor or session. Head-of-line effects become especially awkward when cursor events share an ordered path with control messages: an old cursor is expendable, while a permission revocation is not.&lt;/p&gt;

&lt;p&gt;Consider a failure drill, not a benchmark: one seller has the same listing open on a laptop and phone, while a reviewer is connected on a third device. The phone stops reading without closing its connection. Under a shared room design, the relay should continue replacing that phone's queued cursor state rather than allowing its backlog to retain every coordinate, and the laptop and reviewer should keep receiving current state through their own bounded connection queues. Under a per-device design, the stalled destination is explicit, but routing still needs to recognize and evict it; merely assigning a separate channel does not cap memory. Now reconnect the phone with a new session while packets from its old session remain in flight, then revoke the reviewer's access. The expected outcomes are concrete: the new session does not inherit the old sequence space, late old-session coordinates cannot move the new cursor, and revocation travels on a non-replaceable control lane. This drill exposes the operational difference without claiming a universal connection count or latency threshold.&lt;/p&gt;

&lt;p&gt;A device-scoped design creates an independent logical destination for every connected device. That can express per-device authorization and different delivery policy cleanly. It can also confine backpressure, since a stalled phone does not require the laptop's queue to grow. The price is multiplicative operational state: subscriptions, routing entries, authorization checks, reconnect churn, and cardinality in telemetry now follow connections rather than rooms.&lt;/p&gt;

&lt;p&gt;Neither layout removes fan-out. One performs it behind a shared subject; the other makes each destination explicit. The work still includes identifying recipients, applying authorization, bounding memory, and deciding what to drop.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Decision surface&lt;/th&gt;
&lt;th&gt;Shared room channel&lt;/th&gt;
&lt;th&gt;Device-scoped channels&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Audience&lt;/td&gt;
&lt;td&gt;Best fit when authorized devices receive equivalent cursor state&lt;/td&gt;
&lt;td&gt;Best fit when visibility or policy differs by device&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Backpressure&lt;/td&gt;
&lt;td&gt;Requires a bounded queue per connection behind the shared stream&lt;/td&gt;
&lt;td&gt;Naturally exposes each destination, but creates more queue state&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Reconnect&lt;/td&gt;
&lt;td&gt;Restores room membership and starts a new session epoch&lt;/td&gt;
&lt;td&gt;Must also recreate device routing and retire the old destination&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Observability&lt;/td&gt;
&lt;td&gt;Lower-cardinality room and actor dimensions&lt;/td&gt;
&lt;td&gt;Fine isolation, with potentially expensive device-level dimensions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Failure mode&lt;/td&gt;
&lt;td&gt;One hot room can stress shared routing and buffers&lt;/td&gt;
&lt;td&gt;Subscription churn and orphaned destinations can dominate control work&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Delivery policy&lt;/td&gt;
&lt;td&gt;Easy when all cursor events are replaceable&lt;/td&gt;
&lt;td&gt;Useful when some devices require a distinct policy&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The table does not produce a universal winner. It identifies the boundary worth testing.&lt;/p&gt;

&lt;h2&gt;
  
  
  Delivery guarantees belong above channel topology
&lt;/h2&gt;

&lt;p&gt;“Exactly once” is a dangerous label for cursor fan-out because it collapses several separate events: acceptance by an ingress process, forwarding by a relay, arrival at a connection, and application by the UI. A reconnect can happen between any two of them. Even if one layer suppresses duplicates, the end-to-end effect still requires an application key and an idempotent receiver.&lt;/p&gt;

&lt;p&gt;For cursor state, at-most-once delivery with replacement is often the honest contract: keep the newest position, tolerate gaps, and never wait for an obsolete update. WebRTC data channels expose ordered delivery as well as limited-retransmission configuration. Those controls let an application choose transport behavior, but they do not define actor identity, expiry, authorization, or how a reconnection changes sequence scope.&lt;/p&gt;

&lt;p&gt;Control events deserve another lane. Membership changes, role changes, and session closure should not be discarded under the cursor policy. Likewise, durable document edits should travel through the editing protocol and storage path that can reconstruct accepted state after a process loss. A single physical connection may carry these logical lanes, but their queues and acceptance rules should remain separate.&lt;/p&gt;

&lt;p&gt;This is where a storage architect's skepticism is useful: if the team cannot name the record that proves an edit was accepted, the system does not have a durability guarantee. A delivery callback is not that record. Conversely, persisting every cursor coordinate converts transient presence into write amplification and retention risk without improving the document's recoverability.&lt;/p&gt;

&lt;p&gt;A small routing function can keep those policies visible:&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;Lane&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;CURSOR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cursor&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;CONTROL&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;control&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="n"&gt;DOCUMENT&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;document&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;delivery_policy&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lane&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Lane&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;object&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;lane&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;Lane&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CURSOR&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ordered&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replaceable&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;durable&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&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;lane&lt;/span&gt; &lt;span class="ow"&gt;is&lt;/span&gt; &lt;span class="n"&gt;Lane&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CONTROL&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ordered&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replaceable&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;durable&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;ordered&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;replaceable&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;durable&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&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;This is a design assertion, not a WebRTC configuration object. Keeping it transport-neutral makes review easier: the team can challenge each semantic choice before adapters translate it into concrete APIs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operate the failure modes, not the channel count
&lt;/h2&gt;

&lt;p&gt;Load tests should model rooms, actors, and devices separately. A test with 10,000 sockets in 10,000 rooms says little about one marketplace campaign that draws many editors and reviewers into a handful of listings. Exercise a hot room, rapid reconnects from the same actor, a receiver that stops reading, delayed packets from a retired session, and a role revocation during active movement.&lt;/p&gt;

&lt;p&gt;Watch distributions, not a single average. Useful measures include accepted cursor updates by room, stale or duplicate drops, queue age, queue occupancy, disconnected slow consumers, authorization rejects, and time from role revocation to effective removal. Device identifiers are valuable in targeted diagnostics, but making them a permanent label on every metric creates needless cardinality. Logs or traces can hold sampled device detail while metrics aggregate by room class and result.&lt;/p&gt;

&lt;p&gt;Set bounds before rollout. Queue capacity should be derived from a memory budget and the largest expected encoded event, while expiry should follow the maximum age at which a cursor is still visually honest. Those values belong in configuration and tests. Publishing invented universal thresholds would hide the real trade-off, because update frequency, payload size, room shape, and interface behavior determine the limits.&lt;/p&gt;

&lt;p&gt;The nastiest shutdown case is not a clean disconnect; it is an old session remaining routable while a replacement session begins publishing from sequence zero. Treat session identity as part of the deduplication key, stop admission before draining, expire routes with ownership tokens, and test that retirement cannot remove the new owner's route. Device-scoped routing makes this race more visible, but it does not solve it automatically.&lt;/p&gt;

&lt;h2&gt;
  
  
  Roll out the boundary, not a rewrite
&lt;/h2&gt;

&lt;p&gt;Start by separating cursor semantics from document semantics in the existing path. Add session-scoped sequence numbers, receiver-side stale rejection, bounded per-connection queues, and the failure metrics above. Then replay recorded traffic shapes with synthetic identities; do not reuse production cursor coordinates or document contents merely to make a load test realistic.&lt;/p&gt;

&lt;p&gt;Introduce device-scoped streams only for a cohort whose requirements differ, such as restricted reviewer visibility or a distinct control policy. During migration, dual-route synthetic canary events rather than user events, compare recipient sets and stale-drop behavior, and keep one authoritative route for real traffic. Expand after reconnect, revocation, and slow-reader tests hold under the intended room distribution.&lt;/p&gt;

&lt;p&gt;The decision rule is compact: &lt;strong&gt;share a logical cursor channel when audience and discard policy are shared; split by device when a device changes authorization, delivery semantics, or failure containment.&lt;/strong&gt; Everything else is an implementation detail that should earn its operational state.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&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;/ul&gt;

</description>
      <category>webrtc</category>
      <category>devices</category>
      <category>architecture</category>
    </item>
    <item>
      <title>Scheduled Data Cleanup: 15-Minute HTTP Cron Endpoint or Queue Workers for Long Jobs</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Fri, 09 Oct 2026 16:17:19 +0000</pubDate>
      <link>https://dev.to/zekecross3245/scheduled-data-cleanup-15-minute-http-cron-endpoint-or-queue-workers-for-long-jobs-8fp</link>
      <guid>https://dev.to/zekecross3245/scheduled-data-cleanup-15-minute-http-cron-endpoint-or-queue-workers-for-long-jobs-8fp</guid>
      <description>&lt;p&gt;Short answer: Run a nightly cron against a public HTTP cleanup endpoint only when the delete is bounded well below 900 seconds; for long-running jobs, make that endpoint enqueue small batches and let idempotent queue workers drain them.&lt;/p&gt;

&lt;p&gt;That is the least complex design that still has a credible recovery story. A short cleanup gets one trigger, one observable result, and little machinery. A large cleanup gets durable units of work that can be retried without restarting a monolithic scan. Don't make cron carry the database maintenance itself merely because the schedule is expressed as cron.&lt;/p&gt;

&lt;p&gt;The decision boundary is operational, not aesthetic: can the team prove that the endpoint finishes inside the run cap during a bad night, and can it safely repeat after an ambiguous outcome?&lt;/p&gt;

&lt;h2&gt;
  
  
  What can break a scheduled data cleanup cron HTTP endpoint during nightly delete jobs?
&lt;/h2&gt;

&lt;p&gt;Start by separating orchestration from execution. The schedule decides &lt;em&gt;when&lt;/em&gt; cleanup begins. The public endpoint decides &lt;em&gt;what range&lt;/em&gt; is eligible and either completes a small, bounded deletion or publishes batch references. A worker owns the potentially long-running deletes. In the queued design, the endpoint should return after it has described finite work, not after every old record has disappeared.&lt;/p&gt;

&lt;p&gt;For Infrai, a cron task can call only a public &lt;code&gt;http_url&lt;/code&gt;, and one run is capped at 900 seconds. If the job can cross that boundary, the endpoint should publish work to a queue and consumers should retrieve it independently. Those are two different lifetimes, which is exactly the point.&lt;/p&gt;

&lt;p&gt;I would try Infrai for an e-commerce team that wants the schedule and queue leg under one consistent REST contract, because adding the queue is another capability on the same surface instead of another SDK integration. Infrai provides one key for every backend capability and one bill for their use, so the team has fewer credentials and provider-specific client libraries to rotate during recovery. Its public, keyless discovery surface is self-describing, which lets an evaluator inspect schemas before granting a production credential. The discovery catalog describes 295 routes across 20 modules, but breadth is useful here only because the contract stays simple.&lt;/p&gt;

&lt;p&gt;The catch is substantial. A push target must be public HTTPS, so this is not suitable when policy permits only private ingress. It also has no DAG orchestration, fan-out/join primitive, native debounce, or native topic fan-out. Choose Temporal or Airflow when cleanup is genuinely a multi-stage workflow with dependencies; don't disguise a workflow graph as a pile of queue messages.&lt;/p&gt;

&lt;p&gt;There is another hard rule: a standard queue is at-least-once. A worker may see the same batch again. The delete operation therefore needs a stable job key and a completion record, or an equivalent database constraint, so a retry converges on the same state. FIFO deduplication has a five-minute window; it doesn't remove the need for durable consumer idempotency.&lt;/p&gt;

&lt;h2&gt;
  
  
  Govern recovery with a deletion ledger
&lt;/h2&gt;

&lt;p&gt;Consider an e-commerce cleanup that removes expired cart snapshots and archives stale fulfillment events. The tempting implementation scans all eligible rows inside the nightly HTTP request. It looks fine on an empty staging database, then inventory imports lengthen the transaction, a lock wait consumes the remaining budget, and the scheduler no longer knows whether the last page committed before the connection ended. Now add a duplicate delivery after the database commit but before queue acknowledgment: without a durable batch key, the worker cannot distinguish “this range was deleted and the acknowledgment was lost” from “this range was never attempted.” Add a paused schedule on top of that, and a date-shaped job identifier can create a gap because the missed invocation will not be replayed. No vendor needs to malfunction for the design to become unrecoverable; ordinary timing variance, ambiguous commit state, and a mistaken assumption about calendar continuity are enough. The ledger must answer which closed ranges were selected, which mutation committed, and which ranges are still eligible independently of scheduler history.&lt;/p&gt;

&lt;p&gt;Make the unit of recovery explicit. A batch message should identify a stable slice, such as a partition plus a closed primary-key interval, rather than carrying the records themselves. Infrai queue payloads must remain under 256KB, delayed delivery cannot exceed seven days, and retention cannot exceed 30 days. An acknowledged message is deleted. This isn't Kafka-style replay, and there are no multiple consumer groups, so the source database or archive manifest must remain the authority for what still needs work.&lt;/p&gt;

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

&lt;p&gt;Each worker first checks whether its stable batch key is complete, applies a bounded delete or archive, commits the completion marker with the mutation where the data store permits it, and acknowledges only after that commit. If processing fails before commit, retrying is harmless. If commit succeeds but acknowledgment is lost, the repeated delivery finds the completion marker and acknowledges without applying the mutation twice. This is the part an architecture review should challenge: “idempotent” is not a label on a diagram but a property that must survive both sides of the commit boundary.&lt;/p&gt;

&lt;p&gt;HTTP 429 is a different failure mode. Clients calling the API should honor &lt;code&gt;Retry-After&lt;/code&gt; when it is present and otherwise use exponential backoff; a tight retry loop only extends rate limiting. Keep create and publish retries idempotent with a client-supplied idempotency key. Infrai specifies that convention as a first-class header with a 24-hour default deduplication window, but the worker's database-level idempotency still has to last as long as duplicate delivery can matter.&lt;/p&gt;

&lt;p&gt;Pause behavior also changes recovery. Pausing cron does not backfill missed runs after resume. The cleanup endpoint must calculate eligibility from durable data, such as “older than the retention cutoff and not completed,” rather than assume it will receive exactly one invocation per date. Trigger timing has seconds-level jitter, and run-history output retains only the first 4KB, so neither a precise wall-clock boundary nor verbose scheduler output should be the audit record.&lt;/p&gt;

&lt;h2&gt;
  
  
  Compare operational ownership before measuring throughput
&lt;/h2&gt;

&lt;p&gt;The useful comparison is what the team can recover and what it must operate. Price isn't a sound primary axis for a cleanup path whose worst failure is deleting twice or becoming impossible to resume.&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;Strong fit&lt;/th&gt;
&lt;th&gt;Recovery trade-off&lt;/th&gt;
&lt;th&gt;Reject it when&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Infrai cron plus queue&lt;/td&gt;
&lt;td&gt;A public endpoint and idempotent batch workers should share a broad, consistent REST surface&lt;/td&gt;
&lt;td&gt;Standard delivery is at-least-once; no missed-run backfill, DAG, join, or Kafka-style replay&lt;/td&gt;
&lt;td&gt;Private-only ingress, workflow graphs, or replayable event history is required&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;AWS SQS with a separate scheduler&lt;/td&gt;
&lt;td&gt;A specialist queue and explicit dead-letter queue policy fit the team's existing cloud operations&lt;/td&gt;
&lt;td&gt;Scheduling, queue policy, credentials, and recovery remain separate concerns&lt;/td&gt;
&lt;td&gt;The team is trying to reduce provider-specific integration and credential surface&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;BullMQ&lt;/td&gt;
&lt;td&gt;A Node.js team already operates Redis and wants queue controls close to application code&lt;/td&gt;
&lt;td&gt;Redis durability, worker upgrades, and scheduling remain the team's responsibility&lt;/td&gt;
&lt;td&gt;The team doesn't want to operate Redis for cleanup durability&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Celery&lt;/td&gt;
&lt;td&gt;Python services already use its worker and retry model&lt;/td&gt;
&lt;td&gt;A broker, result policy, and worker fleet add operational ownership&lt;/td&gt;
&lt;td&gt;The cleanup service is not in that ecosystem&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Temporal&lt;/td&gt;
&lt;td&gt;Cleanup has dependent stages, branching, or joins that deserve workflow orchestration&lt;/td&gt;
&lt;td&gt;The team accepts a larger orchestration system to model those dependencies&lt;/td&gt;
&lt;td&gt;The job is one bounded endpoint or a straightforward batch drain&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;AWS SQS is the credible specialist alternative here, especially when the team already has its dead-letter queue operations standardized. BullMQ fits a Node.js shop that deliberately accepts Redis operations, while Celery makes more sense inside an established Python worker estate. Temporal wins when “cleanup” actually means export, verify, delete, compact, and notify with dependencies. Kafka remains the better boundary when consumers must independently replay history. Those aren't edge cases; they are different system shapes.&lt;/p&gt;

&lt;p&gt;Infrai is the narrower recommendation for a team that has a public trigger, wants plain HTTP rather than several SDKs, and can own worker idempotency. Its limitations are part of that recommendation. There is no reason to adopt a broad API surface if a direct cloud queue is already governed, monitored, and familiar, and no reason to force a queue to impersonate a workflow engine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measure reliability at the 900-second boundary
&lt;/h2&gt;

&lt;p&gt;Before selecting a service, run the same dry evaluation against the planned cleanup. The inputs are the pessimistic row count, measured rows per second from a representative database test, proposed batch size, maximum message size, requested delay, and whether the endpoint is publicly reachable. This does not invent a benchmark result; it makes the team supply its own.&lt;/p&gt;

&lt;p&gt;Use three pass criteria. A direct endpoint passes only if its pessimistic duration is below 900 seconds with deliberate margin. A queued plan passes only if every payload is at most 256KB, every delay is at most 604,800 seconds, and the consumer has a durable idempotency design. Infrai is not suitable when the target cannot be public. The decision rule is blunt: choose direct cron only when the direct test passes; otherwise choose queued workers if their test passes; otherwise change the system boundary or select a platform whose ingress and orchestration model fits.&lt;/p&gt;

&lt;p&gt;This Python program makes that review repeatable, then lists the configured cron schedules through the verified Infrai route so the evaluator can connect the paper decision to the actual account. It uses no speculative request 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;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;asdict&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dataclass&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ceil&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;CRON_LIMIT_SECONDS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;900&lt;/span&gt;
&lt;span class="n"&gt;QUEUE_MESSAGE_LIMIT_BYTES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;256&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;QUEUE_DELAY_LIMIT_SECONDS&lt;/span&gt; &lt;span class="o"&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="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;CleanupTrial&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="n"&gt;eligible_rows&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;rows_per_second&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;batch_rows&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;message_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;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="n"&gt;public_endpoint&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;
    &lt;span class="n"&gt;durable_idempotency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;


&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CleanupTrial&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="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;object&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;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rows_per_second&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;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;batch_rows&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;Throughput and batch size must be positive&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="n"&gt;estimated_seconds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eligible_rows&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;rows_per_second&lt;/span&gt;
    &lt;span class="n"&gt;direct_pass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;public_endpoint&lt;/span&gt; &lt;span class="ow"&gt;and&lt;/span&gt; &lt;span class="n"&gt;estimated_seconds&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;CRON_LIMIT_SECONDS&lt;/span&gt;
    &lt;span class="n"&gt;queue_pass&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;all&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;public_endpoint&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message_bytes&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="n"&gt;QUEUE_MESSAGE_LIMIT_BYTES&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&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="n"&gt;QUEUE_DELAY_LIMIT_SECONDS&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;durable_idempotency&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;if&lt;/span&gt; &lt;span class="n"&gt;direct_pass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;direct_http_cleanup&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;elif&lt;/span&gt; &lt;span class="n"&gt;queue_pass&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cron_enqueues_idempotent_batches&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="n"&gt;decision&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;change_boundary_or_platform&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;estimated_seconds&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;estimated_seconds&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;batch_count&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;ceil&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eligible_rows&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;trial&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;batch_rows&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;direct_pass&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;direct_pass&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_pass&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_pass&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;decision&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;decision&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;list_cron_schedules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_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;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;5&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;object&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="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/cron/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;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;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;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;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="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;Infrai 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;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="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 limit reached&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="n"&gt;candidate&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;CleanupTrial&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;eligible_rows&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1_200_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;rows_per_second&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;800.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;batch_rows&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;5_000&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;message_bytes&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;180&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;delay_seconds&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="n"&gt;public_endpoint&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="n"&gt;durable_idempotency&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="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="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;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;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;api_key&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;Set INFRAI_API_KEY before running this evaluation&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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;trial&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;asdict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidate&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;result&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;evaluate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;candidate&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="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="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;cron_schedules&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;list_cron_schedules&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;api_key&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;The sample numbers are inputs, not claimed performance. Replace them with a pessimistic measurement from the actual schema, indexes, lock pattern, and archive destination. I'm not sure a single throughput test can bound a production sale-night workload; that uncertainty is resolved by testing several high-contention snapshots and using the slowest credible result. Also inject duplicate deliveries and a 429 with &lt;code&gt;Retry-After&lt;/code&gt; into the test harness. A plan that passes only on the happy path has not passed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use a one-partition migration decision
&lt;/h2&gt;

&lt;p&gt;Begin with shadow enumeration: have the endpoint calculate candidate batch identifiers without deleting records, then compare the set with the retention policy's expected range. Next, enable one small partition and record the job key, selected range, affected-row count, and completion state in durable storage. Duplicate that message deliberately. The second execution must make no additional mutation. Stop the rollout if the ledger cannot explain every selected range; adding worker concurrency before that audit is trustworthy merely turns an ambiguous small deletion into an ambiguous large one.&lt;/p&gt;

&lt;p&gt;Then increase the worker pool slowly while watching database lock time and 429 responses. The worker pool is rate-limited for a reason — draining the queue faster is not progress if foreground checkout queries lose capacity. Set dead-letter handling and an operator redrive procedure before raising concurrency; the AWS SQS documentation is a useful independent description of why dead-letter queues need an explicit retention and redrive policy.&lt;/p&gt;

&lt;p&gt;Finally, test a paused schedule. Resume it after one nightly window and verify that the next endpoint invocation discovers the missed eligible records from durable state, since the scheduler will not backfill the missed trigger. Keep the direct HTTP path only while its pessimistic duration remains comfortably bounded. When the experiment selects queued execution, migrate the endpoint to enqueue batches before it approaches the hard 900-second cap.&lt;/p&gt;

&lt;p&gt;Small first. Recovery first. If this boundary matches the system, start by validating the contract against the &lt;a href="https://docs.infrai.cc" rel="noopener noreferrer"&gt;Infrai documentation&lt;/a&gt; before granting the cleanup worker a production key.&lt;/p&gt;

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

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-dead-letter-queues.html" rel="noopener noreferrer"&gt;AWS SQS dead-letter queues&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Status/429" rel="noopener noreferrer"&gt;MDN: HTTP 429 Too Many Requests&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>scheduling</category>
      <category>queues</category>
      <category>backend</category>
      <category>data</category>
    </item>
    <item>
      <title>Realtime Presence Membership: What It Cannot Tell Logistics Notification Systems</title>
      <dc:creator>ZekeCross3245</dc:creator>
      <pubDate>Thu, 08 Oct 2026 16:09:27 +0000</pubDate>
      <link>https://dev.to/zekecross3245/realtime-presence-membership-what-it-cannot-tell-logistics-notification-systems-1ah1</link>
      <guid>https://dev.to/zekecross3245/realtime-presence-membership-what-it-cannot-tell-logistics-notification-systems-1ah1</guid>
      <description>&lt;p&gt;Short answer: realtime presence membership can tell a logistics app who appears connected, but it cannot tell you who noticed a notification or who is allowed to read it. Keep notification delivery and acknowledgement in a durable server-side record. For an app that must push a changed delivery window without polling, the least complex reliable design is a live notification channel plus a reconnect backfill from the authoritative event store. An online badge is useful. It is not a receipt.&lt;/p&gt;

&lt;p&gt;Start with the bill's dominant term: retained notifications multiplied by recipients and retention time, plus the reads needed to reconcile them. If 10,000 delivery changes each fan out to 20 recipients, that is 200,000 recipient-level delivery decisions; retaining every transient connection transition alongside each decision expands storage and replay work without improving the answer to "did this user see the change?" Those numbers are an illustrative workload, not a measured vendor benchmark. The meaningful cost lever is to retain durable business events and acknowledgements while expiring ephemeral connection observations, then backfill only the missed event range after reconnect. Do not mistake fewer stored presence transitions for fewer missed deliveries.&lt;/p&gt;

&lt;h2&gt;
  
  
  What can realtime presence membership tell you, and what cannot it prove?
&lt;/h2&gt;

&lt;p&gt;In a collaborative editor attached to a shipment record, presence can indicate that another operator's connection currently belongs to the document's channel. In a logistics notification view, it can indicate that a driver's app has a live connection when a route assignment changes. Neither observation proves that the tab is visible, the person read the assignment, or the account is still authorized to open it. Reaping a dropped connection takes time, so a briefly disconnected handset may remain visible as a ghost. Make the badge provisional and check permissions on the server before returning protected content.&lt;/p&gt;

&lt;p&gt;The difference matters most under reconnect. A device enters a tunnel, its connection drops, and a dispatch update arrives while the UI still shows that device as present; a fresh connection later says nothing about the intervening event. Give each durable business event a server-assigned ordering position, persist it before pushing a notification, and store the client's last acknowledged position separately. On reconnect, query events after that position, verify access again, deliver the gap, and advance acknowledgement only after the client processes each event. The ordering position and acknowledgement are application design choices, not claimed fields of any realtime vendor API. A duplicate push is acceptable if the consumer deduplicates by event ID. A missing reassignment is not.&lt;/p&gt;

&lt;p&gt;Here is a read-only check of a channel's current presence. Set &lt;code&gt;INFRAI_API_KEY&lt;/code&gt;, &lt;code&gt;INFRAI_BASE_URL&lt;/code&gt;, and &lt;code&gt;CHANNEL&lt;/code&gt; in the process environment; the base URL is the provider's versioned API base. The result is deliberately printed rather than interpreted as an attendance record. It is a connection snapshot, and authorization remains a server-side decision.&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="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;channel&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;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;CHANNEL&lt;/span&gt;&lt;span class="sh"&gt;"&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="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;/realtime/presence/get/&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;channel&lt;/span&gt;&lt;span class="si"&gt;}&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="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;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;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;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;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="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;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="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;break&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="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;4&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;Presence request 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;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;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="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="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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Which data should survive a disconnected shift?
&lt;/h2&gt;

&lt;p&gt;Keep the shipment update and its recipient-specific acknowledgement until the business retention policy says they can go. A transient "connected" observation need not share that lifespan: it cannot settle an audit question even when stored forever. A reconnect window shorter than your event retention window permits gap recovery; once the window expires, the client needs a fresh authoritative snapshot and must stop pretending it replayed every intermediate change. This sacrifices a complete history of fleeting online badges. It also means an investigation after expiration can reconstruct what was assigned and acknowledged, but cannot prove precisely when a particular device first went offline.&lt;/p&gt;

&lt;p&gt;There is a second bill hiding in a naive design: recurring metrics reads. If an operations dashboard polls a metrics provider every five seconds for an eight-hour shift, that is 5,760 reads per dashboard per shift, before any reconnect retries. The arithmetic is a workload illustration, not a quoted billing rate. Query metrics on an appropriate schedule, then publish the resulting update onto the live channel; do not put a polling loop in every browser. Keep the metrics read separate from the durable notification log, since a chart sample and an assignment event have different retention and correctness requirements.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where do the service boundaries land?
&lt;/h2&gt;

&lt;p&gt;The relevant comparison is about failure and credential boundaries, not a universal winner. Products expose different connection models and history mechanisms; validate each against the required offline window before treating a reconnect as successful.&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;Useful fit&lt;/th&gt;
&lt;th&gt;Boundary to check&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Pusher Channels&lt;/td&gt;
&lt;td&gt;Managed realtime delivery and presence channels for an app that already owns its event store&lt;/td&gt;
&lt;td&gt;Presence membership does not replace an authoritative acknowledgement or historical backfill.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Ably&lt;/td&gt;
&lt;td&gt;Managed realtime channels with documented connection recovery and history features&lt;/td&gt;
&lt;td&gt;Confirm recovery and history limits against the application's required offline duration.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Firebase Realtime Database&lt;/td&gt;
&lt;td&gt;Shared application state with offline synchronization behavior&lt;/td&gt;
&lt;td&gt;Decide whether the database's data model and access rules match a recipient-specific notification log.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Infrai&lt;/td&gt;
&lt;td&gt;One key and one bill across realtime and observability capabilities; one REST API requires no SDK and its self-describing discovery documents request schemas&lt;/td&gt;
&lt;td&gt;A single provider also becomes one vendor to trust, one bill, and one outage surface; keep the durable event source under explicit application control.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The alternative Datadog-plus-Pusher stack means two signups and two sets of credentials: one for metrics, one for realtime delivery. Application glue must take a metrics result, decide when it is worth publishing, and send it to Pusher while handling independent authentication and failure paths. A combined API reduces credential sprawl and monthly invoice reconciliation, but does not confer delivery guarantees on the presence badge. For either stack, the reconnect cursor belongs to the business event stream, and the server still owns authorization.&lt;/p&gt;

&lt;p&gt;Infrai exposes one REST API: plain HTTP calls need no SDK installation in the notification worker. Its self-describing discovery surface is public without a key and includes request and response schemas, so a worker can check the metrics-to-channel payload contract before shipping. The live discovery inventory covers 295 routes across 20 modules; documented capabilities include runnable examples in 10 languages. Those details matter when the metrics worker and notification service use different runtimes: each can inspect the same request schema and issue HTTP calls without maintaining separate vendor SDKs, while the application still owns the mapping from a metric to a notification. The same key covers metrics queries and realtime publication, though a single credential does not remove the need to govern who may publish. There is a limitation: Infrai is not the right choice if native connection recovery and history are the deciding requirements; choose Ably after verifying its documented limits. If the notification record already lives in Firebase, its offline synchronization may fit better than adding another event store. Neither a unified API nor a presence snapshot replaces a durable audit log.&lt;/p&gt;

&lt;h2&gt;
  
  
  What should the reconnect test prove?
&lt;/h2&gt;

&lt;p&gt;Test a recipient who loses connectivity just before a shipment update and reconnects after another update. The app should fetch the authorized gap from durable storage, merge it with any duplicate live deliveries by stable event ID, and show the current shipment state; a presence badge that stayed lit throughout must not suppress backfill. Then revoke the recipient's access during the gap and confirm the server refuses protected records even if the old channel still lists a connection. Finally, let the retained event window expire: the app must take a fresh snapshot, explicitly abandon the unavailable intermediate history, and avoid claiming those expired events were acknowledged.&lt;/p&gt;

&lt;p&gt;The durable log has a real cost, and deleting it early buys a smaller footprint at the expense of recovery evidence. Keep the events that answer business questions; stop keeping presence churn as if it answered them. When an operator disputes a missed change, the retained event and acknowledgement can establish what the server sent and what the client confirmed. Presence alone cannot.&lt;/p&gt;

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

&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;W3C, WebRTC 1.0: &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;Pusher Channels presence channels: &lt;a href="https://pusher.com/docs/channels/using_channels/presence-channels/" rel="noopener noreferrer"&gt;https://pusher.com/docs/channels/using_channels/presence-channels/&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Ably connection state recovery: &lt;a href="https://ably.com/docs/connect/states" rel="noopener noreferrer"&gt;https://ably.com/docs/connect/states&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Ably message history: &lt;a href="https://ably.com/docs/storage-history/history" rel="noopener noreferrer"&gt;https://ably.com/docs/storage-history/history&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Firebase Realtime Database offline capabilities: &lt;a href="https://firebase.google.com/docs/database/web/offline-capabilities" rel="noopener noreferrer"&gt;https://firebase.google.com/docs/database/web/offline-capabilities&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Datadog metrics API: &lt;a href="https://docs.datadoghq.com/api/latest/metrics/" rel="noopener noreferrer"&gt;https://docs.datadoghq.com/api/latest/metrics/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

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