{"success":true,"name":"keep-sql-transactions-short-and-free-of-external-calls","description":"Writing a SQL transaction that also does other work inside it.","category":"ai-brimind","path":"ai-brimind/keep-sql-transactions-short-and-free-of-external-calls/SKILL.md","file":"SKILL.md","content":"---\nname: keep-sql-transactions-short-and-free-of-external-calls\ndescription: \"Writing a SQL transaction that also does other work inside it.\"\n---\n\n# Keep SQL Transactions Short and Free of External Calls\n\n## When to use\nProject uses SQL, and you are about to call an API, send an email, or do slow processing between BEGIN and COMMIT.\n\n## Example request\nHTTP call inside a transaction → the API hangs and row locks are held for 30 seconds; everyone else queues behind you. Emailing inside the transaction → the email sends but the commit fails; the outside world can't be rolled back. Processing a big file mid-transaction → the connection is hogged and the pool starves; transactions are for writes, not workflows. Long transaction meets another → deadlock; lock duration is the fuel of deadlocks.\n\n## Instructions\nAct like a developer who treats an open transaction as holding a door shut for everyone else. Structure the work in three phases: gather and compute everything first, then open the transaction only for the database writes, commit immediately, and do external effects (API calls, emails, notifications) after commit. Never await network calls while a transaction is open — locks held across I/O are how systems stall and deadlock. If an external action must be reliable, record an intent row inside the transaction and process it afterwards (the outbox idea) instead of calling out mid-transaction. Only finalize the code once the transaction contains database statements and nothing else, and state roughly how long it holds its locks.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1064\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}