Zeeshan Adil
Book a call
← All writing

Databases

PostgreSQL from the inside: locks, query plans, the write-ahead log, sizing and recovery, and what it really takes to run it yourself instead of Aurora.

ARTICLES

Jun 2026 · 35 min read

Aurora Serverless v2 to Self-Managed PostgreSQL: Sizing, WAL, Recovery

A planning guide for leaving Aurora Serverless v2 for self-managed PostgreSQL: what to measure, how to size the machine, and how WAL and recovery change.

Feb 2026 · 25 min read

Choosing Between Optimistic, Pessimistic, Advisory, and Distributed Locks

When to use SELECT FOR UPDATE, version checks, Postgres advisory locks or Redis locks, and which failures each one survives. Includes fencing tokens for expired leases.

Jan 2026 · 22 min read

When RabbitMQ Isn't Enough: Building Durable, Retryable Jobs

Database-backed jobs with atomic claiming, backoff, circuit breakers and an outbox, and what each piece does and does not guarantee.

Oct 2025 · 15 min read

Diagnosing Slow PostgreSQL Queries with EXPLAIN ANALYZE and BUFFERS

How to find and fix a slow PostgreSQL query: read EXPLAIN (ANALYZE, BUFFERS), check row estimates, then choose indexes, statistics and query shape to match.

CHALLENGES TO RUN

Distributed Systems Challenges

Fencing a zombie worker

A worker stalls, its lease runs out, someone else takes the job, and the first worker wakes up and finishes anyway. Make its late work count for nothing.

Distributed Systems Challenges

One message per action through a flaky provider

Send exactly one SMS per order through a provider that times out and sends duplicate, out-of-order webhooks, while workers get killed. Then share the workers fairly across 100 stores.

Distributed Systems Challenges

Where does each comment live?

Split comments across databases four ways on real SQLite shards, move data without losing writes, then meet the viral post no hash can spread and the stale server writing to the wrong place.

CONCEPTS

What is a cache stampede?

A cache stampede happens when many requests miss the same expired or missing cache entry at the same moment and all recompute it at once. The sudden burst of identical queries hits the database together, can overload it, and turns a brief expiry into a long slowdown or outage.

What is consistent hashing?

Consistent hashing places both keys and servers on the same circle of hash values. A key belongs to the first server clockwise from it. When a server joins or leaves, only the keys in the arcs next to it change owner, instead of almost every key as with hash % n.

What is a fencing token?

A fencing token is a number that increases every time a lock or lease is granted. The protected resource remembers the highest one it has seen and rejects writes carrying a lower one, so a paused holder whose lease has expired cannot overwrite the new holder's work.

What is a hot key?

A hot key is a single key that receives a large share of all traffic. Hashing spreads different keys across servers, never one key, so every request for it lands on one server, and adding servers does not help. Fixes are splitting the key, caching reads, or giving it dedicated capacity.

What is an idempotency key?

An idempotency key is a unique id that the client chooses and sends with a request, so a retry of the same operation can be recognized and not applied twice. The server stores the key together with the result, and answers a repeated key with the stored result instead of acting again.

What is the transactional outbox pattern?

The transactional outbox pattern writes an event to an outbox table in the same database transaction as the state change it describes. A separate relay process later reads the table and publishes the event. The event cannot be lost if the change committed, but it may be published more than once.

What are virtual nodes?

Virtual nodes (vnodes) give each physical server many positions on a hash ring instead of one. Its share becomes the sum of many small arcs, so load evens out, and when a server leaves, its data spreads over several neighbors instead of landing on one.