BolEnglishLearn · Play · Win
Login

♻️ API & Integration · APIs & Integration

♻️

Idempotency

API ConceptAdvancedModule 5

Repeating the same request should not create unintended duplicate effects.

It is especially important when clients retry uncertain requests.

💡 In practice

A payment request with the same idempotency key does not charge the customer twice.

🖼️ CONCEPT PICTURE
A picture to help remember Idempotency
A payment request with the same idempotency key does not charge the customer twice.

💡 Like a light switch set to "on": flip it once or flip it five times, the light is still just on — no extra effect from repeating.

💡 Learn🛠️ Apply🎯 Check

💡 Why it matters

Networks drop responses, so a client often cannot tell whether its request really worked, and it retries. If the operation is idempotent, that retry is harmless. If it is not, retries create duplicate orders, double charges and other painful errors. Idempotency is what makes safe retries possible.

🛠️ How to achieve it

1
Use an idempotency key
Let the client send a unique key so the server can recognize a repeat of the same request.
2
Record what you did
Store the result against the key, so a repeat returns the first result instead of acting again.
3
Lean on safe methods
Reads and well-designed updates are naturally repeatable; be careful with create and charge operations.
4
Test the double-send
Deliberately send the same request twice and confirm only one effect occurs.

⚠️ Signs of trouble

  • •Retries create duplicate orders or records.
  • •Customers are charged twice on a flaky connection.
  • •There is no key to tell a repeat from a new request.
  • •The same action produces different totals each time it reruns.
⚠️ Common mistake: Treating every incoming request as brand new, so a retried create charges or inserts twice. Use an idempotency key and return the stored result for repeats.

🎯 Quick check

Score: 0/3

Three questions to test the idea.

  1. 1. What does idempotency guarantee?

    Answer: Repeating a request has the same effect as doing it once

    An idempotent operation can be repeated safely — doing it twice has the same effect as doing it once.

  2. 2. Why does an idempotency key help with payments?

    Answer: A repeated request with the same key does not charge twice

    The server recognizes the key as a repeat and returns the first result, so a retried payment charges the customer only once.

  3. 3. When is idempotency most important?

    Answer: When clients retry requests whose outcome is uncertain

    Dropped responses make clients retry without knowing if the first call worked; idempotency keeps those retries harmless.

🔑 Key terms

Idempotent
Doing it again has the same effect as doing it once.
Idempotency key
A unique id the client sends so repeats can be recognized.
Duplicate effect
An unintended second action, like a double charge.
At-least-once delivery
A message may arrive more than once, so handlers must cope.

✅ Review checklist

📊 Your progress

0%
Mark this topic learned to track it.
Saved in this browser.
🚀 Got it?
Mark it learned and move to the next topic.
Next topic →