Skip to content

Rate limiting idempotency

Rate Limiting & Idempotency Deep Dive

Overview

Rate limits prevent abuse. Idempotency enables safe retries.

Core Concepts

Rate limit headers: - X-RateLimit-Limit - X-RateLimit-Remaining - X-RateLimit-Reset - Retry-After Idempotency-Key: UUID for deduplication

Code Examples

// Add Idempotency-Key to POST
val requestBody = RequestBody.create(...) 
val request = Request.Builder()
    .post(requestBody)
    .addHeader("Idempotency-Key", UUID.randomUUID().toString())
    .build()

Senior-Level Insights

  • Respect rate limits (back off exponentially)
  • Per-user vs global limits
  • Circuit breaker on repeated 429s