Urgent.News

What's breaking now, across thousands of outlets.

Tech

Idempotent webhooks in Node.js: handle every event once, even when it's delivered twice

Webhook providers deliver at least once : if your endpoint is slow, returns an error, or the response is lost on the way back, they send the same event again. A handler that sends an email or charges a card on every delivery will eventually do it twice. The fix is an idempotent handler : claim the event ID in the database with a unique constraint before doing the work, mark it done afterwards,…

Webhook providers deliver events at least once. If your endpoint is slow, returns an error, or the response is lost, the same event is sent again. To handle this, you need an idempotent handler that claims the event ID in the database with a unique constraint. If the work fails, you mark it as done and release the claim so the retry can run it.

The claim must be an atomic operation to prevent duplicate processing when multiple deliveries arrive together. Responding with a 200 status before doing the work allows a crash to lose the event entirely and for the provider to retry. The event ID should be used as a primary key in the database. Use the same SQL for PostgreSQL as well.

The claim checks if the event is still processing and has been untouched for five minutes, indicating the original worker is dead and the new delivery takes it over. If the side effect fails, the claim is released, allowing a retry. This method ensures the side effect runs at most once at a time and once after it succeeds. However, if the email is sent and the process crashes, the email may be sent again due to the gap between the claim and the finish operation.

This cannot be fully resolved within the database alone since the email provider is separate. To make the side effect itself idempotent, pass an idempotency key to the downstream API when supported. Use that key in the same transaction when making changes to the database. This way, repeats are harmless. Verify the signature first to prevent forged requests from filling your table.

Don't rely on the event coming from localhost as proof of authenticity. Respond quickly to prevent queue buildup if the work is slow. Use the provider's event ID, not a body hash. Retries might differ in fields like delivery timestamp. Delete old rows after the provider's retry window has passed to keep the database clean.

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

Push to Talk: the Backend Problem Is Not Audio, It Is Partial State

Push to talk looks like a small feature. Record, send, play. The backend tells a different story, and the whole thing turns on one requirement that sounds impossible the first time you hear it.

  • Push to talk functionality is more complex than it appears
  • Server must manage partial audio stream state for many messages
  • System uses shared database and sequence numbering for scalability

Hand Off Your Vector Search POC: A README and RECREATE.md for Amazon OpenSearch Service

The proof of concept worked in my account. The real test was whether the customer's team could build it again in theirs. A customer evaluating Amazon OpenSearch Service as a vector store asked for two…

  • Amazon OpenSearch Service handled 300 queries per second with 4,096-dimensional vectors
  • CloudFormation template deployed OpenSearch 3.7 with r8gd.8xlarge data nodes in VPC
  • Faiss HNSW indexing with GPU acceleration achieved sub-50ms latency

What Is a ClickFix Scam? How a Fake CAPTCHA Installs Malware

Originally published at warnscams.com You click “Verify you are human.” A small window pops up. It asks you to press Windows + R, then Ctrl + V, then Enter.

  • ClickFix scam deceives users with fake CAPTCHAs to run malicious commands.
  • Users click links from compromised websites leading to the scam page.
  • Fake CAPTCHA instructs pressing Windows + R, Ctrl + V, and Enter to install malware.

More from Wednesday 18 November →