Skip to content
Shell
6.8 KB
Raw Blame

FAILURE_PATTERNS.md

What Breaks and Why

Failures are tuition. This file is the curriculum.


How to Use This File

When something breaks, add it here. When starting something new, scan for relevant patterns. The goal is to fail at new things, not repeat old failures.


Architecture Failures

The Monolith That Should've Been Modular

Pattern: Building everything in one file/component early on, then struggling to untangle. Symptom: Changes in one area break unrelated features. Prevention: Separate concerns early. Even if it's "just a prototype." Recovery: Incremental extraction. Don't rewrite - refactor piece by piece.

The Premature Microservice

Pattern: Splitting into services before you understand the domain. Symptom: Distributed system complexity without distributed system benefits. Prevention: Start monolith, extract services when you feel specific pain. Recovery: Merge back. Seriously. It's okay.

The Shared Database Trap

Pattern: Multiple services writing to the same database tables. Symptom: Mysterious data corruption, unclear ownership, migration nightmares. Prevention: Each service owns its data. Others request through APIs. Recovery: Slow migration to service-owned data. Painful but necessary.


State Management Failures

State Everywhere

Pattern: Component state scattered across the app with no clear source of truth. Symptom: UI shows stale data, sync bugs, "works on my machine." Prevention: Decide on state management approach early. Stick to it. Recovery: Audit all state, consolidate to single source of truth.

The Infinite Re-render

Pattern: State updates triggering state updates triggering state updates. Symptom: Slow UI, browser freezing, useEffect loops. Prevention: Understand your render cycle. Avoid effects that write state. Recovery: Trace the loop. Usually one bad dependency array.


API Failures

The Chatty API

Pattern: Frontend making dozens of requests to render one view. Symptom: Slow load times, waterfall requests, race conditions. Prevention: Design APIs around views/use cases, not just resources. Recovery: Add aggregation endpoints or BFF (Backend for Frontend).

The Breaking Change

Pattern: Changing API response shape, breaking all clients. Symptom: App crashes after "simple" backend change. Prevention: Version your APIs. Add fields, don't remove. Deprecate slowly. Recovery: Hotfix rollback, then proper versioning.

The N+1 Query

Pattern: Fetching a list, then fetching related data one-by-one. Symptom: 100 items = 101 database queries = slow. Prevention: Eager loading, batching, or GraphQL dataloaders. Recovery: Profile queries, add batch fetching.


Frontend Failures

The Component That Does Everything

Pattern: One component handling display, data fetching, state, and business logic. Symptom: 500+ line component, impossible to test, everyone fears touching it. Prevention: Separate concerns: container/presenter, hooks for logic. Recovery: Incremental extraction. One responsibility at a time.

The CSS Specificity War

Pattern: Overriding styles with more and more specific selectors. Symptom: !important everywhere, styles that won't die. Prevention: CSS methodology (BEM, CSS modules, Tailwind). Low specificity. Recovery: Audit and reset. Often easier to rebuild component styles.

The Uncontrolled Form

Pattern: Mixing controlled and uncontrolled inputs without realizing. Symptom: Form values don't update, or update twice, or clear randomly. Prevention: Pick one pattern per form. Controlled is usually clearer. Recovery: Audit inputs, make all controlled (or all uncontrolled).


Data Failures

The Missing Migration

Pattern: Schema changes without proper migration, breaking existing data. Symptom: Old records crash the app. "It works locally." Prevention: Migration scripts. Test against production-like data. Recovery: Write backfill script, fix data, then fix code.

The Null Assumption

Pattern: Assuming data exists when it might be null/undefined. Symptom: "Cannot read property X of undefined" Prevention: Defensive coding. TypeScript helps. Validate at boundaries. Recovery: Add null checks, trace where bad data originates.

The Timezone Bug

Pattern: Storing or displaying times without considering timezones. Symptom: Events showing wrong times, data appearing on wrong days. Prevention: Store UTC, convert for display. Use date library. Recovery: Audit all date handling, standardize to UTC + explicit conversion.


Process Failures

The Missing Acceptance Criteria

Pattern: Building without clear definition of "done." Symptom: Endless revisions, "that's not what I meant." Prevention: Write acceptance criteria before coding. Get sign-off. Recovery: Stop. Clarify. Then proceed.

The Review Bottleneck

Pattern: Big PRs that take forever to review. Symptom: Branches diverge, merge conflicts, stale feedback. Prevention: Small PRs. Daily. Stack if needed. Recovery: Break up the PR. Merge incrementally.

The Silent Failure

Pattern: Errors caught and swallowed, no logging. Symptom: "Something's wrong but we don't know what." Prevention: Log errors. Alert on anomalies. Fail loud in dev. Recovery: Add logging, trace issues, then add monitoring.


Project Failures

The Infinite Planning Phase

Pattern: Researching, discussing, planning... but never building. Symptom: Lots of docs, no code. Weeks pass. Prevention: Timebox planning. Build to learn. Iterate. Recovery: Stop planning. Build the smallest thing. Learn from it.

The Big Rewrite

Pattern: "Let's throw it away and rebuild from scratch." Symptom: New codebase, same problems, plus 6 months gone. Prevention: Incremental improvement. Strangler fig pattern. Recovery: If already started, cut scope ruthlessly. Ship something.

The Creeping MVP

Pattern: MVP scope grows until it's not minimum at all. Symptom: "Just one more feature before launch." Repeat forever. Prevention: Write MVP scope. Lock it. Launch date is real. Recovery: Cut back to original scope. Launch. Iterate.


Adding New Failures

When something breaks:

### [Failure Name]
**Pattern**: What happened / what we did wrong
**Symptom**: How we noticed / what broke
**Prevention**: What we should do next time
**Recovery**: How we fixed it (or would fix it)
**Project**: [Where this happened]
**Date**: YYYY-MM-DD

Remember

"Experience is what you get when you didn't get what you wanted."

Every failure here is a lesson learned. The goal isn't to never fail - it's to fail forward, and never fail the same way twice.