<?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: Twio_AI</title>
    <description>The latest articles on DEV Community by Twio_AI (@twio_ai).</description>
    <link>https://dev.to/twio_ai</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%2F3963488%2Fb1e312c9-b7e5-47f3-a25a-436a00f086a4.png</url>
      <title>DEV Community: Twio_AI</title>
      <link>https://dev.to/twio_ai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/twio_ai"/>
    <language>en</language>
    <item>
      <title>From Monolith Prompt to Event-Driven Agent — twio's Architecture Story</title>
      <dc:creator>Twio_AI</dc:creator>
      <pubDate>Mon, 22 Jun 2026 09:43:42 +0000</pubDate>
      <link>https://dev.to/twio_ai/from-monolith-prompt-to-event-driven-agent-twios-architecture-story-ad0</link>
      <guid>https://dev.to/twio_ai/from-monolith-prompt-to-event-driven-agent-twios-architecture-story-ad0</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt; — Our goal was a free-form agent—like Cursor or Claude Code—where users start anywhere, ask anything, and never march through a fixed pipeline. Getting there meant progressively moving responsibility off the prompt and onto the harness: first sequencing and state, then lifecycle and triage. The conversational freedom at the top was only safe because we kept adding structural guardrails underneath.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We wanted twio to feel like Cursor, but for mortgage brokers: a free-form agent you simply talk to. Jump into the middle of a refix, ask "when does their rate expire?", paste a customer's email, and let the agent carry on. No fixed pipelines, no "step 1 of 4"—just work the way it actually arrives.&lt;/p&gt;

&lt;p&gt;Our first version was the exact opposite of this. It could complete a refix end-to-end, but only if the broker followed the script's exact sequence. Start in the middle, ask a side question, or reply three days later, and the system would break.&lt;/p&gt;

&lt;p&gt;This is the story of how we chased that conversational freedom across three architectures. On the surface, each rebuild looked like a structural change. Underneath, it was a steady offloading of responsibilities—stripping away what the LLM was bad at holding, and handing it to the harness.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(To understand the evolution, just know that a **refix&lt;/em&gt;&lt;em&gt;—renewing a mortgage rate—sounds like a 4-step linear process, but in reality, it's fragmented, non-linear, and spans days. Keep that in mind.)&lt;/em&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture 1: The Monolith Script (and the Illusion of Control)
&lt;/h2&gt;

&lt;p&gt;When we started, we had no prior experience with LLM harnesses. Freedom was the goal, but first we had to answer a simpler question: &lt;em&gt;Can an LLM handle a real mortgage workflow end-to-end at all?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Our first architecture was one giant prompt driving the entire refix. It looked roughly like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You are a mortgage assistant. To do a refix:
1. Look up the customer by name; if several match, ask which one...
2. Ask for the new rate and term — unless the customer emailed...
3. Build the proposal. Repayment = P&amp;amp;I, unless interest-only...
4. Fill the lender form. ANZ uses fields X/Y; ASB uses...
5. Draft the sign-off email. Warm but professional...
...and ~300 more lines of rules, edge cases, and tone notes.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was simple, predictable, and legible. Then it met production reality, and fractured under two fatal flaws:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Cognitive Overload:&lt;/strong&gt; The longer the workflow, the more the prompt ballooned with edge cases, scattering the model's attention. It assumed a fixed sequence, but brokers don't work that way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tangled Coupling:&lt;/strong&gt; One prompt carrying fetch, validate, draft, and edge-case logic became an entangled wall of text. You couldn't test "build the proposal" without running the whole machine.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The recurring disruption that exposed these flaws: &lt;strong&gt;"The customer replies three days later."&lt;/strong&gt; In the monolith, there was simply no place for this. The run was over, or it was blocked waiting for a turn that wasn't coming.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Diagnosis:&lt;/strong&gt; A monolithic prompt fuses three things that should never mix.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmermaid.ink%2Fimg%2FZ3JhcGggTFIKICAgIEFbVXNlciBJbnB1dF0gLS0%2BIEIoR0lBTlQgUFJPTVBUKQogICAgQiAtLT4gQ1tDb250cm9sIEZsb3ddCiAgICBCIC0tPiBEW0RvbWFpbiBMb2dpY10KICAgIEIgLS0%2BIEVbU3RhdGUgLyBNZW1vcnldCiAgICBDICYgRCAmIEUgLS0%2BIEZbTExNIE91dHB1dF0KICAgIAogICAgc3R5bGUgQiBmaWxsOiNmZWUyZTIsc3Ryb2tlOiNlZjQ0NDQsc3Ryb2tlLXdpZHRoOjJweAogICAgc3R5bGUgQyBmaWxsOiNmZWYzYzcsc3Ryb2tlOiNmNTllMGIKICAgIHN0eWxlIEQgZmlsbDojZmVmM2M3LHN0cm9rZTojZjU5ZTBiCiAgICBzdHlsZSBFIGZpbGw6I2ZlZjNjNyxzdHJva2U6I2Y1OWUwYg%3D%3D%3Ftype%3Dpng%26bgColor%3DFFFFFF%26width%3D1200" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmermaid.ink%2Fimg%2FZ3JhcGggTFIKICAgIEFbVXNlciBJbnB1dF0gLS0%2BIEIoR0lBTlQgUFJPTVBUKQogICAgQiAtLT4gQ1tDb250cm9sIEZsb3ddCiAgICBCIC0tPiBEW0RvbWFpbiBMb2dpY10KICAgIEIgLS0%2BIEVbU3RhdGUgLyBNZW1vcnldCiAgICBDICYgRCAmIEUgLS0%2BIEZbTExNIE91dHB1dF0KICAgIAogICAgc3R5bGUgQiBmaWxsOiNmZWUyZTIsc3Ryb2tlOiNlZjQ0NDQsc3Ryb2tlLXdpZHRoOjJweAogICAgc3R5bGUgQyBmaWxsOiNmZWYzYzcsc3Ryb2tlOiNmNTllMGIKICAgIHN0eWxlIEQgZmlsbDojZmVmM2M3LHN0cm9rZTojZjU5ZTBiCiAgICBzdHlsZSBFIGZpbGw6I2ZlZjNjNyxzdHJva2U6I2Y1OWUwYg%3D%3D%3Ftype%3Dpng%26bgColor%3DFFFFFF%26width%3D1200" alt="Diagram: one giant prompt fusing control flow, domain logic, and state into a single LLM output" width="1200" height="437"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Fused together, changing one risks breaking the others.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The mandate for our first refactor was clear: &lt;strong&gt;Pull these three apart, and stop hardcoding the sequence.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture 2: Planner + Steps (Decoupling Flow and State)
&lt;/h2&gt;

&lt;p&gt;We shattered the monolith into &lt;strong&gt;Steps&lt;/strong&gt;. A step is a small, single-purpose agent with a typed contract: a focused prompt, a whitelist of tools, and strictly defined I/O schemas for state.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;Planner&lt;/strong&gt; produced an ordered sequence, and an orchestrator executed them. This cleanly separated the monolith's responsibilities:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmermaid.ink%2Fimg%2FZ3JhcGggTFIKICAgIFBbUGxhbm5lcl0gLS0%2BfE9yZGVyc3wgUzFbU3RlcCAxOiBQYXJ0aWVzXQogICAgUzEgLS0%2BfFdyaXRlcyAncGFydGllcycgc2xpY2V8IFMyW1N0ZXAgMjogUHJvcG9zYWxdCiAgICBTMiAtLT58V3JpdGVzICdwcm9wb3NhbCcgc2xpY2V8IFMzW1N0ZXAgMzogRm9ybSBGaWxsZXJdCiAgICAKICAgIFMxIC0uLT4gTDEoKExMTTogPGJyPlNtYWxsIFByb21wdCkpCiAgICBTMiAtLi0%2BIEwyKChMTE06IDxicj5TbWFsbCBQcm9tcHQpKQogICAgUzMgLS4tPiBMMygoTExNOiA8YnI%2BU21hbGwgUHJvbXB0KSkKCiAgICBjbGFzc0RlZiBoYXJuZXNzIGZpbGw6I2YwZmRmNCxzdHJva2U6IzIyYzU1ZSxzdHJva2Utd2lkdGg6MnB4OwogICAgY2xhc3NEZWYgbGxtIGZpbGw6I2VmZjZmZixzdHJva2U6IzNiODJmNixzdHJva2Utd2lkdGg6MnB4OwogICAgCiAgICBjbGFzcyBQLFMxLFMyLFMzIGhhcm5lc3M7CiAgICBjbGFzcyBMMSxMMixMMyBsbG07%3Ftype%3Dpng%26bgColor%3DFFFFFF%26width%3D1200" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmermaid.ink%2Fimg%2FZ3JhcGggTFIKICAgIFBbUGxhbm5lcl0gLS0%2BfE9yZGVyc3wgUzFbU3RlcCAxOiBQYXJ0aWVzXQogICAgUzEgLS0%2BfFdyaXRlcyAncGFydGllcycgc2xpY2V8IFMyW1N0ZXAgMjogUHJvcG9zYWxdCiAgICBTMiAtLT58V3JpdGVzICdwcm9wb3NhbCcgc2xpY2V8IFMzW1N0ZXAgMzogRm9ybSBGaWxsZXJdCiAgICAKICAgIFMxIC0uLT4gTDEoKExMTTogPGJyPlNtYWxsIFByb21wdCkpCiAgICBTMiAtLi0%2BIEwyKChMTE06IDxicj5TbWFsbCBQcm9tcHQpKQogICAgUzMgLS4tPiBMMygoTExNOiA8YnI%2BU21hbGwgUHJvbXB0KSkKCiAgICBjbGFzc0RlZiBoYXJuZXNzIGZpbGw6I2YwZmRmNCxzdHJva2U6IzIyYzU1ZSxzdHJva2Utd2lkdGg6MnB4OwogICAgY2xhc3NEZWYgbGxtIGZpbGw6I2VmZjZmZixzdHJva2U6IzNiODJmNixzdHJva2Utd2lkdGg6MnB4OwogICAgCiAgICBjbGFzcyBQLFMxLFMyLFMzIGhhcm5lc3M7CiAgICBjbGFzcyBMMSxMMixMMyBsbG07%3Ftype%3Dpng%26bgColor%3DFFFFFF%26width%3D1200" alt="Diagram: a planner ordering three typed steps, each backed by a small scoped LLM prompt" width="1200" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The planner orders typed steps; each runs its own small, scoped LLM prompt.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The Breakthrough: Context as Memory
&lt;/h3&gt;

&lt;p&gt;The most critical insight of this era was how we handled state. Steps didn't get the whole conversation history; they got a scoped view. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;refix_proposal&lt;/code&gt; reads &lt;code&gt;parties&lt;/code&gt;, writes &lt;code&gt;proposal&lt;/code&gt;, and &lt;em&gt;never sees the rest&lt;/em&gt;. This isn't just access control; &lt;strong&gt;it's memory management&lt;/strong&gt;. A model reasons far more accurately over a small, relevant context than a massive one. Scoping the view didn't just tidy the code—it made the steps sharper.&lt;/p&gt;

&lt;p&gt;Architecture 2 was a massive leap forward. We shipped a lot of features on it. But it carried a hidden, fatal assumption: &lt;strong&gt;It assumed work is synchronous and continuous.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To start work, the broker had to land on a homepage and &lt;strong&gt;select the workflow type from a dropdown&lt;/strong&gt; (e.g., "Refix"). Choosing "Refix" launched the fixed plan. That demands the broker knows the shape of the work &lt;em&gt;before&lt;/em&gt; anything runs. (You don't pick "refactor" from a menu before Cursor listens—you just start typing).&lt;/p&gt;

&lt;p&gt;Furthermore, the plan assumed run-to-completion. So, our recurring disruption returned: &lt;strong&gt;The customer replies three days later.&lt;/strong&gt; By then, the pipeline had finished or stalled. We tried bolting on a separate "inbox" to triage incoming items, but it felt like stapling an async patch onto a synchronous system. We deleted it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Diagnosis:&lt;/strong&gt; A refix is not a workflow you execute. It's a long-lived case, fed by disconnected events over days.&lt;/p&gt;

&lt;p&gt;The mandate for the next refactor: &lt;strong&gt;Stop making the broker declare the work up front. Stop pretending work runs to completion.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Architecture 3: The Open Case (Event-Driven Paradigm)
&lt;/h2&gt;

&lt;p&gt;We collapsed the dropdown menu of workflow types into &lt;strong&gt;one universal Case&lt;/strong&gt;. Every inbound event—email, chat message, late reply—flows into the same entry point. The first thing that runs is the planner, but it now has a completely different job: &lt;strong&gt;Triage&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of sequencing a known workflow, the planner looks at a single event and picks a path:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmermaid.ink%2Fimg%2FZ3JhcGggVEQKICAgIEV2ZW50KChJbmJvdW5kIEV2ZW50KSkgLS0%2BIFRyaWFnZXtUcmlhZ2UgUGxhbm5lcn0KICAgIAogICAgVHJpYWdlIC0tPnxTaW1wbGUgUXVlc3Rpb258IERpcmVjdFtSZXNwb25kIERpcmVjdGx5IDxicj4gTk8gUExBTl0KICAgIFRyaWFnZSAtLT58TWF0Y2hlZCBQbGF5Ym9va3wgV2FrZVsgV2FrZSBFeGlzdGluZyBDYXNlIF0KICAgIFRyaWFnZSAtLT58VW5rbm93biBUYXNrfCBBZEhvY1sgQ29tcG9zZSBBZC1Ib2MgU3RlcHMgXQogICAgCiAgICBXYWtlIC0tPiBTdGVwc1tSdW4gUmVxdWlyZWQgU3RlcHNdCiAgICBBZEhvYyAtLT4gU3RlcHMKICAgIAogICAgU3RlcHMgLS0%2BIFF1aWV0WyhDYXNlIEdvZXMgUXVpZXQgPGJyPiBBYnNlbmNlID0gV2FpdGluZyBTdGF0ZSldCiAgICAKICAgIEZ1dHVyZUV2ZW50KChDdXN0b21lciBSZXBsaWVzIDxicj4gMyBEYXlzIExhdGVyKSkgLS4tPiB8UmUtZW50ZXJzIFRyaWFnZXwgVHJpYWdlCgogICAgY2xhc3NEZWYgZXZlbnQgZmlsbDojZTBlN2ZmLHN0cm9rZTojNjM2NmYxLHN0cm9rZS13aWR0aDoycHg7CiAgICBjbGFzc0RlZiBzdWNjZXNzIGZpbGw6I2RjZmNlNyxzdHJva2U6IzIyYzU1ZTsKICAgIGNsYXNzRGVmIHdhaXQgZmlsbDojZmVmOWMzLHN0cm9rZTojZWFiMzA4OwogICAgY2xhc3NEZWYgZnV0dXJlIGZpbGw6I2ZjZTdmMyxzdHJva2U6I2VjNDg5OSxzdHJva2UtZGFzaGFycmF5OiA1IDU7CiAgICAKICAgIGNsYXNzIEV2ZW50IGV2ZW50OwogICAgY2xhc3MgRGlyZWN0IHN1Y2Nlc3M7CiAgICBjbGFzcyBRdWlldCB3YWl0OwogICAgY2xhc3MgRnV0dXJlRXZlbnQgZnV0dXJlOw%3D%3D%3Ftype%3Dpng%26bgColor%3DFFFFFF%26width%3D1200" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmermaid.ink%2Fimg%2FZ3JhcGggVEQKICAgIEV2ZW50KChJbmJvdW5kIEV2ZW50KSkgLS0%2BIFRyaWFnZXtUcmlhZ2UgUGxhbm5lcn0KICAgIAogICAgVHJpYWdlIC0tPnxTaW1wbGUgUXVlc3Rpb258IERpcmVjdFtSZXNwb25kIERpcmVjdGx5IDxicj4gTk8gUExBTl0KICAgIFRyaWFnZSAtLT58TWF0Y2hlZCBQbGF5Ym9va3wgV2FrZVsgV2FrZSBFeGlzdGluZyBDYXNlIF0KICAgIFRyaWFnZSAtLT58VW5rbm93biBUYXNrfCBBZEhvY1sgQ29tcG9zZSBBZC1Ib2MgU3RlcHMgXQogICAgCiAgICBXYWtlIC0tPiBTdGVwc1tSdW4gUmVxdWlyZWQgU3RlcHNdCiAgICBBZEhvYyAtLT4gU3RlcHMKICAgIAogICAgU3RlcHMgLS0%2BIFF1aWV0WyhDYXNlIEdvZXMgUXVpZXQgPGJyPiBBYnNlbmNlID0gV2FpdGluZyBTdGF0ZSldCiAgICAKICAgIEZ1dHVyZUV2ZW50KChDdXN0b21lciBSZXBsaWVzIDxicj4gMyBEYXlzIExhdGVyKSkgLS4tPiB8UmUtZW50ZXJzIFRyaWFnZXwgVHJpYWdlCgogICAgY2xhc3NEZWYgZXZlbnQgZmlsbDojZTBlN2ZmLHN0cm9rZTojNjM2NmYxLHN0cm9rZS13aWR0aDoycHg7CiAgICBjbGFzc0RlZiBzdWNjZXNzIGZpbGw6I2RjZmNlNyxzdHJva2U6IzIyYzU1ZTsKICAgIGNsYXNzRGVmIHdhaXQgZmlsbDojZmVmOWMzLHN0cm9rZTojZWFiMzA4OwogICAgY2xhc3NEZWYgZnV0dXJlIGZpbGw6I2ZjZTdmMyxzdHJva2U6I2VjNDg5OSxzdHJva2UtZGFzaGFycmF5OiA1IDU7CiAgICAKICAgIGNsYXNzIEV2ZW50IGV2ZW50OwogICAgY2xhc3MgRGlyZWN0IHN1Y2Nlc3M7CiAgICBjbGFzcyBRdWlldCB3YWl0OwogICAgY2xhc3MgRnV0dXJlRXZlbnQgZnV0dXJlOw%3D%3D%3Ftype%3Dpng%26bgColor%3DFFFFFF%26width%3D1200" alt="Diagram: inbound events enter a triage planner that responds directly, wakes a case, or composes steps; a 3-day-late reply re-enters triage" width="1200" height="1321"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Triage routes each event — answer directly, wake a case, or compose steps. A late reply just re-enters triage.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Three mechanisms make this architecture work:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Long-Lived Cases with Implicit Waiting&lt;/strong&gt;&lt;br&gt;
After acting, a case goes quiet. In our system, the absence of new messages &lt;em&gt;is&lt;/em&gt; the waiting state—there is no dangling pipeline. What broke Architecture 1 and stalled Architecture 2 is now trivial.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. First-Class "Do Nothing" Path&lt;/strong&gt;&lt;br&gt;
When a broker asks "when does their rate expire?", the triage planner answers it directly and stops. No four-step plan is generated. Often, no plan is the right plan.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Declarative Playbooks&lt;/strong&gt;&lt;br&gt;
Domain knowledge moved out of code and into Markdown playbooks. This allows mortgage experts to edit the "how" without touching the engine code.&lt;/p&gt;

&lt;h3&gt;
  
  
  Guarding the Freedom: Data-Flow Validation
&lt;/h3&gt;

&lt;p&gt;Handing a language model the freedom to compose its own step sequences is dangerous. We put a hard floor under it: a &lt;strong&gt;data-flow validator&lt;/strong&gt; that rejects an incoherent plan &lt;em&gt;before a single token of work is spent&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If the planner emits &lt;code&gt;refix_proposal&lt;/code&gt; before &lt;code&gt;parties&lt;/code&gt;, the validator hands back a precise error, and the planner self-corrects.&lt;/p&gt;

&lt;p&gt;This introduces a brilliant mechanism we call &lt;strong&gt;Soft Reads vs. Hard Reads&lt;/strong&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;Hard Read (Correctness):&lt;/strong&gt; An ordering constraint. &lt;code&gt;form_filler&lt;/code&gt; &lt;em&gt;must&lt;/em&gt; wait for &lt;code&gt;parties&lt;/code&gt;. If it's missing, the validator blocks it.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;Soft Read (Composability):&lt;/strong&gt; Visibility-only. &lt;code&gt;form_filler&lt;/code&gt; &lt;em&gt;can&lt;/em&gt; see &lt;code&gt;refix_proposal&lt;/code&gt; if it exists, but won't force it into the plan. This lets the step be dropped into a one-off request without dragging the whole refix sequence along.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One &lt;code&gt;reads&lt;/code&gt; declaration scopes the step's memory &lt;em&gt;and&lt;/em&gt; acts as an edge in the dependency graph. One declaration, two jobs.&lt;/p&gt;

&lt;p&gt;This is where twio finally felt like the free-form agent we set out to build. It’s the synthesis of our journey: &lt;strong&gt;Freedom at the top, structure at the bottom, knowledge in prose.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Why Not Just Use LangGraph?
&lt;/h2&gt;

&lt;p&gt;We evaluated LangGraph and similar agent frameworks before building our own. They are excellent tools, but designed for a fundamentally different paradigm: the static graph. Our workflow is a dynamic, event-driven beast.&lt;/p&gt;

&lt;p&gt;Forcing our architecture into a graph exposed three core mismatches:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The engine isn't the graph; it's the contracts.&lt;/strong&gt;&lt;br&gt;
Frameworks give you nodes, edges, and shared state. But twio's real value isn't topology—it's the typed step contracts (&lt;code&gt;reads&lt;/code&gt;/&lt;code&gt;softReads&lt;/code&gt;), the triage planner's judgment, and the prose playbooks. We'd still have to write all of that, just wrapped in someone else's &lt;code&gt;StateGraph&lt;/code&gt; syntax. We'd take on a heavy dependency while our actual core logic (like the 40-line data-flow validator) becomes harder to tweak.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Pre-compiled graphs vs. runtime composition.&lt;/strong&gt;&lt;br&gt;
A graph requires defining paths ahead of time. Our planner composes a fresh step sequence at runtime for &lt;em&gt;every single event&lt;/em&gt;, checked by a validator before execution. You can force a static framework to do dynamic routing, but then the graph stops being the source of truth. You end up fighting the framework's core abstraction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Shared state vs. strict isolation.&lt;/strong&gt;&lt;br&gt;
Our central thesis is that a step should only see its declared context slices. Graph frameworks default to passing a massive shared state object through every node. We’d be constantly fighting the framework's default behavior to enforce the one rule we care about most.&lt;/p&gt;

&lt;p&gt;If our workflows were mostly static and predictable, LangGraph would save us real work. Ours aren't.&lt;/p&gt;

&lt;p&gt;But the deeper point is this: &lt;strong&gt;our event-driven case design entirely sidesteps the need for durable execution.&lt;/strong&gt; Frameworks earn their keep by handling suspend/resume, timers, and exactly-once side effects. Because "no new messages" &lt;em&gt;is&lt;/em&gt; our waiting state, the system naturally suspends without needing underlying infrastructure to maintain it. If we ever actually need durable execution, we’ll reach for a dedicated engine like Temporal—not an agent framework.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's Still Hard
&lt;/h2&gt;

&lt;p&gt;Top-level freedom introduces new failure modes. The planner can match the wrong playbook. It can compose a valid but suboptimal plan. Prose playbooks can drift from what the steps actually execute. Our guardrails catch a majority of this, but this is a live frontier, not a solved problem.&lt;/p&gt;

&lt;p&gt;The through-line of this whole journey is that you don't arrive at the architecture—you get pushed into it by reality. Ultimately, the customer who replies three days late wrote more of our architecture than we did.&lt;/p&gt;

&lt;h3&gt;
  
  
  Architectural Takeaways
&lt;/h3&gt;

&lt;p&gt;If you are building long-lived, agentic systems:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Don't make the model hold what the harness holds better.&lt;/strong&gt; Offload sequencing, durable state, and lifecycle management to traditional code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Treat context as memory.&lt;/strong&gt; Strictly scope each step's view. Models reason better over small, relevant contexts.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Model the arriving unit as an event, not a task.&lt;/strong&gt; Work is fragmented; your architecture should expect interruption.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build a first-class "just respond" path.&lt;/strong&gt; Forcing a workflow when a direct answer suffices destroys the user experience.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Earn freedom with guardrails.&lt;/strong&gt; Use static validation (like our data-flow checker) to make self-composing agents safe.&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;&lt;em&gt;We're building &lt;a href="https://dev.to/twio_ai"&gt;twio&lt;/a&gt;, an AI assistant for mortgage brokers. If you're wrestling with the same questions about long-lived, event-driven agent architectures, we'd love to compare notes.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>architecture</category>
      <category>agents</category>
    </item>
    <item>
      <title>Why Twio Chose Vertex AI Search over pgvector for Production RAG</title>
      <dc:creator>Twio_AI</dc:creator>
      <pubDate>Mon, 22 Jun 2026 00:00:58 +0000</pubDate>
      <link>https://dev.to/twio_ai/why-twio-chose-vertex-ai-search-over-pgvector-for-production-rag-51jm</link>
      <guid>https://dev.to/twio_ai/why-twio-chose-vertex-ai-search-over-pgvector-for-production-rag-51jm</guid>
      <description>&lt;p&gt;When we first built RAG at Twio, pgvector was the obvious pick. Our business data was already in PostgreSQL, and dropping embeddings into the same database was the fastest path to a working product.&lt;/p&gt;

&lt;p&gt;For the first version, that was right. As we scaled, the problem stopped being "how do we store vectors?" and became "how do we reliably understand thousands of broker documents, emails, and attachments in production?" That changed the answer. Today, Vertex AI Search is our main retrieval layer.&lt;/p&gt;

&lt;h2&gt;
  
  
  RAG is Twio's memory layer, not a search feature
&lt;/h2&gt;

&lt;p&gt;Twio is an AI SaaS for loan brokers. A single client case is a mess of fragmented information:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;email threads&lt;/li&gt;
&lt;li&gt;payslips, bank statements, identity documents&lt;/li&gt;
&lt;li&gt;loan forms, lender requirements&lt;/li&gt;
&lt;li&gt;handwritten notes, follow-up emails, missing-document requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The AI needs to answer questions like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What documents has this client already sent?&lt;/li&gt;
&lt;li&gt;Which email mentioned the missing requirement?&lt;/li&gt;
&lt;li&gt;Does this bank statement support the income claim?&lt;/li&gt;
&lt;li&gt;Summarize all documents related to this borrower.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If retrieval is weak, the answer is weak. If indexing lags, context is missing. If parsing is wrong, the model sees the wrong evidence. RAG isn't a feature on the side — it's the memory layer of the product.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why pgvector was the right first choice
&lt;/h2&gt;

&lt;p&gt;Twio is a multi-tenant SaaS, so retrieval can't just return "similar content" — it has to return similar content scoped to the right user, client, application, or file. pgvector made that trivial: embeddings sat next to the business records, joined cleanly, and filtered with plain SQL.&lt;/p&gt;

&lt;p&gt;The early wins were real:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;no new infrastructure&lt;/li&gt;
&lt;li&gt;low cost, easy local dev&lt;/li&gt;
&lt;li&gt;SQL inspection for debugging&lt;/li&gt;
&lt;li&gt;straightforward metadata filtering&lt;/li&gt;
&lt;li&gt;fast to ship&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It let us build the first version quickly and learn from actual usage. That matters more than people give it credit for.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flnwrd6ayn9xd0hscn4ue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flnwrd6ayn9xd0hscn4ue.png" alt=" " width="800" height="650"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Where pgvector stopped paying off
&lt;/h2&gt;

&lt;p&gt;pgvector didn't fail. It did exactly what it's designed for. The issue was that vector storage is only one slice of the RAG pipeline, and pgvector left every other slice to us:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;download attachments&lt;/li&gt;
&lt;li&gt;extract text from PDFs, run OCR on scans&lt;/li&gt;
&lt;li&gt;chunk documents, generate embeddings&lt;/li&gt;
&lt;li&gt;design metadata, build retrieval queries&lt;/li&gt;
&lt;li&gt;tune indexes, improve ranking&lt;/li&gt;
&lt;li&gt;monitor Postgres load, debug retrieval quality&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A clean PDF is easy. A scanned bank statement isn't. An email body is easy. An email with five attachments, lender forms, tables, and partial OCR isn't. A demo dataset is easy. A real broker workspace with years of historical emails isn't.&lt;/p&gt;

&lt;p&gt;With pgvector, every weakness in that pipeline was ours to fix. When retrieval quality dropped, the suspect list ran all the way from OCR through chunking and embedding to vector distance, SQL filtering, ranking, and DB performance. The extension is simple. The production RAG system around it isn't.&lt;/p&gt;

&lt;p&gt;The cost shifted from cloud bill to engineering time — and engineering time was the constrained resource.&lt;/p&gt;

&lt;h2&gt;
  
  
  pgvector vs Vertex AI Search, in Twio's terms
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;pgvector&lt;/th&gt;
&lt;th&gt;Vertex AI Search&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Clean text PDF&lt;/td&gt;
&lt;td&gt;We own extraction, chunking, embedding, storage, search&lt;/td&gt;
&lt;td&gt;Vertex handles most of the indexing and retrieval workflow&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Scanned document&lt;/td&gt;
&lt;td&gt;We build or integrate OCR ourselves&lt;/td&gt;
&lt;td&gt;Vertex absorbs much of the document-processing logic&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Broker asks a document question&lt;/td&gt;
&lt;td&gt;We own query design, ranking, filtering&lt;/td&gt;
&lt;td&gt;Managed search with stronger out-of-the-box quality&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Attachment bursts&lt;/td&gt;
&lt;td&gt;Postgres carries more search and indexing load&lt;/td&gt;
&lt;td&gt;Search workload lives outside the main database&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Debugging&lt;/td&gt;
&lt;td&gt;Excellent SQL visibility, but many custom layers to inspect&lt;/td&gt;
&lt;td&gt;Less low-level control, but far less custom infra to debug&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost&lt;/td&gt;
&lt;td&gt;Lower direct service cost&lt;/td&gt;
&lt;td&gt;Higher service cost, lower engineering and maintenance cost&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Production readiness&lt;/td&gt;
&lt;td&gt;Significant custom work required&lt;/td&gt;
&lt;td&gt;Easier to operate as a managed layer&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;pgvector was cheaper as a database extension. Vertex is cheaper as a product decision.&lt;/strong&gt; The cloud bill is one input; engineering time, reliability, and iteration speed are the bigger ones at our stage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Vertex fits Twio's shape of problem
&lt;/h2&gt;

&lt;p&gt;Twio's RAG problem is document-heavy. We aren't searching short snippets — we're dealing with messy broker PDFs, scans, forms, tables, and forwarded attachments. Vertex helps in four concrete ways:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Less infrastructure to own.&lt;/strong&gt; Indexing and retrieval are handled by the managed layer, so we don't rebuild that surface.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Less document-processing logic to maintain.&lt;/strong&gt; OCR and parsing for messy broker files is one of the harder parts of the pipeline to keep healthy. Vertex covers much of it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Postgres stays focused on what it's good at&lt;/strong&gt; — business data, transactions, workflow state — instead of competing with OLTP work for the same resources.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It scales more naturally&lt;/strong&gt; as document volume grows.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Vertex isn't free, but the alternative isn't either. Building OCR, indexing, ranking, monitoring, and tuning ourselves has its own bill — paid in engineer-weeks.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F18fsqompa5ea18g1vpgy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F18fsqompa5ea18g1vpgy.png" alt=" " width="800" height="570"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What pgvector still does well
&lt;/h2&gt;

&lt;p&gt;pgvector is still a strong choice when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;data volume is moderate&lt;/li&gt;
&lt;li&gt;you're already on Postgres and want retrieval close to your data&lt;/li&gt;
&lt;li&gt;your documents are already clean text&lt;/li&gt;
&lt;li&gt;you need tight SQL filtering and full control&lt;/li&gt;
&lt;li&gt;you want a fast, low-cost first version&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For us, it was the right first implementation — and it taught us what retrieval the product actually needed. It may stay in the stack for internal or fallback use cases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Takeaway
&lt;/h2&gt;

&lt;p&gt;The lesson from Twio's RAG evolution is simple:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Start with the tool that helps you learn fastest. Move to the tool that helps you operate best.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;pgvector got us to a working RAG system quickly. As the product matured, the real challenge shifted to document processing, indexing quality, and operational reliability — and at that point, Vertex AI Search became the better fit. It costs more as a service and less as a system to maintain. For a SaaS at Twio's stage, that's the trade that matters.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>architecture</category>
      <category>database</category>
      <category>rag</category>
    </item>
    <item>
      <title>From pg-boss to Cloud Tasks: Fixing Queue Bursts and DB Connection Failures on Serverless</title>
      <dc:creator>Twio_AI</dc:creator>
      <pubDate>Tue, 02 Jun 2026 03:23:40 +0000</pubDate>
      <link>https://dev.to/twio_ai/from-pg-boss-to-cloud-tasks-fixing-queue-bursts-and-db-connection-failures-on-serverless-ii5</link>
      <guid>https://dev.to/twio_ai/from-pg-boss-to-cloud-tasks-fixing-queue-bursts-and-db-connection-failures-on-serverless-ii5</guid>
      <description>&lt;p&gt;At Twio we picked pg-boss for our job queue, ran into trouble when we went serverless, looked at Pub/Sub, and ended up on Google Cloud Tasks. This is what each queue got right, what it got wrong for our workload, and the rule we landed on for choosing between them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The workload
&lt;/h2&gt;

&lt;p&gt;Twio is an AI SaaS for loan brokers. The piece that needs a job queue is email processing: download an email, parse the body and attachments, OCR, classify with an LLM, write structured data, and index for RAG. One email with five attachments easily becomes 30+ background jobs. A batch upload becomes hundreds.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why pg-boss worked — until it didn't
&lt;/h2&gt;

&lt;p&gt;Our database was Postgres on Neon, so pg-boss was the obvious starting point. No extra infrastructure, and one feature we genuinely loved: &lt;strong&gt;transactional enqueue&lt;/strong&gt;. Because jobs live in the same database as business data, you can create a job in the same transaction as the row that triggered it. No dual-write problem, no "DB succeeded but the queue API failed" inconsistency.&lt;/p&gt;

&lt;p&gt;It also gave us retries, delayed jobs, dead-letter queues, dedup keys, and full SQL visibility into stuck or failed jobs. For a Postgres-first app on always-on infra, it's an excellent tool.&lt;/p&gt;

&lt;p&gt;Then we moved heavy processing to Cloud Run, and the cracks showed up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;pg-boss polls. Neon suspends. They want opposite things.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;pg-boss runs a query roughly every 1–2 seconds to look for the next job, plus maintenance queries. Neon autosuspends compute when nothing touches the database. If the queue is polling every second, Neon's idle timer never expires — you pay for always-on compute even when the queue is empty.&lt;/p&gt;

&lt;p&gt;Worse, when Neon &lt;em&gt;did&lt;/em&gt; manage to suspend, the next poll had to wake it. That wake-up takes hundreds of ms to a few seconds, and queries that triggered it would fail with &lt;code&gt;Connection terminated&lt;/code&gt;, &lt;code&gt;ECONNRESET&lt;/code&gt;, or timeouts. Pooled connections made it worse: the pool kept sockets that the server had already closed during suspend, and the next polling cycle picked one up and broke.&lt;/p&gt;

&lt;p&gt;This isn't a pg-boss bug. It's an architectural mismatch.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Pub/Sub wasn't the answer
&lt;/h2&gt;

&lt;p&gt;Pub/Sub is event-driven — no polling against Postgres, Neon can suspend freely. That fixed the obvious problem, but introduced a worse one for our shape of work.&lt;/p&gt;

&lt;p&gt;Pub/Sub is built to move messages &lt;strong&gt;fast&lt;/strong&gt;. We needed a queue that moves messages &lt;strong&gt;carefully&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Two specific failure modes hit us:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Retry amplification.&lt;/strong&gt; A parent import job publishes 100 child parse messages, then crashes before acking. Pub/Sub redelivers the parent. The parent re-publishes 100 children. After a few retries, you have hundreds of duplicate child jobs.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;No native job-level pacing.&lt;/strong&gt; If 300 messages land at once, subscribers consume them as fast as they can — slamming our parser, Neon, the LLM provider, and third-party APIs simultaneously. Pub/Sub has flow control on the subscriber side, but it's not the kind of per-queue dispatch throttle we needed.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Plus the ack-deadline problem on long parse jobs, where a missed lease extension causes redelivery while the original is still running.&lt;/p&gt;

&lt;p&gt;All of these are solvable with idempotency keys, outboxes, and bounded retries — but at that point you're rebuilding what a job queue should give you out of the box.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Cloud Tasks fit
&lt;/h2&gt;

&lt;p&gt;Cloud Tasks is push-based: when a task is due, Google sends an HTTP request to our handler. When there are no tasks, nothing touches our database. That alone resolved the pg-boss/Neon conflict — Neon suspends, costs drop, no more wake-up connection errors.&lt;/p&gt;

&lt;p&gt;But the real reason it fit was &lt;strong&gt;per-queue dispatch control&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# queue.yaml&lt;/span&gt;
&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;email-parse&lt;/span&gt;
  &lt;span class="na"&gt;rateLimits&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;maxDispatchesPerSecond&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;
    &lt;span class="na"&gt;maxConcurrentDispatches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;20&lt;/span&gt;
  &lt;span class="na"&gt;retryConfig&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;maxAttempts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;
    &lt;span class="na"&gt;minBackoff&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10s&lt;/span&gt;
    &lt;span class="na"&gt;maxBackoff&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;600s&lt;/span&gt;
    &lt;span class="na"&gt;maxDoublings&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enqueue 300 tasks in a second and Cloud Tasks won't deliver them all at once — it paces dispatch to the limits we set. Our parsers, Neon, and the LLM provider stay protected from bursts.&lt;/p&gt;

&lt;p&gt;It also gives us operational levers Pub/Sub doesn't: list tasks, inspect depth, pause a queue, purge a bad batch. When a fan-out goes wrong, we can stop it.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Cloud Tasks doesn't solve
&lt;/h2&gt;

&lt;p&gt;Two things, both important.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;It's still at-least-once.&lt;/strong&gt; A handler can finish the work and Cloud Tasks can still redeliver if the HTTP response is lost. Handlers must be idempotent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Fan-out duplication is still possible.&lt;/strong&gt; If the parent creates 100 child tasks and then fails before returning 200, the retried parent creates them again. The fix here is deterministic task names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;parse-{emailId}-{attachmentId}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Cloud Tasks rejects duplicate names within its retention window, so the second attempt is a no-op. But you have to design for it — it's not automatic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And it doesn't recover transactional enqueue.&lt;/strong&gt; Cloud Tasks lives outside the database, so creating a task after a DB write is a dual-write. If you need strict atomicity, the answer is still an outbox: write the business row and an outbox row in one transaction, have a relay publish to Cloud Tasks and mark the row published. No external queue makes this go away.&lt;/p&gt;

&lt;h2&gt;
  
  
  The rule we landed on
&lt;/h2&gt;

&lt;p&gt;Queue selection isn't about finding the best queue. It's about matching the queue to the runtime model.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;pg-boss&lt;/strong&gt; for small internal jobs in always-on services where Postgres transactionality matters.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cloud Tasks&lt;/strong&gt; for cross-system, serverless workflows where we need to protect Neon, LLM providers, and third-party APIs from bursts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And three rules that apply regardless:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Every handler is idempotent.&lt;/li&gt;
&lt;li&gt;Fan-out children have deterministic keys.&lt;/li&gt;
&lt;li&gt;If enqueue must be atomic with a business write, use an outbox.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cloud Tasks fixed our infrastructure mismatch, but the real win was clarifying what the queue is responsible for. Infrastructure handles scheduling, retries, and rate limits. Correctness belongs to the application.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>cloud</category>
      <category>postgres</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
