Java Shorts: Cursor-Based Pagination Why Cursor-Based Pagination Is the Right Way to Scale APIs ? When working with large datasets, pagination is unavoidable. Most systems start with traditional (offset-based) pagination, but that approach doesn’t scale well. Traditional pagination Sql - LIMIT 10 OFFSET 1000 Returns only 10 rows But the database still scans and skips 1000 rows internally and Slows down as page number increases Cursor-Based Pagination (Modern & Efficient) : Cursor-based pagination uses the last record from the previous response as a reference. Simple example First request → get 10 orders Last order ID returned = 5000 Next request: WHERE id > 5000 LIMIT 10 Here, 5000 is the cursor Why this works better : Database jumps directly using indexes No scanning or skipping rows Consistent performance Reliable even when data changes Ideal for APIs & infinite scrolling Simple analogy : Traditional pagination: flipping pages from the start Cursor pagination: continuing from a bookmark Cursor-based pagination fetches data relative to the last seen record, not page numbers—making it faster and more reliable at scale. #Java #SpringBoot #BackendDevelopment #SystemDesign #Microservices #APIDesign #Databases
Cursor-Based Pagination for Scalable APIs
More Relevant Posts
-
Java Records:- At some point, you notice something odd. Half your Java classes look the same. Fields. Constructor. Getters. equals(). hashCode(). toString(). That repetition is exactly why Java Records were introduced. What a Record really is A record is a data carrier. Nothing more. Nothing less. It represents immutable data. public record User(Long id, String name) {} That one line automatically gives you: Constructor Getters equals() hashCode() toString() No boilerplate. No Lombok required. What makes Records different from classes Fields are final Objects are immutable Intent is clear: this class holds data You cannot accidentally add state-changing logic. Perfect use cases DTOs API request / response models Read-only projections Data coming from other services Records shine at boundaries of your system. Bad use cases JPA entities Classes with complex business logic Objects that need setters Records are not replacements for everything. Why Records matter in real projects Less code to maintain Fewer bugs from mutable state Cleaner APIs Faster onboarding for new developers The compiler does the boring work for you. Simple rule to remember 👉 If a class only carries data → consider a Record 👉 If it owns behavior → use a Class Closing thought Records are not a shortcut. They are the language telling you: “This object is just data.” That clarity improves design. Question Have you started using Java Records in your projects, or are you still relying on traditional DTO classes? #Java #SpringBoot #Programming #SoftwareDevelopment #Cloud #AI #Coding #Learning #Tech #Technology #WebDevelopment #Microservices #API #Database #SpringFramework #Hibernate #MySQL #BackendDevelopment #CareerGrowth #ProfessionalDevelopment #RDBMS #PostgreSQL
To view or add a comment, sign in
-
As I have started my new journey with Advance Java course, these are the inputs I have taken from my previous classes, 1.Input/Output Streams: ->Byte Oriented Stream ▫️ InputStream classes and OutputStream classes ->Character Oriented Stream ▫️ Reader classes and Writer classes 2.Serialization and Deserialization -> Serialization ▫️ ObjectOutputStream and BufferedOutputStream ->Deserialization ▫️ ObjectInputStream and BufferedInputStream ->Serialization and Deserialization with Buffered locations ->Selective Serialization ▫️ Using "transient" keyword ▫️ Using "Externalizable" interface ▫️ Using "Serializable" interface ->Secure Hash Algorithm 3.J2EE(Java 2 Enterprise Edition) ->3 types of application ▫️Standalone application ▫️Web application ▫️Distributed/Enterprise application ->Important terms ▫️JDBC(Java Database Connectivity) ▫️Servlets ▫️JSP(Java Server Page) ▫️Server ▫️MVC Architecture ->JDBC(Java Database Connectivity) ▫️Types of Drivers 🔸 JDBC-ODBC Bridge Driver 🔸 Native Driver 🔸 Network Driver 🔸 Thin Driver ▫️Components present in JDBC API 🔸Interfaces ▪️ Driver ▪️ Connection ▪️ Statement ▪️ PreparedStatement ▪️ CallableStatement ▪️ ResultSet ▪️ ResultSetMetaData 🔸Classes ▪️ DriverManager 🔸Exceptions ▪️ SQLException ->Batch Updates in JDBC ->Transactions in JDBC ->Connection Pooling These concepts has been learned and moving forward in the course by started to learn servlet concepts....... #globalquesttechnologies G.R NARENDRA REDDY #JAVVFULLSTACK
To view or add a comment, sign in
-
When I was learning Java backend, I thought JPA/Hibernate was the ultimate solution. Less SQL. Cleaner code. Faster development. So I used to wonder… “Why do most companies still use JDBC instead of JPA?” After working on a real-world project, the answer became very clear. Production systems aren’t just simple CRUD apps. They have: • millions of records • complex joins & aggregations • large Excel exports • stored procedures • performance-critical APIs And in these cases, ORM becomes overhead. Extra queries. Higher memory usage. Hidden performance costs. That’s where JDBC shines. Direct SQL. Full control. Better performance. Predictable behavior. Now my approach is simple: 👉 JPA for business CRUD 👉 JDBC for heavy queries & performance paths Big lesson: Don’t choose tools because they’re popular. Choose them because they fit the problem. Real engineering starts when you stop chasing “magic” and start understanding trade-offs. Still learning every day — refining not just my code, but my engineering decisions. #Java #SpringBoot #JDBC #Hibernate #BackendDevelopment #SystemDesign #SoftwareEngineering #SoftwareDeveloper
To view or add a comment, sign in
-
-
Hi connections, As a Java Developer, writing boilerplate SQL can slow development. With Spring Data JPA, we can: ✅ Perform CRUD operations without writing SQL ✅ Generate queries using method names ✅ Use pagination & sorting easily ✅ Manage relationships cleanly Simple Flow: Controller → Service → Repository → Database One interface. Less code. Clean architecture. Faster development. #Java #SpringBoot #SpringDataJPA #BackendDeveloper #Microservices
To view or add a comment, sign in
-
-
Complete day 10✅️of Java+ Springboot, where i learnt about, how array are stored. 📌How arrays are stored- ●Remember that all primitive data types goes to Stack memory. ●The reference variable is stored in Stack memory ,whereas the data is stored in Heap memory. ☆The formula to find value is - arr[i]= Base address + [ data type size × index] Base address is mostly 100. ●Data type size - Int-4 byte, Long - 8 byte, Float- 4 byte , Double- 8 byte ●According to official java doc " Boolean has no fix size". For better optimization Boolean has 1 byte. ● Reference variable always takes 4 byte.. boolean [ ][ ] - these reference array took 4 byte. A special thanks to Rohit Negi and Aditya Tandon sir who give their immense knowledge in it.
To view or add a comment, sign in
-
-
📚 Exploring JDBC — Understanding ResultSet in Java Today I explored JDBC ResultSet in Java and finally understood how Java actually reads data from a database, not just connects to it 💻🗄️ I built a small program where Java connects to MySQL, runs a SELECT query, and prints the record on the console. While doing this, I got clarity on the complete flow of database interaction: 1. Loading the MySQL driver 🔌 2. Creating a connection using DriverManager 🌐 3. Creating a Statement object 🧠 4. Executing the query ▶️ 5. Fetching data using ResultSet 📄 6. Extracting column values using getInt() and getString() 🔍 7. Closing the connection properly 🔒 The biggest learning was understanding how ResultSet works like a cursor 📍 It does not immediately give all records. Instead, it points to one row at a time. Only after calling next() does the cursor move to the first row and allow data access. Without it, no data can be read. So internally the flow becomes: Database Table → SQL Query → ResultSet Cursor → Java Variables → Console Output ⚙️ This small exercise helped me clearly visualize how backend applications actually fetch and process data from databases 🚀 Github link: https://lnkd.in/gask2mmb Special thanks to Prasoon Bidua sir for amazing guidance. #Java #JDBC #MySQL #BackendDevelopment #LearningInPublic
To view or add a comment, sign in
-
-
Writing an ORM over SQL is like writing Java to generate TypeScript — why are you complicating the obvious? #SQL #RawQuery #DataOriented #CleanCode #StopTheAbstraction
To view or add a comment, sign in
-
-
The Hidden Mechanism Behind ThreadLocal in Java ThreadLocal is often explained simply as: “Data stored per thread.” That’s true — but the interesting part is how it actually works internally. Most developers think the data lives inside ThreadLocal. It doesn’t. How ThreadLocal Works Internally Each Thread object maintains its own internal structure: Thread └── ThreadLocalMap ├── ThreadLocal → Value ├── ThreadLocal → Value The important detail: The map belongs to the Thread, not to ThreadLocal. ThreadLocal simply acts as a key. Basic Flow When you call: ThreadLocal.set(value) Internally: Copy code thread = currentThread map = thread.threadLocalMap map.put(ThreadLocal, value) When you call: ThreadLocal.get() It retrieves the value from the current thread’s map. Each thread therefore has its own independent copy. Where This Is Used in Real Systems You’ll find ThreadLocal used in many frameworks: • Spring Security → SecurityContextHolder • Transaction management → TransactionSynchronizationManager • Logging correlation IDs • Request scoped context It allows frameworks to store request-specific data without passing it through every method. The Hidden Danger If you forget to call: Copy code ThreadLocal.remove() You can create memory leaks. Why? Because thread pools reuse threads. Old values may remain attached to long-lived threads. ThreadLocal is simple conceptually. But its internal design is what makes many Java frameworks work efficiently. Have you used ThreadLocal in production code? #Java #CoreJava #Multithreading #ThreadLocal #SpringBoot #BackendEngineering #InterviewPreparation
To view or add a comment, sign in
-
When working with Hibernate, your Java classes are automatically mapped and persisted into actual database tables. It’s powerful how objects become real relational data with minimal configuration. But let’s be honest — without help, our entity classes can quickly become full of boilerplate code: getters, setters, constructors, toString(), equals(), and hashCode(). That’s where Project Lombok comes in. With simple annotations like: @Getter @Setter @Data @Builder @NoArgsConstructor @AllArgsConstructor Lombok drastically reduces boilerplate code and keeps your entities clean and readable. Instead of writing 50+ lines of repetitive code, you focus on business logic. Clean entities + less clutter = better maintainability Are you using Lombok in your Hibernate projects, or do you prefer writing everything manually? #Java #SpringBoot #Hibernate #Lombok #BackendDevelopment #CleanCode
To view or add a comment, sign in
-
-
𝗦𝘁𝗼𝗽 𝘁𝗿𝗲𝗮𝘁𝗶𝗻𝗴 𝗦𝗽𝗿𝗶𝗻𝗴 𝗗𝗮𝘁𝗮 𝗝𝗣𝗔 𝗹𝗶𝗸𝗲 𝗮 "𝗺𝗮𝗴𝗶𝗰 𝘄𝗮𝗻𝗱." When I started, I assumed JpaRepository was a shortcut to avoid learning SQL. I was wrong. Production traffic is the ultimate truth-teller. It exposes every shortcut. Here’s what real systems taught me: If you don’t know the exact SQL Hibernate is generating, you don’t truly know what your application is doing. My production checklist now includes: • Checking for N+1 issues (JOIN FETCH, @EntityGraph) • Using @Transactional(readOnly = true) for read-heavy paths • Replacing 100-character derived queries with explicit @Query • Reviewing database indexes before touching Java code Most so-called “JPA performance issues” are actually database design issues. Turning on Hibernate SQL logs was the single biggest upgrade in how I approach backend development. What was the biggest lesson you learned when taking a JPA-based service to production? #Java #SpringBoot #SpringDataJPA #BackendEngineering #SystemDesign
To view or add a comment, sign in
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