By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Waypoint's credit execution endpoint receives an approval id and an amount. A client retries when the response is slow. Your task is to make the write path replay-safe: the second request with the same approval must return the original action id and amount, and the store must contain exactly one effect.
replayed status instead of executing again.WRITES: dict[str, dict] = {}
def execute_credit(approval_id: str, amount_cents: int) -> dict:
key = f"credit:{approval_id}"
if key in WRITES:
return {"status": "replayed", **WRITES[key]}
record = {
"action_id": f"act_{approval_id}",
"amount_cents": amount_cents,
}
WRITES[key] = record
return {"status": "executed", **record}
first = execute_credit("APR-2201", 4500)
retry = execute_credit("APR-2201", 4500)
print(first["status"], first["action_id"], first["amount_cents"])
print(retry["status"], retry["action_id"], retry["amount_cents"])
print("writes stored:", len(WRITES))Key takeaways
Derive the idempotency key from the approval identity, not from time or randomness.
Persist the result before reporting success, and return the stored result on replay.
Concurrency safety needs a durable store, a unique constraint and a transaction.
The client should not be able to tell a replay from the original success.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.