Tips in Database

Explore all tips and tutorials about Database.
shape
shape
shape
shape
shape
shape
shape
shape

Database Hard

Cache Stampede Prevention: Locks, XFetch, Stale-While-Revalidate and Laravel Cache::flexible

Why a hot key expiring can melt your database, and four fixes: Cache::lock with double-check, XFetch early expiration, Cache::flexible, and TTL jitter.

Laravel 13 PHP 8.4 Redis 7.4
Diagram Try the challenge
11 min Read tip
Database Medium

Optimistic Locking With a Version Column: Fix Lost Updates in Laravel (vs lockForUpdate)

Two users save the same record and one change silently disappears. Fix lost updates with a version column, 409 responses and retries, and know when lockForUpdate fits better.

Laravel 13 PHP 8.4 Mysql 8.4
Diagram Try the challenge
10 min Read tip
Database Hard

Transaction Isolation Levels: Dirty, Non-Repeatable and Phantom Reads in MySQL and PostgreSQL

Why DB::transaction() did not stop your oversold stock: what each isolation level guarantees in MySQL vs PostgreSQL and how to pick one in Laravel.

Laravel 13 PHP 8.4 Mysql 8.4
Diagram Try the challenge
11 min Read tip
Database Medium

Offset vs Cursor Pagination: Why Page 4,000 Is Slow and How Keyset Queries Fix It

OFFSET makes deep pages slow and shuffles rows when data changes. Learn keyset queries, composite cursors, Laravel cursorPaginate and cursor-based API design.

Laravel 13 PHP 8.4 Mysql 8.4
Diagram Try the challenge
11 min Read tip
Database Hard

Database Deadlocks: Detection, Diagnosis, and Prevention

How relational databases detect deadlocks with wait-for graphs, why they happen, and concrete techniques to prevent them in high-concurrency systems.

Postgresql 13+
Diagram
5 min Read tip
Database Hard

Distributed Locking with Redis: Understanding the Redlock Algorithm

A deep dive into the Redlock algorithm for safe distributed locking across multiple Redis nodes, including failure modes, clock drift, and the fencing token fix.

Redis 7.x
Diagram
6 min Read tip
Database Medium

Redis Caching Strategies: Cache-Aside vs Write-Through

Compare cache-aside and write-through caching with Redis, including consistency trade-offs, TTL strategy, and when to use each pattern.

Redis 7.x
Diagram
4 min Read tip
Database Medium

Database Indexes: Turn a Full Scan Into an Instant Lookup

See why a query without an index scans every row, how an index turns it into a fast lookup, and how to read EXPLAIN to tell the difference.

SQL ANSI / MySQL 8+
Diagram
2 min Read tip