Urgent.News

What's breaking now, across thousands of outlets.

Tech

To Retry or Not to Retry: Safe Retry Logic with Exponential Backoff, Jitter and Idempotency Keys

Hồi trước team mình từng có một sự cố khá kinh điển: payment provider chập chờn khoảng 30 giây, và trong 30 giây đó service của bọn mình gửi 4 lần request charge tiền cho cùng một đơn hàng. Lý do là có 3 tầng cùng retry: SDK của client, service gọi API, và cả job queue phía sau. Không tầng nào sai nếu xét riêng, nhưng gộp lại thì thành thảm họa. Sau lần đó mình rút ra một điều: retry không phải…

In a previous incident, the team faced a notable issue where a payment provider took about 30 seconds to respond, and during that time, their system sent four requests to charge the same order. This happened due to three layers of retry: the client's SDK, the API service, and the job queue behind it. While no single layer was at fault, the outcome was disastrous.

From that experience, they learned that retry is not an added feature to ensure reliability. In fact, if it leads to incorrect behavior, it can be more dangerous than not retrying at all.

This article shares their approach to retry logic in production: when to retry, how to do it without overloading their system, and how to ensure safe retry for requests with side effects. The first question to ask before writing any code is whether the request should be retried. Before writing any code, they need to answer two questions: is this a temporary error (transient) or something else?

Does the 429 (Too Many Requests), 503 (Service Unavailable), 504 (Gateway Timeout), or 400/401/404/422 status code indicate a transient error? 400, 401, 404, 422 do not benefit from multiple retries. Is this request idempotent, or does it have an Idempotency-Key? HTTP GET, PUT, and DELETE methods are idempotent, while POST is not.

Retrying a POST /charges request that timed out is the quickest way to charge a customer twice, as timing out doesn't mean the server hasn't processed the request. There's a chance the server already processed it, and the response simply didn't reach the client.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Build Notes: A Browser-Local Image Compressor for Everyday Upload Problems

I built Quick Image Kit as a small browser-local image toolkit: quickimagekit.com The product is intentionally practical. Many people do not need a full photo editor.

  • Browser-local image compression tool designed for everyday upload problems
  • Handles personal data safely without uploading to remote servers
  • Provides clear, understandable interface for image resizing and compression

My barcode generator encoded whatever I gave it — the check digit is the scanner's only trust

Two months ago I added barcode symbologies to what had been a plain QR endpoint — code128, EAN-13, UPC-A. My test suite verified the images rendered and that my phone could decode them.

  • Author expanded QR code endpoint to support barcode symbologies
  • Partner scanned EAN-13 labels with handheld laser scanner, received invalid read error
  • Author implemented fix with rules for twelve-digit UPC-A codes and check digit validation

Custom Functions in CSS

CSS already has plenty of useful functions, like calc() , min() , max() , and clamp() . They let you build more flexible styles without repeating the same logic.

  • CSS already has functions like calc(), min(), max(), and clamp()
  • @function at-rule defines custom functions with parameters and results
  • Custom functions can accept multiple parameters, type declarations, and defaults

More from Thursday 8 October →