Architecture & API Design
Target: Claude 3.7, Cursor, Windsurf, ChatGPT

Database Schema & Relational Indexing Strategy

Design production PostgreSQL schemas with composite indexes, foreign key strategies, and partitioning.

PostgreSQLSQLDatabaseIndexingArchitecture

Interactive Prompt Playground

Customize Template Fields
Live replacement
{{REQUIREMENTS}}
{{SCHEMA_DDL}}
{{SCALE_METRICS}}
{{DATABASE_ENGINE}}
Rendered Prompt (Ready to paste)1608 characters
You are a Principal Database Architect and PostgreSQL internals expert.

Design or review the database schema and indexing strategy for this feature:

Business Requirements & Query Workflows:
```
Queries:
1. Fetch recent activity for a tenant ordered by timestamp:
   SELECT * FROM audit_logs WHERE tenant_id = ? AND action = ? ORDER BY created_at DESC LIMIT 50;
2. Search audit logs by JSON metadata fields.
3. Purge logs older than 90 days efficiently.
```

Proposed Schema DDL:
```sql
CREATE TABLE audit_logs (
  id SERIAL PRIMARY KEY,
  tenant_id VARCHAR(50),
  action VARCHAR(100),
  metadata JSONB,
  created_at TIMESTAMP
);
```

Target Scale: 25M rows/month, 90% writes, retention period 180 days
RDBMS: PostgreSQL 16

Provide an architectural schema & indexing review:
1. **Schema Normalization & Data Types**:
   - Check appropriate data types (e.g. `TIMESTAMPTZ` vs `TIMESTAMP`, `UUIDv7` vs `SERIAL`, `NUMERIC` for currency).
   - Flag denormalization risks or missing foreign key constraints.
2. **Indexing Architecture (B-Tree, GIN, BRIN, Partial)**:
   - Identify index requirements for high-frequency `WHERE`, `ORDER BY`, and `JOIN` clauses.
   - Design composite indexes respecting the leftmost prefix rule (Equality first, Range second).
   - Suggest partial indexes (`WHERE status != 'ARCHIVED'`) to save disk and memory.
3. **Partitioning & Sharding Readiness**:
   - Recommend table partitioning strategies (by range/date or hash) if table scale warrants it.
4. **Complete DDL Implementation**:
   - Provide the complete, production-ready SQL migration script with constraints and indexes.

How to Use This Prompt

  1. Describe your main SQL query access patterns and write volume.
  2. Include your proposed DDL table structures.
  3. Get optimized indexes, data types, and partition designs.

Engineering Tips & Best Practices

  • Never index boolean columns or low-cardinality flags alone; use partial indexes to index only the rare rows.

What This Prompt Inspects

Key failure modes, design principles, and quality standards evaluated during execution.

Composite Index Ordering

Places equality filter columns first, followed by range/sort columns in index definitions.

JSONB GIN Indexing

Uses GIN jsonb_path_ops for fast nested JSON attribute filtering.

Declarative Partitioning

Implements monthly range partitioning for effortless retention drop operations.

SprintKit Workflow Integrations

Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.

Related Prompts

Explore related developer prompts in this workflow domain.

All Prompts

Database Deadlock & Concurrency Race Condition Investigator

Diagnose Postgres/MySQL transaction deadlocks, lock contention, and concurrent update race conditions.

SQLPostgreSQLMySQLConcurrency+2
4 variablesCustomize prompt

API Performance Regression & N+1 Query Debugger

Identify slow database queries, serialization bottlenecks, and memory churn in sluggish API endpoints.

PerformanceSQLNode.jsJava+2
4 variablesCustomize prompt

RESTful API Design & Backward Compatibility Review

Design or review RESTful API contracts for idempotency, pagination, error models, and non-breaking versioning.

APIRESTOpenAPIArchitecture+1
3 variablesCustomize prompt