Skip to content
StackPractices

Tag: databases

Browse 49 practical software engineering resources tagged with "databases". Discover code recipes, design patterns, documentation templates, and in-depth guides to help you build, deploy, and maintain production-ready solutions involving databases.

Cursor-Based Pagination with PostgreSQL

Implement efficient cursor-based pagination for large datasets in PostgreSQL, avoiding OFFSET performance degradation with indexed keyset pagination and stable sort ordering

Multi-Tenancy Architecture

Design multi-tenant applications with shared or isolated databases, tenant-aware routing, and data isolation strategies.

UUID Generation: v4, v7, and ULID Comparison

Compare UUID v4, v7, ULID, and nanoid for generating unique identifiers with different tradeoffs in randomness, sortability, performance, and database index locality

Implement ACID Transactions in PostgreSQL

How to use PostgreSQL transactions to ensure Atomicity, Consistency, Isolation, and Durability for reliable multi-step database operations

Caching with Redis

How to implement application caching using Redis for performance and scalability.

Connect to MySQL

How to connect to MySQL databases in Python, JavaScript, and Java.

Connect to PostgreSQL

How to connect to PostgreSQL databases in Python, JavaScript, and Java.

Connect to Redis

How to connect to Redis and perform basic operations in Python, JavaScript, and Java.

Database Connection Pooling

Configure and tune database connection pools to maximize throughput while preventing connection exhaustion.

Handle Database Deadlocks and Retries

Detect, prevent, and recover from database deadlocks with automatic retry logic, isolation levels, and query ordering strategies.

Manage Database Migrations Safely

How to version, apply, and rollback database schema changes using migration tools like Flyway, Alembic, and Liquibase in production environments.

Database Migrations Safely

How to run database schema migrations without downtime or data loss.

Set Up Database Read Replicas for Scaling

Scale read-heavy workloads with database read replicas, replication lag monitoring, and read/write splitting across primary and replica instances.

Database Replication

Set up and manage database replication for high availability, read scaling, and disaster recovery with primary-replica architectures.

Database Transactions

How to use ACID transactions to ensure data integrity across Python, JavaScript, and Java with SQL examples.

Create and Use Database Views and Materialized Views

How to create and use database views and materialized views to simplify queries and improve read performance

Prevent and Resolve Deadlocks in SQL Transactions

Identify deadlock patterns in SQL databases, apply consistent lock ordering, use appropriate isolation levels, and implement retry logic for resilient concurrent transactions

Elasticsearch Aggregations for Analytics and Search

How to use Elasticsearch aggregations to build faceted search, analytics dashboards, and real-time metrics from indexed data

Implement Event Sourcing in a Relational Database

Build event sourcing systems using relational databases with event stores, projections, and snapshotting for audit and temporal querying.

Execute Raw SQL

How to execute raw SQL queries safely with parameterized statements.

Full-Text Search

How to implement full-text search with Elasticsearch, Meilisearch, and PostgreSQL.

CRUD Operations with MongoDB and Mongoose

How to perform Create, Read, Update, and Delete operations in MongoDB using Mongoose ODM with Node.js and Express

Implement Optimistic Locking with Versioning

How to implement optimistic locking with versioning to prevent lost updates in concurrent database access

PostgreSQL Query Optimization and Indexing Strategies

Analyze and optimize slow PostgreSQL queries using EXPLAIN, proper indexing, partial indexes, and query rewriting to reduce execution time from seconds to milliseconds

Redis Cache Patterns for High-Performance Applications

How to implement cache-aside, write-through, and write-behind patterns with Redis to reduce database load and improve response times

Database Schema Evolution

Evolve database schemas safely with backward-compatible changes, versioned migrations, and online DDL operations in production environments.

Seed Database

How to seed databases with realistic data for development, testing, and staging environments using seed scripts, migrations, and factories across PostgreSQL, MongoDB, and Prisma.

Soft Deletes

How to implement soft deletes to preserve data while hiding records from normal queries.

SQL Joins

Practical examples of INNER, LEFT, RIGHT, and FULL OUTER JOINs with real-world query patterns.

Use ORM for CRUD

How to perform CRUD operations using ORMs in Python, JavaScript, and Java.

Composite Entity Pattern

Map a coarse-grained entity to multiple database tables by composing dependent objects, reducing the number of fine-grained remote calls in EJB and distributed systems.

Data Mapper Pattern

Separate in-memory domain objects from the database by delegating persistence to a dedicated mapper layer, keeping models framework-agnostic.

Database per Service Pattern

Give each microservice its own private database to ensure loose coupling, independent deployment, and technology heterogeneity across the application portfolio.

Eager Loading Pattern

Load related data in a single query rather than multiple round-trips, preventing the N+1 problem and improving read performance.

Identity Map Pattern

Ensure each object is loaded only once per transaction by caching instances by their primary key, preventing duplicate in-memory representations of the same database row.

Materialized View Pattern

Precompute and store expensive query results in a read-optimized cache to avoid repeated costly aggregation or joins across large datasets.

Sharding Pattern

Split a large dataset into smaller partitions (shards) distributed across multiple servers to improve growth, performance, and availability beyond single-node limits.

Unit of Work Pattern

Track changes to in-memory objects during a business transaction and commit all updates atomically to the database, ensuring consistency.

Database Migration Runbook Template

A database migration runbook template for executing schema changes safely with rollback procedures, verification steps, and communication plans.

CAP Theorem and Database Trade-offs

A practical guide to the CAP theorem: consistency, availability, and partition tolerance. Learn how to choose the right trade-offs for your application.

Complete Guide to Database Sharding

Master database sharding. Covers range-based, hash-based, and directory-based partitioning strategies, consistent hashing, shard key selection, cross-shard queries, resharding, Vitess, Citus, and when to shard vs scale vertically with practical examples.

Complete Guide to Elasticsearch Cluster Setup

Deploy and scale Elasticsearch clusters. Covers node roles, sharding, replicas, index templates, mapping, snapshots, and production tuning for search at scale.

Complete Guide to MongoDB Indexing

Master MongoDB indexing. Covers single field, compound, text, geospatial, TTL, wildcard, hashed indexes, ESR rule, covered queries, explain plan analysis, index intersection, and partial indexes with practical examples.

Complete Guide to PostgreSQL Replication

Master PostgreSQL replication. Covers streaming replication, logical replication, cascading replicas, synchronous commit, failover with Patroni, monitoring lag, slot management, and disaster recovery with practical configuration examples.

Complete Guide to PostgreSQL Tuning

Optimize PostgreSQL for high throughput. Covers configuration tuning, indexing strategies, query optimization, connection pooling, partitioning, and vacuum management.

Complete Guide to Redis in Production

Run Redis in production. Covers persistence (RDB, AOF), clustering, sentinel for HA, failover handling, memory management, eviction policies, pipelining, Lua scripting, monitoring, security hardening, and backup strategies with practical examples.

Complete Guide to SQL Query Optimization

Optimize SQL queries. Covers EXPLAIN plan analysis, index strategies, join optimization, N+1 query detection, query rewriting, materialized views, partitioning, connection pooling, and query caching with practical PostgreSQL and MySQL examples.

Database Sharding and Partitioning Strategies

A practical guide to horizontal partitioning (sharding), vertical partitioning, and range vs hash strategies. Scale databases without downtime.

Complete Guide to Serverless Databases

Choose and operate serverless databases for event-driven applications. Covers DynamoDB, Aurora Serverless, FaunaDB, and PlanetScale with pricing, scaling, query patterns, and migration strategies.