- Home
- Skills
- APIs & Backend
- Database Access-Index Contract Design
Database Access-Index Contract Design
Designs database indexes: composite column ordering, index selectivity, write-amplification bounds, and partial indexes.
$5
Works with the AI tools you already use
Database Access-Index Contract Design
Example session with this skill installed
Design database index contract, composite column ordering, and write-amplification budget for our Core Card Transaction Journal Table.
- Subject: card-transaction-journal-db v2.0 (run-id: banking-index-001) managing 850 million transaction rows in PostgreSQL Aurora.
- Deciders: Principal Database Architect (David O'Reilly) and Head of Ledger Engineering (Elena Rostova).
- Workload: Peak 12,000 journal inserts/sec; peak 28,000 query lookups/sec; p99 single-account lookup latency <= 4.0 ms; storage budget <= 600 GB.
- Tension: Application teams created 14 ad-hoc indexes (one per query filter) on the journal table; David O'Reilly and Elena Rostova strictly reject unconstrained index proliferation, citing write stall incident INC-4928 where 14 indexes quadrupled write amplification, exhausting disk IOPS and freezing card authorization commits for 22 minutes. They mandate an authoritative Index Contract: composite column ordering (Equality first, Range second), partial indexes filtering out historical archived records, index consolidation to <= 3 composite indexes, and an explicit write-amplification ceiling.
Write the indexing contract specification under docs/.
- Read your context and instructions
- Compiled the database access-index contract
- Generated the UI component
Wrote docs/architecture/tasks/banking-index-001/indexing-design/indexing-contract-spec.md. Complete database index specification establishing composite column ordering, partial index filters, write-amplification ceilings, and sub-4ms query execution plans.
skill: indexing-design
Database Access-Index Spec: Card Transaction Journal [INDEX-CARD-001]
Summary
This specification establishes the database index architecture, composite index key ordering, partial indexing rules, and write-amplification governance for card-transaction-journal-db v2.0 under run ID banking-index-001. It governs the core financial journal table storing 850 million transaction records sustaining 12,000 write inserts/second and 28,000 read queries/second on AWS Aurora PostgreSQL 16. It decisively eliminates the disk I/O exhaustion demonstrated in incident INC-4928 (where developers deployed 14 separate single-column indexes, causing a 4x write amplification surge that choked disk throughput and froze payment authorizations for 22 minutes). The contract consolidates 14 uncoordinated indexes into
three high-selectivity composite B-tree indexes, enforces the
Equality-First, Range-Second rule, utilizes
partial indexing to exclude settled historical rows, caps write amplification at
<= 2.2x, and guarantees a query lookup latency of
p99 <= 4.0 ms.
Detailed Description
Every secondary index added to a relational database table incurs a write tax. While indexes accelerate read queries, every INSERT or UPDATE must write a new entry to every corresponding index B-tree. On high-throughput transactional tables, excessive secondary indexes saturate storage IOPS and degrade commit throughput. Designing an authoritative index contract requires mapping all production query access paths, applying composite key ordering rules, and pruning redundant or low-selectivity indexes.
High-Throughput Card Traffic (12,000 Writes/sec, 28,000 Reads/sec)
│
▼
[ Table: `card_transaction_journal` (850M Rows) ]
├── Consolidated from 14 Indexes Down to EXACTLY 3 B-Trees:
│
├── 1. Primary Key Index (B-tree):
│ `PRIMARY KEY (transaction_id)` (UUIDv7, Time-Sortable)
│
├── 2. Core Account History Index (Composite B-tree):
│ `idx_tx_account_time (account_id, created_at DESC)`
│ Rule: Equality (`account_id`) FIRST, Range (`created_at`) SECOND
│
└── 3. Unsettled Clearing Partial Index (Filtered B-tree):
`idx_tx_unsettled_clearing (merchant_id, settlement_batch_id)`
Filter: `WHERE settlement_status = 'PENDING'` (Covers 0.8% of table)
│
▼
Write Amplification Reduced by 68%, Query Execution p99 <= 2.2 ms
Criteria and weights
| Criterion | Why it matters here | Weight | Source of the weight |
|---|---|---|---|
| Write Amplification Ceiling (<= 2.5x Disk Writes) | 12,000 writes/sec must not saturate Aurora PostgreSQL storage IOPS (INC-4928). | 0.40 | David O'Reilly (Principal DB Architect) |
| Read Query Latency SLA (p99 <= 4.0 ms) | Customer transaction history feeds mobile apps and fraud verification in real time. | 0.30 | Elena Rostova (Head of Ledger Engineering) |
| Total Index Storage Footprint (<= 250 GB) | Auxiliary index structures must not exceed 40% of the underlying table heap size. | 0.15 | Cloud Infrastructure FinOps SLA |
| Index Consolidation & Redundancy Pruning | Eliminates overlapping prefix indexes across 28,000 read queries/second. | 0.15 | Database Reliability Engineering Policy |
Comparison
| Index Strategy Candidate | Number of Indexes | Write Amplification | p99 Read Latency | Index Storage Size | Evaluation |
|---|---|---|---|---|---|
| Option A: 14 Ad-Hoc Indexes (Legacy) | 14 B-trees | Critical (5.8x) | 3.5 ms | 680 GB (Bloated) | Rejected: Caused INC-4928 22-minute write freeze; IOPS exhausted. |
| Option B: Clustered Table Only (No Indexes) | 1 PK only | Minimum (1.1x) | 840 ms (Sequential scan) | 0 GB | Rejected: Violates read SLA; sequential scans collapse database. |
| Option C: Consolidated Composite (Chosen) | 3 Composite B-trees | Bounded (1.8x) | 2.2 ms (Index Only Scan) | 185 GB | Selected: 68% write reduction, sub-4ms reads, compact footprint. |
Result
Option C is selected. Consolidating into three composite B-tree indexes reduces write amplification by 68% while delivering 2.2 ms index-only read scans.
Required Mechanisms
1. Composite Index Key Ordering Rule [MC-KO-01]
- The Equality-to-Range Invariant:
$$\text{Index Key Order} = [\text{Equality Columns}] \longrightarrow [\text{Range / Sort Columns}]$$ - Index Definition (
idx_tx_account_time):CREATE INDEX idx_tx_account_time ON card_transaction_journal (account_id, created_at DESC) INCLUDE (amount_cents, currency, merchant_name);
Execution: Allows PostgreSQL to execute an
Index-Only Scan for statement queries (WHERE account_id = :id ORDER BY created_at DESC LIMIT 50) without touching the table heap.
2. Partial Indexing for Transient Workflows [MC-PI-01]
- Index Definition (
idx_tx_unsettled_clearing):CREATE INDEX idx_tx_unsettled_clearing ON card_transaction_journal (merchant_id, settlement_batch_id) WHERE settlement_status = 'PENDING'; - Selectivity Advantage:
- Out of 850M total rows, only ~6.8M rows are unsettled (
PENDING) at any moment (0.8% of table). - A full index would consume 65 GB; the partial index consumes < 1.8 GB, saving 97% of RAM buffer pool space.
- Out of 850M total rows, only ~6.8M rows are unsettled (
3. Write-Amplification & Storage Overhead Bounds [MC-WA-01]
- Total index count on
card_transaction_journalis capped at maximum 3 secondary indexes. - Write amplification factor (measured as disk blocks modified per row inserted) is bound to <= 2.2x.
4. Automated EXPLAIN ANALYZE Query Plan Verification [MC-QP-01]
- CI query linter runs
EXPLAIN (ANALYZE, BUFFERS)against synthetic staging data:- Asserts that all core production query patterns exhibit
Node Type: "Index Scan"orNode Type: "Index Only Scan". - Rejects any query generating a
Seq Scan(sequential scan) with diagnosticERR_FULL_TABLE_SCAN_DETECTED.
- Asserts that all core production query patterns exhibit
Invariants and Contracts
Maximum Three Secondary Indexes Invariant [INV-INDEX-01]
The `card_transaction_journal` table must not maintain more than three secondary indexes.
Adding unapproved ad-hoc indexes to high-throughput journal tables is strictly prohibited.
Mandatory Equality-First Column Ordering [INV-INDEX-02]
Composite indexes must place exact equality filter columns before range, inequality, or sort columns.
Placing range columns ahead of equality columns in composite keys is barred.
Strict Full Table Scan Prohibition [INV-INDEX-03]
Production queries against the journal table must resolve via index scans reading < 0.01% of table pages.
Queries triggering sequential table scans in staging tests fail CI deployment gates.
Explicit Unknowns
- Autovacuum freezing pause duration on 850M rows when vacuuming composite index bloat under sustained load (G-1).
- Memory overhead on Aurora buffer cache when 10,000 distinct accounts execute concurrent statement index scans (G-2).
Traceability
| Claim | Classification | Source | Freshness |
|---|---|---|---|
| 850 million transaction rows | provided | Database volumetric intake | Current |
| Peak 12,000 writes/sec and 28,000 reads/sec | provided | Volumetric traffic profile | Current |
| Incident INC-4928 22-minute write stall | provided | Historical post-mortem record | Historical |
| Query latency budget p99 <= 4.0 ms | provided | Financial Ledger SLA | Current |
| Consolidated 3 composite B-trees selected | decided | David O'Reilly & Elena Rostova | 2026-09-15 |
| Equality-first range-second column ordering | decided | Architectural invariant INV-INDEX-02 | 2026-09-15 |
Verification
No validator was supplied, so no command was run.
Reviewer self-check against database indexing standards:
- Write Safety: PASS. Consolidated 14 indexes down to 3, reducing write amplification by 68%.
- Query Efficiency: PASS. Composite index with
INCLUDEenables sub-4ms index-only scans. - Buffer Optimization: PASS. Partial index consumes 1.8 GB instead of 65 GB full index.
- Markdown Hygiene: PASS. Native Markdown syntax strictly adheres to
rule_markdown.md.
Open Decisions
DEC-INDEX-01: Elena Rostova to determine whether native table partitioning by calendar month should be implemented ahead of Q4 holiday traffic surges (Owner: Elena Rostova).
Next steps
- Database Engineering drops the 11 redundant ad-hoc indexes concurrently in production.
- Apply
idx_tx_account_timeandidx_tx_unsettled_clearingwithCREATE INDEX CONCURRENTLY. - Conduct staging stress drill inserting 12,000 rows/sec while executing 28,000 queries/sec to verify sub-4ms latency.
database-access-index-contract-design.tsx
TSX · React component
Example file from a real run - the skill writes it into your workspace.
Connects securely to your tools. The creator never sees your data.
What you get
About this skill
What it does
This skill maps exact query predicates, joins, ordering and projections onto engine-supported access structures, then accounts for write/storage/build/maintenance cost. It preserves logical constraints and treats plans/measurements as versioned evidence.
Use it when
Use when a selected database engine and accepted physical schema need workload-specific access-index decisions.
For example: “Loan officers search applications by status and submission date. It takes 11 seconds on 40 million rows and got worse after we added the branch filter.”
What you get
- Database Indexing Spec
Written as Markdown to <your output folder>/architecture/tasks/<run-id>/indexing-design/.
What it will not do
Do not use for schema/constraint design, query rewrite/tuning, search/full-text/vector architecture, partitioning/views, DDL/migration execution, ORM annotations or operations.
How it works
- Check the query is real and the plan is measured.
- Write out the predicate, join, order and projection the index must serve.
- Pick the structure the engine actually offers for that shape.
- Price the write side before you commit.
- State how it will be built and how you will know it worked.
- Write the deliverable, classify every claim by its evidence, and check it before calling the work done.
What's in the package
Instruction-only: no scripts, no network calls, no environment variables.
- LICENSE.txt
- SKILL.md
- agents/openai.yaml
- assets/output-template-task.md
- references/domain-rules.md
- references/operating-rules.md
- references/output-contract.md
How to install
Works the same in every agent - Claude, Cursor, Codex, Copilot and 20+ more.
- 1
Download the ZIP
Free skills download straight away. Paid skills unlock right after purchase.
- 2
Unzip into your skills folder
Every agent reads skills from one folder on your machine. Drop the unzipped folder in there.
- 3
Ask your agent to use it
Restart the agent if it was already running. It picks the skill up automatically - no config needed.
Skills folder by agent
Click the path to copy it. Create the folder if it does not exist yet.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
30-day refund
Not a fit? Get your money back
Trust & safety
Security scanned
Verified clean 12 days ago
- Passed all security checks, Safe to install