Course contentsShow
← System Design
Lesson 1005 of 1,91926. Idempotency and RetriesFree lesson

Idempotency Time Windows

Learn why servers can't store idempotency state forever and how time-bounded windows balance safety and resources.

Idempotency Time Windows

What You'll Learn

You'll learn why servers can't keep idempotency state forever and how time-bounded windows balance safety with practical resource constraints.

The Eternal Storage Problem

In the previous lesson, you learned that servers store idempotency keys and their responses to prevent duplicate operations. But here's the catch: you can't store this state forever.

Imagine keeping a record of every single payment request ever made, indefinitely. Your database would explode in size, costs would skyrocket, and performance would degrade as you search through billions of old records.

The Time Window Solution

Idempotency time windows limit how long the server remembers an idempotency key. Common windows range from 24 hours to 30 days, depending on your use case.

Here's how it works:

  • Client sends a request with idempotency key abc-123 at 10:00 AM Monday
  • Server processes it, stores the key + response
  • For the next 24 hours (or your chosen window), any retry with abc-123 returns the cached response
  • After 24 hours, the key expires and is purged from storage
  • A new request with abc-123 after expiration is treated as a fresh operation

The Tradeoff

This creates a practical compromise:

  • Safety window: Protects against common retry scenarios (network blips, client crashes, reasonable user behavior)
  • Resource efficiency: State storage remains bounded and predictable
  • Risk acceptance: Very late retries (beyond the window) might re-execute

Think of it like a pharmacy's prescription pickup window: "We'll hold your medicine for 7 days." After that, they need the shelf space for new orders.

Choosing Your Window

Pick based on:

  • How long clients might reasonably retry (seconds? hours? days?)
  • Your storage capacity and costs
  • The severity of duplicate operations in your domain

Key Takeaway: Idempotency time windows let servers provide safety guarantees for a practical duration without infinite storage, balancing protection against duplicates with operational reality.