Skip to main content
CHEAT SHEET #04Quick Reference Architectureβ€’5 min read

REST API Design, Idempotency & Protocol Cheat Sheet

Production engineering guide for designing enterprise RESTful APIs, idempotency keys, pagination protocols, and resilient error handling.

FreeCheat SheetDatabasesAPIs

Production engineering guide for designing enterprise RESTful APIs, , pagination protocols, and resilient error handling.


1. The 6 Architectural Constraints of REST

Interactive Architecture Diagram
Synthesizing vector architecture diagram...
  1. Client-Server Separation: Separation of UI concerns from data storage concerns.
  2. Statelessness: Every request contains all necessary session tokens and parameters.
  3. Cacheability: Responses explicitly declare whether they can be cached via Cache-Control and ETag.
  4. Uniform Interface: Identification of resources via URIs; manipulation via standard representations.
  5. Layered System: Client cannot determine whether it is connected directly to end server or an intermediary.
  6. Code on Demand (Optional): Servers can temporarily extend client functionality (e.g., JavaScript).

2. HTTP Methods & Idempotency Matrix

HTTP MethodSafe? (No state change)Idempotent? (N calls = 1 call)Cacheable?Typical Use Case
GETβœ… Yesβœ… Yesβœ… YesRetrieve resource representations
HEADβœ… Yesβœ… Yesβœ… YesRetrieve response headers only (size, ETag)
POST❌ No❌ No⚠️ ConditionalCreate a new subordinate resource
PUT❌ Noβœ… Yes❌ NoComplete replacement of existing resource
PATCH❌ No❌ No (Can be made so)❌ NoPartial update / delta modification of resource
DELETE❌ Noβœ… Yes❌ NoRemove target resource
OPTIONSβœ… Yesβœ… Yes❌ NoCORS preflight & server capabilities

3. HTTP Status Codes Quick Reference

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

4. Pagination Design: Offset vs. Keyset (Cursor)

Pagination DimensionOffset-Based (?page=5&limit=20)Cursor / Keyset-Based (?cursor=eyJpZCI6MTB9)
SQL ImplementationLIMIT 20 OFFSET 80WHERE id > :last_id ORDER BY id ASC LIMIT 20
Performance at Scale❌ Severe degradation: DB scans and discards all skipped rows.βœ… O(1) index seek regardless of whether row is 10th or 10,000,000th.
Stability (Data Drift)❌ Missed rows or duplicates if records inserted while paginating.βœ… Deterministic: Cursor points to exact immutable position.
Random Page Navigationβœ… Jump directly to Page 42.❌ Only sequential Next / Previous scrolling.
RecommendationAdmin dashboards with small total counts (< 1,000 items).Mobile feeds, infinite scroll, high-scale public APIs.

5. Idempotency Key Implementation Pattern

When clients issue unsafe requests like POST /v1/payments, network timeouts can cause duplicate billing if retried without protection.

Interactive Architecture Diagram
Synthesizing vector architecture diagram...

6. Rate Limiting Headers Specification

Always return standard rate limit context in every HTTP response:

http
HTTP/1.1 200 OK
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 985
X-RateLimit-Reset: 1772841600
Retry-After: 60

7. Architectural Cross-References