Interview's MateSystem Design
Interview's Mate

System Design

Architecture & trade-offs

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
All topics/API Design & Gateways
DISTRIBUTED SYSTEMS & ARCHITECTURE · SUBTOPIC

Cursor Pagination & Idempotent APIs

Why OFFSET slows down on large tables and how idempotency keys make retries safe.

IntermediatePart of API Design & Gateways
Practice in AI HLD
Subtopics in API Design & Gateways (2)
OverviewREST vs. GraphQL/gRPCPagination & Idempotency

In plain words

Cursor pagination says "give me 20 posts after Post #940" instead of "count past the first 10,000 posts and skip them." Idempotency means pressing "Pay" twice because of weak Wi-Fi only charges once.

Think of it like…

Bookmarking page 120 (cursor) vs. counting 120 pages from page 1 every time (offset).

Loading interactive diagram
Loading interactive exercise

Theory & how it works

How Idempotency Keys work

The client generates a UUID (Idempotency-Key: abc-123) before calling POST /orders. The server stores (user_id, key) → saved response in Redis/SQL inside the same transaction. If the client retries 3 times due to timeouts, the server returns the saved original receipt without running the charge again.

Key points & practical guide

Summary checklist

  • Use cursor/keyset pagination for feeds and large datasets
  • Attach Idempotency-Key to all non-idempotent POST/payment calls
  • Return standard HTTP codes: 409 Conflict or cached 200/201 on duplicate keys

When to use it

  • Every infinite scroll feed and every payment/order endpoint

Watch out for

  • Allowing LIMIT 100000 from untrusted clients - cap page_size to e.g. 100

Quick check

Loading quiz
Previous subtopic
REST vs. GraphQL vs. gRPC
Back to overview
Full API Design & Gateways Lesson