Day 24. My API was fast. Until it wasn't. I had this: return ResponseEntity.ok(userRepository.findAll()); 10 users in development. Works instantly. Feels perfect. Then production happened: → 50,000 users in the database → One API call loads everything → Response time: 40ms → 8 seconds → Memory spikes → API crashes That's not a performance issue. That's a design mistake. And it was there from day one. I just couldn't see it yet. That's when it clicked: Your API should never decide how much data to return. The client should. So I added pagination. (see implementation below 👇) What changed: → Performance — stable response time → Scalability — works at 100 or 100,000 rows → Stability — no memory spikes The hard truth: → findAll() works in tutorials → It breaks in production → Pagination is not an optimization — it's a requirement Fetching data is easy. Controlling how much you fetch is what makes your API scalable. Are you still using findAll() in production? 👇 Drop it below #SpringBoot #Java #BackendDevelopment #Performance #JavaDeveloper
One more thing I didn’t expect: Pagination doesn’t just improve performance. It protects your API from accidental abuse. One bad client request without limits can bring your system down. Pagination is not optimization. It’s a safety layer.
the code doesn't make sense. you repository returns dto en the second one you map it tondto
True. I experienced this in production with 8M+ records—findAll() caused immediate memory spikes and crashes. Switching to pagination (and batching where needed) made it stable and scalable.
Hot take: findAll() is fine. Until your dataset grows. Then it becomes the slowest endpoint in your system. Even if you "only have 100 users today." You won't always. Are you using pagination everywhere? 👇