I optimized a Django API from 12s → 200ms. Here's the 6-step playbook 👇 1️⃣ Measure first — Django Debug Toolbar showed N+1 queries everywhere 2️⃣ Fix N+1 — select_related() and prefetch_related() = biggest win 3️⃣ Count in SQL — replaced Python loops with annotate() 4️⃣ Paginate — stop returning massive datasets 5️⃣ Add indexes — on fields you actually filter and sort by 6️⃣ Cache last — Redis only after fixing the real problems The lesson? Caching should come LAST, not first. Performance isn't magic. It's: Measure → Fix → Measure again. #Django #Python #BackendDevelopment #APIOptimization #WebDevelopment #DRF #SoftwareEngineering
I liked the paginate early point. I ran into this recently while validating phone fields across a large set of CRM deals even with pagination, offset based paging was still painful at scale, so, curious if you usually pair pagination with ordering on indexed fields to avoid that?
Insightful 💡
can we do this with other APIs too using the same steps I'm sure pagination adds faster responses but would the same steps work on other APIs or not?