Making a production database cheaper
SQL Server, Query Store, Application Insights, RedisMonthly database cost down ~40%, with the slowest queries over 100x faster.
- Problem
- The main transactional database was the biggest line on the infrastructure bill, and the standing answer to slow pages and busy weekends was to buy more capacity. Nobody knew which pages or queries were actually expensive.
- Approach
- I measured before changing anything. Application Insights showed which pages were hit hardest and loaded slowest. Query Store showed which statements were burning processor time behind them. The two lists overlapped in a handful of places, and a single page turned out to be using about a third of all database processor time. From there the fixes were about doing less work: one query instead of one per row, caching values that were recalculated on every request but changed a few times a day, fixing a query plan regression that had quietly taken over half of all processing, and removing indexes and jobs nothing read. Only then did I scale the hardware down, in stages timed around peak traffic.
- Result
- The database does a fraction of the work it used to while traffic kept growing. Cost dropped ~40%, the worst queries run over 100x faster, and the same measurements now catch the next regression before it costs anything.