database-patterns

Design PostgreSQL data models and Redis caching strategies.

258|26|Updated Dec 9, 2025
One-click install
npx skills add https://github.com/majiayu000/claude-arsenal --skill database-patterns-majiayu000
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: database-patterns
Source: https://github.com/majiayu000/claude-arsenal/tree/main/skills/database-patterns
Command: npx skills add https://github.com/majiayu000/claude-arsenal --skill database-patterns-majiayu000

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Designing robust data models and caching strategies is hard. This Skill combines PostgreSQL patterns with Redis caching to improve data models, indexing, and cache consistency.

Core Features & Use Cases

  • PostgreSQL data modeling: Effective data types, JSONB usage, and index strategies.
  • Redis caching patterns: Cache-aside, write-through, and eviction strategies.
  • Indexing & JSONB: Partial, expression, and GIN indexes for fast queries.

Quick Start

Design a users table with JSONB metadata and add a cache-aside layer for user lookups.

Frequently Asked Questions about database-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I design efficient PostgreSQL indexes for large tables?

PostgreSQL indexing strategies depend on query patterns. B-tree indexes work for range queries, GIN indexes optimize JSONB searches, partial indexes reduce size by filtering rows, and expression indexes speed computed columns. Choose based on your access patterns and data distribution.

What's the best way to cache database queries with Redis?

Cache-aside and write-through are the primary Redis caching patterns. Cache-aside checks Redis first, loads from PostgreSQL on miss, and updates the cache. Write-through writes to both systems simultaneously. Select based on consistency requirements and acceptable staleness.

How do I use JSONB effectively in PostgreSQL?

JSONB columns store semi-structured data with GIN indexes for fast lookups. Use JSONB for flexible metadata, nested attributes, or variable schemas while maintaining queryability. Combine with partial indexes to optimize specific JSONB paths.

When should I denormalize data into JSONB instead of separate tables?

Denormalize to JSONB when data is read-heavy, rarely updated independently, or has variable structure. Avoid JSONB for frequently joined data or strict transactional consistency needs. Evaluate query patterns and update frequency before deciding.

How do I handle cache invalidation across PostgreSQL and Redis?

Cache invalidation strategies include time-based expiration (TTL), event-driven invalidation on database writes, and manual cache clearing. Design based on consistency tolerance and update frequency. OLTP systems typically use shorter TTLs or event-driven approaches.

Can I use these patterns for analytics workloads?

Yes. PostgreSQL indexing and JSONB support analytical queries on OLTP data. Redis caching accelerates aggregations and dashboards. However, dedicated analytical databases often outperform PostgreSQL for large-scale analytics—evaluate scale and query complexity first.