惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
D
Docker
有赞技术团队
有赞技术团队
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
爱范儿
爱范儿
H
Help Net Security
美团技术团队
MyScale Blog
MyScale Blog
B
Blog RSS Feed
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
阮一峰的网络日志
阮一峰的网络日志
A
About on SuperTechFans
小众软件
小众软件
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
GbyAI
GbyAI
G
Google Developers Blog
月光博客
月光博客
Google DeepMind News
Google DeepMind News
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Blog — PlanetScale
Blog — PlanetScale
MongoDB | Blog
MongoDB | Blog
F
Fortinet All Blogs

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Stop Letting AI Agents Break Your Database: Transactional...
Machine codi · 2026-05-22 · via DEV Community

Machine coding Master

Stop Letting AI Agents Break Your Database: Transactional Multi-Agent Workflows with Temporal and Spring AI

In 2026, AI agents are no longer just glorified chatbots summarizing PDFs; they are executing real-world financial transactions, booking flights, and mutating production databases. But when an LLM tool call succeeds and the subsequent step fails due to a rate limit or a hallucinated parameter, you cannot just throw a 500 Internal Server Error and leave your database in an inconsistent state.

Why Most Developers Get This Wrong

  • Relying on @Transactional: Standard database transactions completely fail when dealing with asynchronous, non-blocking, and external LLM API calls.
  • Trusting LLMs to "Self-Correct": Believing that a Claude 3.5 or GPT-4o agent can reliably invoke its own "undo" tools when a downstream system fails is a recipe for data corruption.
  • Homegrown State Machines: Writing fragile, database-backed polling mechanisms to orchestrate agent retries and rollback states instead of using durable execution.

The Right Way

Treat LLM tool execution as a series of distributed, unreliable steps orchestrated by a Temporal workflow using the Saga pattern.

  • Decouple Brains from State: Use Spring AI's ChatClient to handle the non-deterministic reasoning and tool routing, but let Temporal handle the execution state.
  • Register Compensations Immediately: For every successful tool execution, register its compensating rollback action inside a Temporal Saga builder.
  • Isolate LLM Calls in Activities: Never call an LLM directly inside a Temporal Workflow method; wrap Spring AI calls in Temporal Activities to keep the workflow deterministic.

Shameless plug: javalld.com has full LLD implementations with step-by-step execution traces — free to use while prepping.

Show Me The Code

Here is how you orchestrate an agentic transaction with Spring AI and Temporal's Saga API:

@WorkflowMethod
public void executeAgenticBooking(String userPrompt) {
    Saga saga = new Saga(new Saga.Options.Builder().build());
    try {
        // Spring AI parses prompt and decides on the tool execution path
        AgentDecision decision = aiActivities.consultLLM(userPrompt);

        bookingActivities.chargeCard(decision.getAmount());
        saga.addCompensation(bookingActivities::refundCard, decision.getAmount());

        bookingActivities.reserveSeat(decision.getSeatId());
        saga.addCompensation(bookingActivities::releaseSeat, decision.getSeatId());
    } catch (ActivityFailure e) {
        saga.compensate(); // Guaranteed, durable rollback across microservices
        throw e;
    }
}

Enter fullscreen mode Exit fullscreen mode

Key Takeaways

  • Deterministic Orchestration: LLMs are inherently non-deterministic; your workflow engine must be 100% deterministic.
  • Spring AI for Mapping, Temporal for Execution: Use Spring AI to bind prompts to Java POJOs, then pass those POJOs to Temporal Activities.
  • Never Trust the Agent: Always assume the LLM will hallucinate a tool parameter at step 3, and design your compensating Sagas to handle the cleanup automatically.