Databases
Overview
Databases store application state and define many of the constraints that shape product behavior.
Why It Matters
Even frontend engineers need enough database understanding to debug data issues and reason about latency.
Core Concepts
- Data integrity matters.
- Indexes affect performance.
- Transactions protect multi-step changes.
Mental Models
Ask what data must be correct forever versus what can be recomputed.
Best Practices
- Model clear ownership of data.
- Avoid unbounded queries.
- Respect migrations and backward compatibility.
Common Mistakes
- Fetching more data than needed.
- Ignoring indexes until performance fails.
- Making schema changes without rollout planning.
Trade-offs
Denormalization can speed reads, but it increases consistency work.
Decision Framework
| Question | Check |
|---|---|
| Is the data critical? | Use constraints and transactions |
| Is the data read often? | Consider indexes or caching |
| Is the schema changing? | Plan backward compatibility |
Examples
- A duplicate user row should be prevented by a database constraint, not just app code.
Checklists
- Are constraints protecting the data?
- Are queries indexed appropriately?
- Is the migration safe to roll out?
Senior Engineer Notes
Senior engineers understand that the database is part of the product contract, not an implementation detail.