Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

incident.io 15 min read Case study hardMaster

How savepoints quietly throttled our Postgres queue

Using a SAVEPOINT per tick in a Postgres-backed job queue made every locked row carry a MultiXact ID in xmax. FOR UPDATE SKIP LOCKED scans then contended on the LWLock-guarded pg_multixact cache, so adding workers made acquisition slower. incident.io fixed it by moving the queue to a slim escalation_jobs table, replacing subtransactions with a claimed_until lease (one transaction per tick), keeping claimed_until unindexed with fillfactor 85 to allow HOT updates, and running one dispatcher goroutine per pod that feeds workers over a channel. Together these raised peak escalation capacity 3.5x, at the cost of up to 10 seconds of delay if a pod dies mid-claim.

Related posts

  • 1M Durable Workflows per Second on Postgres

    DBOS mediumAdept

    Sharding Postgres with PgDog let DBOS durable workflow throughput scale linearly from 20K workflows/sec on one db.m7i.4xlarge RDS instance to 1M workflows/sec across 50 shards. Linear scaling depends on every workflow operation hitting a single shard, so a shard_key column is added to workflow_status and all dependent tables, and workers dequeue one shard at a time. Past roughly 8-16 shards, performance turned metastable: a briefly slow shard (e.g. during VACUUM) attracted more concurrent FOR UPDATE SKIP LOCKED dequeuers, and the resulting lock contention made the shard slower still until the whole cluster collapsed. The fix caps concurrency per shard with a small pool of Postgres advisory 'dequeue locks', and a worker that cannot get one skips to the next shard instead of waiting.

  • When upserts don’t update but still write: Debugging Postgres performance at scale

    Datadog Engineering mediumAdept

    A Postgres `INSERT ... ON CONFLICT DO UPDATE ... WHERE` upsert still locks the conflicting row even when the WHERE clause blocks the update. That lock assigns a transaction ID and writes a Heap LOCK record plus a COMMIT to the WAL, forcing a WAL sync per query. Datadog's host last-seen tracker hit this: at 500 upserts/s it doubled write IOPS against a gp3 disk limit of roughly 1,000 fsyncs/s, which made the planned 25,000/s impossible. Using pg_walinspect and an lldb backtrace to find the cause, the team switched to a CTE that does `INSERT ... ON CONFLICT DO NOTHING` followed by a conditional UPDATE, accepting a minor race condition in exchange for zero WAL writes on no-op calls and HOT updates otherwise.

  • PostgreSQL Stories: A simple query with a big problem

    Render mediumAdept

    A seemingly simple indexed join with LIMIT 1 ran for over four hours on Render's staging PostgreSQL, holding a lock that blocked CREATE OR REPLACE VIEW migrations and stalled deploys. The team traced it by watching oldest-transaction age, querying pg_stat_activity for long-running active queries, and using pg_blocking_pids() to map which backends blocked which migrations. The culprit was an engineer's ad-hoc psql query: pressing Ctrl+C in psql stopped reading results but left the server-side query running. Killing the backend fixed it immediately. Key lessons are to keep transactions short, because they block locks, autovacuum and risk XID wraparound, and to set application_name and inspect usename so queries can be traced to their source.

  • PGKeeper: Building the bouncer we needed for Postgres

    Figma mediumAdept

    Figma replaced PgBouncer with PGKeeper, a Go service built on PGX that sits between its DBProxy router and each Postgres instance. Clients reach it over gRPC with per-query metadata such as traffic tier and request source. PgBouncer was ruled out for its single-threaded scaling ceiling, lack of prioritization and backpressure, and weak protection against connection churn. Pooling inside DBProxy was ruled out because hundreds of replicas cannot share a ~100-connection pool, and PGCat would have required a fork. PGKeeper token-bucket rate-limits both connection creation and teardown, warms pools before taking traffic, and avoids churn with bounded result draining, automatic ROLLBACK, and context cancellation via pg_cancel_backend plus SELECT 1. Its priority-based semaphore admission control uses CoDel to shed stale lower-priority work during concurrency spikes.

  • Everyone gets faster writes: We turned off FPW's in Neon

    Neon hardMaster

    Neon disabled Postgres full-page writes fleet-wide because its stateless compute streams WAL to a Paxos safekeeper quorum and has no local disk pages that can tear. To keep delta chains bounded without FPW images, the pageserver now generates page images itself once a page accumulates more deltas than a threshold, rather than relying on the checkpoint cycle. HammerDB TPROC-C throughput rose up to 4.5x on 32 vCPU, and WAL per transaction fell from 58KB to under 4KB (94%). In production, p99 read latency dropped 30-50%, and the change was rolled out without restarts via the XLOG_FPW_CHANGE WAL record.

The quest for software engineering knowledge.

Look:
Layout: