Let me share how I fixed a slow report loading issue in my application I had created the report APIs, and initially it worked fine. What I was doing: I fetched all users data from the backend and applied pagination on the frontend. This worked well in the beginning when the dataset was small. But as the number of users grew: Reports started taking longer to load API responses became heavy Overall user experience degraded After digging deeper, I realized: Paginating on the frontend after fetching all data is a bad practice for large datasets. The Fix: I moved pagination to the backend: Sent page and rowsPerPage as query params Used Spring Boot’s pagination (PageRequest) Returned only the required chunk of data Result: Much faster report loading Reduced payload size Better scalability Key takeaway: Always paginate at the backend when dealing with large datasets. Small design decisions early on can create big performance issues later. #SpringBoot #BackendDevelopment #Java #PerformanceOptimization #APIDesign
Optimizing Report Loading with Backend Pagination in Spring Boot
More Relevant Posts
-
🚫 Stop Using Magic Numbers & Magic Strings in Your Code Ever opened a codebase and found something like this? if (status == 3) { // do something } Or worse: if (user.getRole().equals("ADMIN")) { // grant access } 🤔 What does 3 mean? 🤔 Why "ADMIN"? Is it safe? Is it reused elsewhere? These are classic examples of magic numbers and magic strings — values with no clear meaning or context. ❌ Why This Is a Problem 1. Poor Readability Code should tell a story. Magic values force developers to guess the meaning. 2. Hard to Maintain If "ADMIN" changes to "SUPER_ADMIN", how many places do you need to update? 3. Error-Prone Typos like "AdMiN" won’t be caught at compile time. 4. No Single Source of Truth Values scattered across the codebase lead to inconsistencies. ✅ Better Approach Use constants, enums, or value objects to give meaning to your code. public static final int STATUS_ACTIVE = 3; if (status == STATUS_ACTIVE) { // clear and readable } Or even better: public enum Role { ADMIN, USER, GUEST } if (user.getRole() == Role.ADMIN) { // type-safe and expressive } 💡 The Real Benefit You’re not just cleaning code — you’re: ✔ Improving communication between developers ✔ Reducing bugs ✔ Making future changes safer ✔ Creating self-documenting systems ⚡ Rule of Thumb If a value makes you stop and think “what is this?” → it probably shouldn’t be there. Clean code isn’t about perfection — it’s about clarity. And clarity scales. #CleanCode #Java #SoftwareEngineering #BestPractices #Refactoring
To view or add a comment, sign in
-
-
🚀 Excited to share that JsonApi4j 1.4.0 is now live! 👉 https://lnkd.in/esH-K9AR This release adds support for JSON:API Compound Documents (https://lnkd.in/efzDhj5W) as a pluggable module. JSON:API's Compound Documents let you fetch a resource(s) and all related data in one request, eliminating extra round-trips and keeping everything perfectly consistent. It's a powerful way to deliver rich, interconnected data graphs efficiently - like getting an entire object tree in a single, clean response. Just add the plugin dependency, and your API can handle requests like: "/users/123?include=relatives.relatives&include=placeOfBirth" → Fetch a user → Their relatives (users). And relatives of those relatives (users) → And the user’s place of birth (countries) All in one request. You can fine-tune how relationships are resolved and fetched via configuration, with built-in and configurable guardrails. --- JsonApi4j is an open-source framework for building APIs aligned with the JSON:API specification, with a strong focus on developer productivity and clean architecture. If you're looking for a structured and flexible way to expose JSON:API endpoints — give it a try. Feedback and contributions are always welcome! 🙌 #java #jsonapi #opensource #api
To view or add a comment, sign in
-
I stopped treating backend development as “just CRUD APIs” and started building systems the way they actually run in production. Recently, I designed and implemented a user management service using Spring Boot with a focus on clean architecture and real-world constraints. Instead of just making endpoints work, I focused on: • Strict layer separation (Controller → Service → Repository) • DTO-based contracts to avoid leaking internal models • Validation at the boundary using @Valid and constraint annotations • Centralized exception handling with @RestControllerAdvice • Pagination & filtering using Pageable for scalable data access • Query design using Spring Data JPA method derivation • Handling edge cases like null/empty filters and invalid pagination inputs I also implemented authentication with password hashing (BCrypt) and started integrating JWT-based stateless security. One thing that stood out during this process: Building features is easy. Designing them to be predictable, scalable, and secure is where real backend engineering begins. This project forced me to think beyond “does it work?” and start asking: How does this behave under load? What happens when input is invalid? How does the system fail? That shift in thinking changed everything. Always open to feedback and discussions around backend architecture, API design, and Spring ecosystem. #SpringBoot #BackendEngineering #Java #SystemDesign #RESTAPI #SoftwareEngineering
To view or add a comment, sign in
-
-
🚀 Spring Boot in Real Projects — Day 4 One doubt almost everyone has 👇 👉 How does a frontend request go to the correct backend method?And how the code responses as per the user request? Let’s understand how APIs are actually created and how they work in Spring Boot. 💡 What is @RequestMapping? It is used to map a client request (like from UI or Postman) to a specific method in your backend. In simple words: 👉 It tells Spring “when this URL is hit, run this method”. 🤔 What about @GetMapping and @PostMapping? Yes, they are part of this concept. @GetMapping → used to get data @PostMapping → used to send/create data. 👉 They are just simplified versions of @RequestMapping. 📍 Where do we use these? We use all these annotations inside the Controller layer Because controller is the entry point of our backend. 🧪 Example @RestController @RequestMapping("/users") public class UserController { @GetMapping public List<String> getUsers() { return List.of("Rajesh", "Kumar"); } @PostMapping public String createUser() { return "User created successfully"; } } 🔄 Working Flow Let’s say frontend sends a request: 👉 GET /users 1. Request comes to Spring Boot 2. It checks controller mappings 3. Finds @GetMapping("/users") 4. That method runs 5. Response is sent back #SpringBootSeries #javadeveloper #backenddeveloper #series
To view or add a comment, sign in
-
-
🚀 Why Offset Pagination Fails at Scale (and What to Use Instead) When I started building backend services with Spring Boot, I used Pageable everywhere. It worked fine… until it didn’t. Once your table hits millions of rows, this becomes dangerous: LIMIT 20 OFFSET 1000000 👉 The database still scans & skips 1M rows before returning data. 👉 Result: slow queries, high DB load, poor user experience. 💡 The Better Approach: Window-Based Iteration (Cursor Pagination) Instead of OFFSET, use a cursor (lastId / timestamp): SELECT * FROM post_comment WHERE post_id = :postId AND id < :lastId ORDER BY id DESC LIMIT 20; 🔥 Why This Works ✅ Constant performance → O(limit), not O(offset) ✅ Uses indexes efficiently ✅ No lag even with 10M+ rows ✅ Perfect for infinite scroll APIs 🧠 Real Insight Think of it like this: • OFFSET → flipping every page to reach page 1000 📖 • Cursor → using a bookmark 🔖 ⚙️ How I Implement It • Use batchSize to control data window • Maintain lastId as cursor • Fetch next chunk using id < lastId • Repeat until no data 🚀 Where This Is Used • Social feeds (Instagram, LinkedIn, Twitter) • Comment systems • Chat applications • Large-scale analytics pipelines 🎯 Takeaway 👉 OFFSET pagination is simple but not scalable 👉 Cursor + window-based iteration is production-grade #Backend #SpringBoot #SystemDesign #Scalability #Java #SoftwareEngineering
To view or add a comment, sign in
-
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
To view or add a comment, sign in
-
-
Are you just returning data, or delivering a complete API response? When I first started working with Spring Boot, my REST controllers looked something like this: @GetMapping("/{id}") public User getUser(@PathVariable Long id) { return userService.findById(id); } Simple. Clean. Functional. But not truly professional. As I gained more experience in backend development, I realized this approach silently assumes that everything always succeeds — defaulting to a "200 OK" response regardless of the situation. That’s a missed opportunity to communicate effectively with API consumers. The industry-standard approach is to use ResponseEntity — not just to return data, but to return meaningful responses. Here’s why it matters: ✅ Precise Status Codes Return "201 Created" for new resources, "404 Not Found" when data is missing, or "400 Bad Request" for invalid input — instead of forcing clients to interpret ambiguous responses. ✅ Custom Headers Easily include headers like "Location", pagination details, or authentication metadata — improving API usability and scalability. ✅ Flexible Response Bodies Structure different responses for success and failure scenarios, making your APIs predictable and consumer-friendly. In backend development, returning data is only half the job. Communicating the outcome of the operation is equally important. A well-designed API doesn’t just work — it speaks clearly to every client that consumes it. 👇 I’m curious — how do you design your REST responses? Do you rely on "ResponseEntity", or prefer annotations like "@ResponseStatus" with global exception handling? #SpringBoot #Java #BackendDevelopment #APIDesign #RESTAPI #SoftwareEngineering #CodingBestPractices
To view or add a comment, sign in
-
-
I made every REST API design mistake in the book. Here are the ones that actually matter. Mistake 1: Using verbs in URLs Wrong: /getUser, /deleteOrder Right: GET /users/{id}, DELETE /orders/{id} The HTTP method IS the verb. Don't repeat it in the URL. Mistake 2: Returning 200 for everything I was returning HTTP 200 even when operations failed, with an error message in the body. This breaks every API client that checks status codes. Learn your codes: 200, 201, 400, 401, 403, 404, 409, 500. Mistake 3: No versioning When I changed my API, I broke the frontend immediately. Add /v1/ to your base path from day one. /api/v1/orders — not /api/orders Mistake 4: Exposing database structure My early APIs returned every column from the entity directly. That's a security and coupling problem. Use DTOs. Return only what the client actually needs. Mistake 5: No input validation Anything can arrive through an API. Validate everything before it touches your database. These sound basic. But I still see all five in production codebases every week. Which one did you learn the hard way? #REST #BackendDevelopment #Java #SpringBoot #APIDesign
To view or add a comment, sign in
-
Stop treating Multer as just a “File Uploader.” 📦 Ever wondered why req.body is empty when you send a file and data, even though the frontend is perfect? 🤔 Most developers add upload.single() to the route because the tutorial said to. But the real work happens in the parsing, not just the storage. The Technical Reality ⚙️ The Parser Gap: Standard JSON parsers cannot decode multipart/form-data. This format sends data in a boundary-separated stream that Express doesn't naturally read. The "Unlock" Mechanism: Multer’s main job is to intercept that stream 🔓 It is the middleware that fills req.body for your text fields and req.file for your binary data. The Dependency: Without this middleware, your server is essentially blind 👀❌ Not just to the file — but to the entire request payload. Don't just say you're uploading a file. You are parsing a multipart request to reconstruct data that would otherwise be unavailable to the server. Understanding the request-response cycle at this level is what separates someone who just codes… from someone who truly builds 🚀 #NodeJS #Backend #ExpressJS #SoftwareEngineering #WebDev
To view or add a comment, sign in
-
Learning in Public — Building a Professional Backend Structure 🚀 Today’s session was all about setting up the "skeleton" of a professional backend using Express.JS. Key focus areas: - Module Code Structure: Organizing logic into dedicated folders for better clarity. - Global Architecture: Setting up a common home for global-level middlewares and configurations. - Separation of Concerns: Ensuring each part of the code has one specific job. - Standardization: Establishing consistent patterns to make the codebase predictable and clean. - Data Handling: Designing Schemas and DTOs (Data Transfer Objects) for structured data flow. - Validation: Implementing Joi to ensure incoming data meets our requirements before it hits the logic. - Middlewares: Using them to handle repetitive tasks across the application. It’s exciting to see how these structural pieces fit together to create a maintainable backend! 🧱 Thanks to my mentors: Hitesh Choudhary | Piyush Garg | Chai Code Shoutout to Anirudh Jwala | Suraj Kumar Jha | Akash Kadlag | Jay Kadlag for the support. #LearningInPublic #NodeJS #BackendDevelopment #CleanCode #SoftwareArchitecture #Express
To view or add a comment, sign in
-
Explore related topics
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development