Design Review
Iron Law
CATCH IT IN THE PLAN, NOT IN THE PR
A plan that implies N+1 queries will produce N+1 queries. A plan that omits error
handling will produce code with no error handling. Review the plan as rigorously as
the code: every implementation decision follows it.
Anti-Pattern Detection Rules
A concrete case is an external call in this change, a stated or measured hot path, or a repeated delivery.
1. N+1 Queries
What to look for in a plan:
- Steps that fetch a list, then loop to fetch related data per item
- "For each X, get Y" or "Display X with Y" language, with no JOIN or batch fetch named
How to flag:
[N+1 RISK] Step {N}: "{quoted plan text}" — fetches {entity} per iteration.
Resolution: Replace loop with batch query: {proposed batch operation}.
Suggest: collect the IDs first and batch-fetch the related rows in one query, or eager-load them (JOIN) in the list query.
2. God Functions
What to look for in a plan:
- Single step handling more than 3 distinct responsibilities
- "Validate AND process AND notify AND log AND update" in one step
- Steps described as "the main handler" that touch multiple subsystems
- No one-sentence description of what the function does
How to flag:
[GOD FUNCTION RISK] Step {N}: "{quoted plan text}" — handles {n} responsibilities.
Resolution: Split into: {responsibility 1} → {responsibility 2} → {responsibility 3}.
Suggest: one purpose per function; move notification, logging and other side effects to their own functions, and compose them at the service layer.
3. Missing Parallelism
What to look for in a plan:
- Sequential steps with no data dependency between them ("First do A, then B, then C")
- Multiple external API calls or DB queries listed sequentially
- Fan-out operations (notify all users, update all records) without parallel mention
How to flag:
[SEQUENTIAL BOTTLENECK] Steps {N}-{M}: "{quoted steps}" — no dependency between them.
Resolution: Execute {step A} and {step B} in parallel: {proposed parallel pattern}.
Suggest: run independent steps in parallel (Promise.all, goroutines, asyncio.gather), and name the steps that must stay in order.
4. Error Handling Gaps
What to look for in a plan:
- Happy path fully described, failure paths absent or vague
- "If error, return error" without specifying what the caller does with it
- Partial operations (multi-step) that can lose data, without rollback plan
- External calls (API, DB, queue) without failure mode specification
- Retry or compensation absent: a finding only with a concrete case. Error handling at a trust boundary or for data loss needs no case.
How to flag:
[ERROR HANDLING GAP] Step {N}: "{quoted plan text}" — failure path unspecified.
Resolution: Add: {on failure scenario} → {specific recovery action}.
Suggest: for each external call, the action on timeout, 4xx and 5xx; a compensation step only for a partial write that loses data; Result types or explicit error returns, never a silent failure.
5. Missing Caching
What to look for in a plan:
Only with a concrete case; else no finding.
- "Fetch configuration on each request", "call third-party API per user action"
- Reference data (categories, settings, permissions) loaded repeatedly
- Computed aggregates recalculated on every read
How to flag:
[CACHING GAP] Step {N}: "{quoted plan text}" — {expensive operation} on every request.
Resolution: Cache {data} for {TTL}: {proposed cache strategy and invalidation}.
Suggest: an application cache for cross-request data, a short-TTL in-memory cache for process-local reference data, and the invalidation (on update, by TTL, or both).
6. Poor Decomposition
What to look for in a plan:
- Steps combining unrelated concerns (auth + business logic + presentation)
- Unclear ownership — which module/layer owns each step?
- Cross-cutting steps that appear multiple times without abstraction
- "Also update X" or "also send to Y" appended to otherwise focused steps
How to flag:
[DECOMPOSITION ISSUE] Step {N}: "{quoted plan text}" — combines {concern A} and {concern B}.
Resolution: {concern A} belongs in {layer/module}; {concern B} belongs in {layer/module}.
Suggest: one layer per step (presentation, business logic, data access); cross-cutting concerns (logging, auth, validation) in middleware or decorators; one bounded context per module.
Extended References
| Reference | Content |
|-----------|---------|
| references/anti-patterns.md | Before/after plan examples for each anti-pattern |
Severity Guidelines
| Level | An anti-pattern that |
|-------|----------|
| CRITICAL | will cause correctness failures (data loss, security breach) |
| HIGH | will cause significant performance or maintainability problems |
| MEDIUM | will require architectural rework post-implementation |
| LOW | reduces code quality but is easily refactored |