Skip to content
majiayu000 avatar

Database Patterns

Database schema, indexing, and caching patterns for PostgreSQL with Redis, covering data types, JSONB, and cache consistency.

CCM score
56 of 100
skills.sh installs
146
GitHub stars
301
last updated
Jun 3, 2026
View on GitHub

Own this skill? Claim it

What it does

  • Covers PostgreSQL data type choices, schema design, indexing strategy, JSONB usage, and query optimization with EXPLAIN ANALYZE
  • Includes Redis data structure selection, key naming conventions, TTL strategy, and cache-aside, write-through, and invalidation patterns
  • Provides cache stampede and cache penetration prevention code, including lock-based loading and short-lived null caching
  • Designed for backend teams choosing between relational and cached storage when modeling data and planning caching behavior

Install

$ npx -y skills add majiayu000/spellbook --skill database-patterns -y

Installs into .agents/skills for every agent it finds here, and .claude/skills for Claude Code.

Files

Database Patterns

Core Principles

  • PostgreSQL Primary — Relational data, transactions, complex queries
  • Redis Secondary — Caching, sessions, real-time data
  • Index-First Design — Design queries before indexes
  • JSONB Sparingly — Structured data prefers columns
  • Cache-Aside Default — Read-through, write-around
  • Tiered Storage — Hot/Warm/Cold data separation
  • No backwards compatibility — Migrate data, don't keep legacy schemas

PostgreSQL

Data Type Selection

Use CaseTypeAvoid
Primary KeyUUID / BIGSERIALINT (range limits)
TimestampsTIMESTAMPTZTIMESTAMP (no timezone)
MoneyNUMERIC(19,4)FLOAT (precision loss)
StatusTEXT + CHECKINT (unreadable)
Semi-structuredJSONBJSON (no indexing)
Full-textTSVECTORLIKE '%..%'

Schema Design

-- Use UUID for distributed-friendly IDs
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

Details

Repository
github.com/majiayu000/spellbook
Categories
Databases, Backend & APIs
First seen
Jun 3, 2026

More from majiayu000/spellbook

All 8

Similar to Database Patterns

More Databases