Urgent.News

What's breaking now, across thousands of outlets.

Tech

The silent retry bug killing ASP.NET Core reliability (and how idempotency keys save you)

The Silent Retry Bug: Why Your Resilient .NET System Is Actually Fragile If you’ve spent any time working with distributed systems in C# and ASP.NET Core, you know the drill: network calls fail, timeouts happen, and services become temporarily unavailable. The standard advice? Use Polly. Add a retry policy. Make it resilient. But here’s the hard truth: retries without idempotency are dangerous.…

When working with distributed systems in C# and ASP.NET Core, network issues like timeouts and service unavailability are common. The conventional solution is to use Polly, a library for resilience and transient fault handling, by adding retry policies. However, retries without idempotency can lead to data inconsistency. For instance, retrying a POST or PUT request might change the system state, leading to issues like double charges in a payment system or duplicate orders in an e-commerce platform.

This problem is referred to as the "duplicate-state problem," which is a hidden threat to system reliability.

Most retry strategies, including those from Polly, Hangfire, and Azure Service Bus, operate on the "at least once" delivery guarantee. This means they will retry if something seems to have failed, but without idempotency, a successful first call followed by a failed second call (or vice versa) can result in inconsistent data.

The solution to this issue is the use of Idempotency Keys. This involves generating a unique identifier (typically a GUID) for the operation, attaching it to the HTTP request (often in the Idempotency-Key header), and having the server check if this key has been seen before. If it's new, the server executes the business logic, saves the result, and records the key-result pair with a Time-To-Live (TTL). If the key is already present, the server skips the business logic and returns the stored result.

In ASP.NET Core, implementing this involves checking for existing results in a fast, distributed cache like Redis, executing the business logic if no existing result is found, and storing the key-result pair in the cache. It's recommended to encapsulate this logic in middleware or a filter for uniform application across all endpoints.

Using Polly, you can ensure that every retryable HTTP call includes the idempotency key, either by adding the header automatically for specific clients or by ensuring clients always provide it. For background jobs in Hangfire or Azure Functions, the same principle applies—ensure the underlying HTTP calls are idempotent to maintain data integrity during retries.

In summary, resilience in distributed systems isn't just about avoiding crashes; it's about maintaining data integrity during failures. Implementing Idempotency Keys for all state-changing endpoints and using a distributed cache to store these keys can safeguard your system against the "duplicate-state problem." Always test your retry logic by simulating scenarios like timeouts after successful writes to ensure your system doesn't create duplicate data.

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 an Admin Dashboard in React

An admin dashboard is mostly three things: a row of numbers that matter, a chart that shows the trend, and a table of recent activity.

  • Admin dashboard built with React using KPI cards, revenue chart, and recent activity table
  • Each KPI card displays label, value, change, and trend with color-coded indicators
  • Revenue chart shows monthly online and store revenue with automatic legend generation

Building a High-Performance Safari Content Blocker on iOS with Declarative WebKit Rules

Introduction: The State of Ad Blocking on iOS When developing ad-blocking solutions on iOS, developers face a major architectural choice between: Declarative WebKit Content Blockers (…

  • AdBlocker Pro uses declarative WebKit Content Blocker API for on-device rule execution.
  • Leverages modular content extensions to bypass strict rule count limits.
  • Achieves high performance with minimal memory footprint (~12 MB RAM).

Two things nobody was watching

First published on openspec-ui.dev . OpenSpec Workbench's whole pitch is watching an agent while it works. Two small fixes this week are about the product not watching itself closely enough - one…

  • Cleanup process stopped prematurely, leaving 54 MB Visual Studio Code file
  • DeepSeek CLI failed to read crucial usage number
  • OpenSpec Workbench fixed both issues with new changes

More from Tuesday 6 October →