Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
•
IT Security NachrichtenBetrüger phishen mit vermeintlicher Reisebestätigung - IT-Markt(24.09.2026 um 23:41 Uhr)
••
Sicherheitslücken (CVE)IT Security News Daily Summary 2026-09-24(24.09.2026 um 23:55 Uhr)
•
Sicherheitslücken (CVE)IT Security News Roundup: 2026-09-24(24.09.2026 um 23:57 Uhr)
•
Sicherheitslücken (CVE)IT Security News Hourly Summary 2026-09-25 00h : 9 posts(25.09.2026 um 00:00 Uhr)
•••
IT NachrichtenMicrosoft puts Brad Smith in charge of communications(25.09.2026 um 00:08 Uhr)
•••
IT Security NachrichtenBetrüger phishen mit vermeintlicher Reisebestätigung - IT-Markt(24.09.2026 um 23:41 Uhr)
••
Sicherheitslücken (CVE)IT Security News Daily Summary 2026-09-24(24.09.2026 um 23:55 Uhr)
•
Sicherheitslücken (CVE)IT Security News Roundup: 2026-09-24(24.09.2026 um 23:57 Uhr)
•
Sicherheitslücken (CVE)IT Security News Hourly Summary 2026-09-25 00h : 9 posts(25.09.2026 um 00:00 Uhr)
•••
IT NachrichtenMicrosoft puts Brad Smith in charge of communications(25.09.2026 um 00:08 Uhr)
••
Intelligence View
⚡ tsecurity.de Intelligence

Stop Using OFFSET for Pagination: Why Keyset Cursors Scale and LIMIT/OFFSET Doesn't

--- title: "Stop Using OFFSET for Pagination — It Won't Scale" published: true description: "LIMIT/OFFSET pagination degrades linearly with dataset size. Let me walk you through keyset cursor pagination for consistent O(1) performance at a…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

---
title: "Stop Using OFFSET for Pagination — It Won't Scale"
published: true
description: "LIMIT/OFFSET pagination degrades linearly with dataset size. Let me walk you through keyset cursor pagination for consistent O(1) performance at any page depth."
tags: postgresql, api, architecture, performance
canonical_url: https://blog.mvpfactory.co/stop-using-offset-for-pagination
---

## What We're Building

By the end of this tutorial, you'll understand exactly why your paginated queries slow down as your dataset grows — and you'll have a working keyset cursor pagination pattern you can drop into any REST or GraphQL API. We'll use PostgreSQL and Kotlin (Ktor), but the principle applies everywhere.

## Prerequisites

-
Basic SQL knowledge (SELECT, WHERE, ORDER BY)
- A PostgreSQL database with a non-trivial table (thousands of rows)
- Familiarity with any backend framework (examples use Ktor)

## Step 1: See the Problem With Your Own Eyes

Here is the minimal setup to get this working. Run these two queries against any table with 100K+ rows and compare:







sql

-- OFFSET approach (page 5000, 20 rows per page)

EXPLAIN ANALYZE

SELECT * FROM orders ORDER BY id LIMIT 20 OFFSET 100000;



-- Result: Seq Scan on orders

-- Planning Time: 0.08 ms

-- Execution Time: 112.45 ms (scanned 100,020 rows)











sql

-- Keyset approach (same logical page)

EXPLAIN ANALYZE

SELECT * FROM orders WHERE id > 100000 ORDER BY id LIMIT 20;



-- Result: Index Scan using orders_pkey

-- Planning Time: 0.07 ms

-- Execution Time: 0.12 ms (scanned 20 rows)





That's ~900x faster at this depth. PostgreSQL scans 100,020 rows with OFFSET, discards 100,000, and returns 20. The keyset query does an index seek directly to the starting point, then reads exactly 20 rows. Consistent O(log n + k) performance where k is your page size.

## Step 2: Build a Cursor-Based API Response

Your API returns an opaque `next_cursor` that the client passes back on the next request:







json

{

"data": [...],

"pagination": {

"next_cursor": "eyJpZCI6MTAwMDIwfQ==",

"has_more": true

}

}





The cursor is a Base64-encoded representation of the last row's sort key. Here's the server side in Ktor:







kotlin

get("/orders") {

val cursor = call.parameters["cursor"]

?.let { Base64.decode(it) }

?.let { Json.decodeFromString(it) }



val orders = db.orders
.run { if (cursor != null) where { id greater cursor.lastId } else this }
.orderBy(Orders.id)
.limit(20)
.toList()

val nextCursor = orders.lastOrNull()?.let {
Base64.encodeToString(Cursor(lastId = it.id))
}

call.respond(PagedResponse(orders, nextCursor))



}





Let me show you a pattern I use in every project — Spring Boot follows the same shape: decode the cursor, apply a `WHERE` clause, encode the next cursor from the last result.

## Step 3: Handle Non-Unique Sort Columns

When sorting by a non-unique column like `created_at`, you need a composite cursor with a tiebreaker. The docs don't mention this, but without it, rows with identical timestamps get skipped or duplicated.







sql

SELECT * FROM orders

WHERE (created_at, id) > (:last_timestamp, :last_id)

ORDER BY created_at ASC, id ASC

LIMIT 20;





This tuple comparison leverages PostgreSQL's row-value comparison and can use a composite index on `(created_at, id)` efficiently.

## Step 4: GraphQL — You're Already Set Up

If you're building a GraphQL API, the Relay Connection specification was built for exactly this:







graphql

query {

orders(first: 20, after: "eyJpZCI6MTAwMDIwfQ==") {

edges {

node { id total createdAt }

cursor

}

pageInfo { hasNextPage endCursor }

}

}





## Gotchas

Here's the gotcha that will save you hours:

- **No arbitrary page jumping.** Keyset cursors don't support "jump to page 50." If you need numbered pages on large datasets, use a hybrid: keyset pagination under the hood with a separate cached count query for the page count display.
- **Always include a unique tiebreaker.** Sorting by `created_at` alone will silently skip or duplicate rows when timestamps collide. Always add `id` as a secondary sort.
- **OFFSET is fine for small datasets.** Under ~10,000 rows, users never paging past the first few pages, admin dashboards with modest data — OFFSET works. The problem is when teams pick OFFSET as a default and never revisit the decision as data grows.
- **Duplicate/skipped rows with OFFSET.** When rows are inserted while a user pages forward, rows shift between pages. Cursors are stable — they point to a fixed position in the sort order.

## Conclusion

Run `EXPLAIN ANALYZE` on your paginated queries at realistic offsets — page 100, 500, 1000. If execution time grows linearly with the page number, you've got a problem that will only get worse. For any API-facing or feed-style pagination, default to keyset cursors. Encode composite cursors from day one so you handle the non-unique sort column case before it bites you.


SOC Incident Playbook: Vulnerability Remediation & Verification
1 Warnungen
title: Detect Exploitation - Stop Using OFFSET for Pagination: Why Keyset Cursors Scale and LIMIT/OFFSET Doesn't
id: 8b352022-66a8-4c0a-8620-a55f2ec5d7ab
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-25
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-25"
        description = "YARA Signature for "
    strings:
        $str = "Stop Using OFFSET for Paginati" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("Stop Using OFFSET for Pagination Why Key")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*Stop Using OFFSET for Pagination Why Key*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "Stop Using OFFSET for Pagination Why Key"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc
🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Stop Using OFFSET for Pagination: Why Ke.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Stop Using OFFSET for Pagination: Why Keyset Cursors Scale and LIMIT/OFFSET Doesn't

Thematisch verwandte Begriffe: Stop, Using, OFFSET, Pagination · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-87722 | Uncontrolled Resource Consumption (CWE-400 / CWE-1333) in regex search q…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel • Rechts: nächster Artikel • unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...
↗ Original-Quelle