Autoscaling Ate the Database
Easy · system design problem
A promo ×2.5 makes the API autoscale — and every new instance opens 20 Postgres connections. Raising max_connections makes Postgres slower, not faster.
orders-api autoscales on CPU; each instance keeps a pool of 20 PostgreSQL connections, and today 15 instances use 300 of the database’s 320. The workload is write-heavy, so caching reads will not save the primary. At T+20s a promo multiplies traffic by 2.5 for the rest of the day and the autoscaler heads for ~36 instances. Every PostgreSQL connection is a process: past a few hundred, the database spends its CPU juggling them.
Topics
More
Codelays runs in your browser: turn on JavaScript to use it.