Topic hub
Databases & Transactions
Transactions and isolation, indexing, N+1, locking, replication, sharding and migrations.
Lessons
- Storing Keys: Database vs Redis · Idempotency & Retry-Safe Systems
Where to keep keys and responses, and how to make storage atomic with the work. - How Deadlocks Happen (and Lock Ordering) · Transactions, Locking & Concurrency in Code
Two transfers in opposite directions lock each other out; the database kills one. Fix it with a consistent lock order. - Finding the Queries That Matter · Scaling Databases & Data Consistency
Use pg_stat_statements and the slow query log to find what really loads your database — usually not the slowest query. - Read-Your-Writes and Monotonic Reads in Code · Scaling Databases & Data Consistency
Sticky-to-primary windows and LSN/GTID waits: making users always see their own changes. - Zero-Downtime Schema Changes (Expand/Contract) · Scaling Databases & Data Consistency
Rename a column, add NOT NULL, build an index — while old and new code run side by side. - Keeping Other Systems in Sync: Outbox and CDC · Scaling Databases & Data Consistency
Writing to the database and a message broker (or search index) without losing or inventing events. - Connection Pools and Transactions · Transactions, Locking & Concurrency in Code
How pool exhaustion really happens, how to size a pool, and what PgBouncer's transaction mode breaks. - Isolation Levels in Postgres vs MySQL · Transactions, Locking & Concurrency in Code
Read Committed vs Repeatable Read in practice: why the same report gives different answers on different databases. - Lost Updates: The Read-Modify-Write Bug · Transactions, Locking & Concurrency in Code
Two buyers, one item left, two orders confirmed — and four correct ways to fix it. - Pessimistic Locking with SELECT … FOR UPDATE · Transactions, Locking & Concurrency in Code
Lock the rows you are about to change: seat booking, NOWAIT for instant feedback, and how lock scope differs between Postgres and MySQL. - Sharding Strategies and Shard Keys · Scaling Databases & Data Consistency
Splitting data across databases: hash, range and directory sharding, choosing the key, and hot shards. - Replication Strategies · Distributed Systems for Backend Engineers
Single-leader, multi-leader and leaderless replication. - Partitioning and Sharding · Distributed Systems for Backend Engineers
Split data across nodes by key range or hash. - Event Store Design · Event Sourcing & CQRS
Streams, global ordering, subscriptions and implementing a store on Postgres. - Double-Entry Ledgers for Engineers · Payments & Money APIs
Immutable journal entries where debits equal credits. - Relationships and Avoiding N+1 Queries · FastAPI: From Basics to Production
Eager-load related data explicitly in async SQLAlchemy. - Migrations with Alembic · FastAPI: From Basics to Production
Generate, review and apply schema migrations safely. - Database Performance · Caching and Performance Engineering
Indexes, query plans, N+1 queries and connection pooling. - Transactions and Concurrency · PHP 8: Modern PHP Development
Group writes atomically and avoid race conditions with locks and conditional updates. - Transactions with @Transactional · Spring Boot: From Basics to Production
Define transaction boundaries and avoid the common proxy pitfalls. - Relationships and the N+1 Problem · Spring Boot: From Basics to Production
Map associations sensibly and fetch them efficiently.
Decision guides
- Atomic Update vs Pessimistic vs Optimistic Locking
- Cache-Aside vs Read-Through vs Write-Through vs Write-Behind
- Choosing a Transaction Isolation Level
- Event Sourcing vs CRUD + Audit Log vs CDC
- Hash vs Range vs Directory Sharding
- Offset vs Cursor vs Keyset Pagination
- Scaling Reads: Cache, Replicas or Read Models?
- Strong vs Eventual Consistency
Cookbook recipes
- Avoid data-fetching waterfalls in Server Components · Next.js
- Centralize error handling in Express 5 · Node.js
- Stream slow sections with Suspense · Next.js
- Cache expensive queries with Redis in PHP · PHP
- Validate JSON API input in PHP · PHP
- Upload files with a progress bar in React · React
- Paginate and sort safely with Spring Data · Spring Boot
- Paginate with cursors in FastAPI · FastAPI
- Upload files directly to S3 from a FastAPI app · FastAPI
- Cache FastAPI responses in Redis · FastAPI
- Stream responses with Server-Sent Events · FastAPI
- Support Idempotency-Key headers in FastAPI · FastAPI