IL-0486 Figma · 2020-01-22databaseaws
Figma's PostgreSQL 9 database on RDS slowed under high write IOPS and lock contention until the site was unavailable
Figma runs PostgreSQL on Amazon RDS. On January 21 a long-running, expensive query raised database CPU until it was cancelled. On January 22 a routine automatic ANALYZE changed the statistics of a table used by a complex ORM-generated query. ANALYZE samples rows, and it had increasingly underestimated the selectivity of the innermost subquery; once the estimate for an inner HashAggregate crossed 200 rows, a deficiency in the PostgreSQL 9 query planner made the total estimate jump from 199 rows to over 20 million. The resulting plan used full table scans and wrote large amounts of data to temporary buffers, consistent with the high write IOPS and temp bytes metrics seen during the incident. At the same time, the backlog left by the query cancelled on January 21 had started aggressive anti-wraparound autovacuum, which added to the locking and writes.
The team cancelled inessential queries, raised IOPS, cancelled autovacuum statements, and at 3:00 PM restarted the database to apply a change to autovacuum_freeze_max_age that stopped aggressive autovacuum; that reboot caused part of the downtime between 2 PM and 3 PM. Because the database stayed unhealthy, the team took the service down at 7:00 PM for emergency maintenance and upgraded to PostgreSQL 11, which had been tested in staging for several months with a written upgrade plan. The site was back at 8:15 PM and all site and database metrics returned to normal.
Afterwards the team restored a snapshot from before the upgrade, reduced the query to nested sub-selects on the roles table, reproduced the bad estimate by running ANALYZE manually, and bisected PostgreSQL versions with the official Docker images: the test case from a PostgreSQL mailing list thread reproduced in 9.6.16 but not in 10.0. The 10.0 change "Use uniqueness guarantees to optimize certain join types" lets the planner use the primary key's uniqueness, and on the upgraded database EXPLAIN VERBOSE shows "Inner Unique: true" for the query. PostgreSQL 11 also handles autovacuum much better than version 9.
- Severity
- –
- Scope
- Figma web service: intermittent issues and failures to load Figma at several points during January 22, plus an emergency maintenance downtime from 7:00 PM to 8:15 PM PST
- Users affected
- some users
- Region
- –
- Time to detect
- 15m
- Time to resolve
- 10h 30m
Symptoms
On January 22, 2020 at 9:45 AM PST, Figma's database metrics showed rising write IOPS and lock contention, while database CPU was lower than normal. An automated alert followed at 10:00 AM, and by 11:42 AM enough API requests had queued up behind the database that Figma became unavailable for some users.
The pressure showed in write IOPS, write latency, lock contention and the temp bytes metric. One statement with complex subqueries, generated by Figma's ORM layer, kept appearing in the lock contention. Its plan estimated over 20 million rows when the real result was 3 rows, did full table scans instead of using an index and wrote large amounts of data to temporary buffers, and its execution time stretched into minutes.
The disruption came in waves. Cancelling several inessential queries and raising the allocated IOPS stabilised performance for a while, but at 2:00 PM the database degraded again and the site went down a second time. A restart at 3:00 PM brought relative stability, but write IOPS, write latency and lock contention stayed higher than normal until the evening upgrade.
The first theory was aggressive autovacuum. A long-running query cancelled the previous day had left a vacuuming backlog that crossed the threshold for the autovacuum mode that prevents transaction ID wraparound, which weighs more on locking and writes in the PostgreSQL version Figma ran. Cancelling autovacuum statements on the largest tables helped only briefly, because autovacuum resumed, and even after it was disabled the performance problems continued.
Symptom Lock contention or deadlockDatabase overloadService outage
Root cause
Root cause Software defect
- Trigger
- An automatic ANALYZE on one of the tables in the query finished at exactly the moment the incident began. The new statistics pushed the planner's row estimate for an inner subquery past 200 rows, and the plan for the whole query switched to an estimate of over 20 million rows.
Detection
Database metrics showed higher write IOPS and lock contention at 9:45 AM PST, and an automated alert at 10:00 AM started the investigation.
Remediation
- Cancelled several inessential queries and increased the allocated IOPS
- Cancelled autovacuum statements running on the largest tables
- Changed autovacuum_freeze_max_age and restarted the database to stop aggressive autovacuuming
- Took the service down for emergency maintenance and upgraded the database to PostgreSQL 11
Action items
- Revisit transaction timeouts and limits so long-running and expensive queries are terminated
- Improve metrics, monitoring and database settings for autovacuuming, locking and query performance
- Audit queries for unnecessary or excessive joins and subqueries that could trip up the query planner
- Bring the performance tools of the upgraded PostgreSQL into the incident response plans
- Audit the structure and access patterns of data stored in PostgreSQL and consider moving some of it to datastores suited to those patterns
- Improve in-app messaging about unexpected maintenance windows
- Move towards online database upgrades that do not need downtime
- Let users keep working on already open files safely while offline, even after closing the browser
Lessons
Having upgraded staging to PostgreSQL 11, tested it for months and written a production upgrade plan let the team upgrade under poor conditions with confidence. A routine statistics refresh can flip a query to a catastrophic plan, and the same query's plan can differ widely over time, so comparing plans from snapshots taken at different dates exposed the cause.
Sources
Related cases
IL-0451Setting indexes INVISIBLE on Aurora MySQL 3.10 spiked CPU and ReadIOPS on all three readers but not on the writerDaangn · 2026same root cause · shared Database
IL-0313Decagon voice requests stalled for exactly 300 seconds behind self-managed PgBouncer and exhausted the SQLAlchemy poolDecagon · 2026same root cause · shared Database
IL-0281PostHog's Logs ClickHouse cluster silently deleted almost all its S3 data, losing US logs older than 3 daysPostHog · 2026same root cause · shared Database
IL-0310An Aurora PostgreSQL failover to an upsized reader reversed twice and backend writes failed in read-only transactionsHightouch · 2025same root cause · shared Database
IL-0150A latent race condition in DynamoDB's DNS automation left an empty DNS record for dynamodb.us-east-1.amazonaws.com, and the DynamoDB and EC2 launch failures that followed caused EKS, ECS and Fargate container launch failures and cluster scaling delays in us-east-1Amazon Web Services · 2025same root cause · shared Database
IL-0436A supremum lock left by ROLLBACK TO SAVEPOINT in a long transaction blocked inserts and filled Aurora MySQL connectionsfreee · 2025same root cause · shared Database
IL-0527OpenStreetMap.org made no replication diffs for 16 hours as PostgreSQL logical decoding failed on a memory alloc errorOpenStreetMap Foundation · 2025same root cause · shared Database
IL-0329A routine migration left PGAudit stuck holding Postgres locks, causing intermittent timeouts and a 2-minute outageincident.io · 2025same root cause · shared Database
IL-0347About 25% of Scaleway FR-PAR-1 hypervisors lost VPC connectivity when both VPC BGP route reflectors got stuckScaleway · 2024same root cause · shared Database
IL-0373Heroku Postgres Essential-tier databases in the EU region ran out of memory and refused connections, twice in four daysHeroku · 2024same root cause · shared Database
IL-0024Expensive cache-backed API calls and uncancelled database requests overloaded MongoDB and took the Hugging Face Hub down three timesHugging Face · 2024same root cause · shared Database
IL-0217Honeycomb's main MySQL database locked up under cache-miss reads and ran out of connections, a 68-minute total outageHoneycomb · 2023same root cause · shared Database
IL-0330Requests timed out for two weeks waiting on Go's database/sql connection pool, one for almost 20 secondsincident.io · 2023same root cause · shared Database
IL-0385GitHub MySQL read replicas hit a semaphore deadlock during a schema migration's table rename and kept crash-recoveringGitHub · 2021same root cause · shared Database
IL-0462Some MySQL pods on Shopify's GKE clusters took up to 30 minutes to start, slowing instance replacementShopify · 2021same root cause · shared Database
IL-0196Adding a second Redis replica and lowering memory limits in one RedisFailover change restarted the only Redis pod that held data, and Sentinel promoted the empty new replica, erasing the dataPalark · 2020same root cause · shared Database
IL-0241A database shard could not elect a new primary, and the Stripe API failed most requests in two periods on one dayStripe · 2019same root cause · shared Database
IL-0439Database access slowed after each block device and filesystem expansion because the Linux kernel dropped the page cacheCybozu · 2018same root cause · shared Database
IL-0388A Google Cloud live migration took a Discord Redis primary offline, and the failover broke API instances and then guildsDiscord · 2017same root cause · shared Database
IL-0454Baemin billing servers could not open new MariaDB connections at the start of a card-discount eventWoowa Brothers · 2016same root cause · shared Database
IL-0536Amazon SimpleDB in US East returned HTTP 500 to nearly all API calls for two hours after its nodes left the clusterAmazon Web Services · 2014same root cause · shared Database
IL-0485Dropbox went down when an OS upgrade script reinstalled active MySQL master-replica pairs and backup restores ran slowDropbox · 2014same root cause · shared Database
IL-0589Every Kickstarter MySQL replica on Amazon RDS stopped replicating on a duplicate-key error in the backings tableKickstarter · 2013same root cause · shared Database
IL-0303GitHub's MySQL master failed over to a node with a cold buffer pool during a schema migration and GitHub.com went downGitHub · 2012same root cause · shared Database
Check your cluster for this
For AI tools and scripts
- This case as JSON: https://incidentlib-api.benchlet.com/cases/IL-0486
- The cases most like it: https://incidentlib-api.benchlet.com/cases/IL-0486/similar
- MCP server (Streamable HTTP, no key):
https://incidentlib-mcp.benchlet.com/mcp
The API needs no key. The MCP server offers search_incidents, get_incident, list_incidents, get_topic and vocab; both are explained on API and MCP.