When a Missing Index Cost $5,000: Lessons from a PlanetScale Mishap
An engineer’s oversight in a PlanetScale schema—omitting a foreign‑key‑based index—led to massive row‑scan costs, prompting a $5,000 bill, while the article also critiques junior developers’ naive schema designs and offers advice on proper database indexing and mentorship.
1. The hidden cost of missing indexes
Brian Anglin’s team built a Superwall SDK and used PlanetScale’s serverless database. They created two tables, ApplicationUser and ApplicationUserAlias, linked many‑to‑one, but PlanetScale’s Vitess layer does not support foreign keys, so the expected automatic index was never created.
Because the index was missing, a query that should have scanned only a few rows actually inspected the entire users table, which grew to over one million rows within a month. PlanetScale charges by the number of rows read, not by rows returned, so each request cost about $0.15. At roughly 280 requests per hour, the daily cost approached $1,000.
The team eventually fixed the issue by manually creating the missing index, but the bill had already highlighted the importance of understanding how foreign‑key relationships affect indexing.
The problematic query (shown in the next image) attempted to retrieve all aliases for a user, but without an index the database had to scan the whole table.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
