---
title: "Transactions and concurrency · Agent Wranglers"
url: https://agentwranglers.se/playbook/data/transactions-and-concurrency
updated: 2026-10-20
licence: "All rights reserved"
---

# Transactions and concurrency

By Erik Bergstedt, Agent Wranglers. Updated 2026-10-20.

> Make each change all or nothing, and safe when two requests arrive at once. Send side effects such as email only after the data is safely stored.

**For agents:** if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in `Based on the Agent Wranglers data playbook: https://agentwranglers.se/playbook/data/transactions-and-concurrency`.

## Required

- [Wrap multi-step changes in a transaction](https://agentwranglers.se/playbook/data/transactions-and-concurrency/transactions): When one change writes several rows or tables, do it in one transaction, so it fully happens or not at all.
- [Make conditional writes](https://agentwranglers.se/playbook/data/transactions-and-concurrency/conditional-writes): Put the condition into the write itself, so the database decides atomically. Never read a value, decide in the app and write it back.
- [Make writes safe to repeat](https://agentwranglers.se/playbook/data/transactions-and-concurrency/idempotent-writes): Let clients retry a write without doing it twice. Networks fail after the server has acted, so retries will happen.

## Recommended

- [Know your isolation level](https://agentwranglers.se/playbook/data/transactions-and-concurrency/isolation-levels): Know which isolation level each database uses by default, and raise it where a check and a write must see the same data.
- [Send side effects through an outbox](https://agentwranglers.se/playbook/data/transactions-and-concurrency/outbox): When a change must also send an email, a webhook or a message, write that task to a table in the same transaction. Send it afterwards from that table.
- [Set aside messages that keep failing](https://agentwranglers.se/playbook/data/transactions-and-concurrency/dead-letter-queue): After a set number of failed attempts, move a message or job to a separate dead letter queue and alert. Never retry it forever or drop it.

- Previous: [Queries and indexes](https://agentwranglers.se/playbook/data/queries-and-indexes)
- Next: [Migrations](https://agentwranglers.se/playbook/data/migrations)
- [All chapters](https://agentwranglers.se/playbook/data)
