Posts tagged “databases”

  1. Why does one long-running transaction slow down the whole database?

    Databases keep old row versions for as long as any open transaction might need them. One idle transaction on an unrelated table made PostgreSQL's busiest table 200× bigger and its writes 3× slower; in MySQL it made the old transaction's own reads 250× slower. Measured, with the settings that…

    · 10 min read · Databases

  2. How do you keep two systems consistent without distributed transactions?

    An order in one database, its payment in another, and a process that can die between them. Dual writes, two-phase commit, sagas and the outbox, each run 1,000 times with crashes injected: what goes wrong, what recovers, and what two-phase commit's in-doubt transactions block.

    · 9 min read · Databases

  3. What does ACID actually promise, and what do you lose with BASE?

    ACID is four separate promises, and most 'NoSQL vs SQL' arguments mix them up. Money transfers in PostgreSQL, MongoDB and DynamoDB, with and without transactions, with crashes: what each letter bought, measured, and why atomic writes still aren't enough if your reads aren't snapshots.

    · 9 min read · Databases

  4. Why isn't a Redis lock enough?

    A Redis lock is a lease: it expires whether or not its holder is done. Measured with Redis 7.4 and PostgreSQL 17: a paused holder overwriting newer data, a release that frees someone else's lock, a cron job running twice, and what fixes each.

    · 10 min read · Databases

  5. Why is there an append-only log under queues, databases and the outbox?

    PostgreSQL's WAL, Kafka's partitions, a transactional outbox and an event-sourced store are all the same structure: records appended to the end, read in order, never changed. Why appending is the shape durability takes, what an fsync costs, and how group commit gets 30x more out of the same disk…

    · 10 min read · Data Structures

  6. Should you lock the row or retry on conflict?

    Pessimistic locking (SELECT … FOR UPDATE) vs optimistic retries (a version column) vs a single atomic UPDATE, measured on PostgreSQL 17 at high and low contention, plus 50 buyers rushing the last 10 tickets.

    · 12 min read · Databases

  7. Why does my Postgres query get slower as the table grows, even with an index?

    An index only helps when Postgres can stop early or touch few pages. Six measured reasons it can't, from 10K to 10M rows, and the fix for each.

    · 12 min read · Databases

  8. Why are some databases fast at writes and others at reads?

    Under the hood, most databases are either a B-tree or an LSM tree. A B-tree updates data where it lives and pays for random writes; an LSM tree appends and sorts later, and pays at read time. Measured with the engines under etcd and CockroachDB: 54× vs 7× bytes written per byte stored, and reads…

    · 9 min read · Databases

  9. Postgres or DynamoDB for a new SaaS?

    DynamoDB is superb at the questions you designed it for and expensive at the ones you didn't; PostgreSQL answers questions you haven't thought of yet. The same 200,000 orders in both: 0.5 read units for the planned query, 2,689 for an unplanned report that PostgreSQL ran in 13 ms without an index.

    · 9 min read · Databases

  10. CAP or PACELC: what trade-off do you make when nothing is broken?

    CAP describes the rare moment the network splits. PACELC adds the trade-off you make all day: a fresher answer costs latency. Measured on a PostgreSQL primary and replica: how often reading your own write is stale, what each synchronous_commit level costs, and what happens when the replica is gone.

    · 9 min read · Databases

  11. Read replicas, partitioning or sharding: what does each one fix?

    Three ways to outgrow one database, often confused. Replicas add read capacity and cost you freshness. Partitioning keeps one huge table manageable but adds no capacity. Sharding adds write capacity and costs you almost everything that was easy. Measured on PostgreSQL 17: replica staleness, and…

    · 8 min read · Databases

  12. If MongoDB is schemaless, why do we write Mongoose schemas? Why not one collection for everything?

    MongoDB stores whatever you write; Mongoose checks only what goes through Mongoose, and not all of that. Measured on MongoDB 8.2: what each layer enforces, and what one shared collection costs.

    · 10 min read · Databases

  13. How do you migrate a live database without downtime?

    Most outages during migrations aren't failed migrations; they're migrations that held a lock while traffic queued behind them. Measured on a 5M-row table under load: one-step changes that stalled every request for 2-8 seconds, and the online versions that stalled them for a fraction of a second…

    · 9 min read · System Design

  14. Should you self-host your database or use RDS?

    RDS and Aurora buy you backups, point-in-time recovery, failover and patching for a premium on every instance-hour. Self-hosting on EC2 can cost far less, and makes every one of those jobs yours. When each is the right call, and what you must build before self-hosting is safe.

    · 7 min read · AWS

  15. Which isolation level should you use, and what does each one let through?

    Ten concurrency scenarios, four isolation levels, one PostgreSQL 17 database. A measured matrix of what each level allows, and why the stricter levels move the work into your retry loop.

    · 12 min read · Databases