Urgent.News

What's breaking now, across thousands of outlets.

Tech

Distributed API Rate Limiting & Idempotency at Scale: Redis Keyspace Architecture & Lock Patterns

Distributed API Rate Limiting & Idempotency at Scale: Redis Keyspace Architecture & Lock Patterns Protecting high-throughput public APIs requires two non-negotiable guarantees: shielding downstream services from traffic spikes and guaranteeing that duplicate client payloads execute exactly once. Here is how to engineer scalable rate-limiting and idempotency subsystems using Redis. 1. Distributed…

This brief discusses the implementation of distributed API rate limiting and idempotency at scale using Redis keyspace architecture and lock patterns. The author highlights the importance of shielding downstream services from traffic spikes and ensuring that duplicate client payloads execute exactly once. To achieve this, the author describes two main approaches: Sliding Window Log Pattern for distributed rate limiting and an Idempotency Layer for eliminating duplicate side effects caused by network timeouts, client retries, and webhook delivery loops.

The Sliding Window Log Pattern is implemented using Redis sorted sets (ZSET) to track timestamps for every request in a sliding time range, prune expired tokens atomically, and evaluate current volume in O(log N + M) time complexity. The Idempotency Layer employs a state machine with three states: IN_PROGRESS (Mutex Lock), COMPLETED (Cached Response), and FAILED.

A distributed lock is acquired on idempotency:{tenant_id}:{key} with a short TTL (e.g., 30 seconds) to prevent concurrent race condition executions. Once the handler finishes successfully, the status and serialized HTTP response body are cached in Redis with a long TTL (e.g., 24 to 72 hours).

Brief written by urgent.news from Dev.to's own syndicated text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Polymarket Execution Verification: When “Filled” Doesn’t Mean Settled

A Polymarket trading bot can receive a successful execution response and still not know enough to safely continue trading. That sounds like a small implementation detail. It isn't.

  • Polymarket's bot receives execution responses even before full settlement.
  • System distinguishes between trade completion and transaction information availability.
  • Explicit state machine needed to avoid incorrect assumptions about trade status.

Moving on-premises block storage to AWS? The "divide by 625 MBps" sizing approach comes out wrong

Moving on-premises block storage to AWS? The "divide by 625 MBps" sizing approach comes out wrong — measured session and queue counts What this article does and does not cover: it covers the measured…

  • Dividing throughput by 625 MBps to determine sessions is inaccurate.
  • Testing shows method fails to capture system's true potential.
  • Approach not recommended for AWS block storage sizing.

More from Wednesday 30 September →