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

# Data and databases playbook

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

A data and databases playbook for any app that stores information. It covers schema design, queries and indexes, transactions, migrations, backups, personal data, day-to-day operation and caches. A last chapter covers product analytics, from the tracking plan to A/B experiments.

The examples use PostgreSQL, MySQL and SQLite. Where document stores such as MongoDB work differently, the rule says so.

Data outlives code. A bug in a page is fixed with the next deploy, but a bad row can stay wrong for years. So these rules put as much of the checking as possible inside the database itself.

**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`.

## Chapters

1. [Schema design](https://agentwranglers.se/playbook/data/schema-design): Let the database guard its own data. Use constraints, exact types and stable keys, so no bug in any app can store a row that makes no sense. (3 required, 4 recommended)
2. [Queries and indexes](https://agentwranglers.se/playbook/data/queries-and-indexes): Ask the database only for what you need, in one round trip where you can. Index for the queries you run, and read the plan before you guess. (3 required, 3 recommended)
3. [Transactions and concurrency](https://agentwranglers.se/playbook/data/transactions-and-concurrency): 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. (3 required, 3 recommended)
4. [Migrations](https://agentwranglers.se/playbook/data/migrations): Change the schema only through numbered migrations in version control. Run them in the deploy, test them on a copy, and keep old and new code working. (5 required, 1 recommended)
5. [Backups and recovery](https://agentwranglers.se/playbook/data/backups-and-recovery): Encrypt every database backup, keep point-in-time recovery where data changes all day, and prove each backup restores. Schedules and targets live in operations. (2 required, 1 recommended)
6. [Personal data](https://agentwranglers.se/playbook/data/personal-data): Store as little personal data as the job needs, delete it on a schedule and on request, and keep it out of test copies. Know who read it and when. (3 required, 2 recommended)
7. [Operations](https://agentwranglers.se/playbook/data/operations): Keep the database healthy day to day. Pool connections, set time limits, watch slow queries and growth, and let routine maintenance run. (4 required, 2 recommended)
8. [Caches and copies](https://agentwranglers.se/playbook/data/caches-and-copies): Treat every cache, replica and search index as a copy that can be stale or lost. Say how fresh it must be, and keep the source of truth in one place. (2 required, 2 recommended)
9. [Product analytics](https://agentwranglers.se/playbook/data/product-analytics): Plan every event in code and validate it. Keep people out of it, record business facts on the server, and fix experiment rules before the start. (8 required, 1 recommended)

See all 52 rules on one page in the [checklist](https://agentwranglers.se/playbook/data/checklist).
