Skip to content

Example: Safe Mutation with Idempotent POST Requests #49

@cinar

Description

@cinar

Description: Retrying a GET request is safe, but retrying a POST request (like executing a trade order or mutating a database record) can result in catastrophic duplicate actions if the network drops the HTTP response. This example demonstrates how to safely retry state-changing HTTP requests using Idempotency Keys.

  • Architecture & Implementation Requirements:

    • Setup: Create examples/http_idempotent/main.go.
    • Idempotency Logic: Generate a unique UUID or ULID before the resile.Do loop begins.
    • Header Injection: Inside the retry closure, inject this key into the HTTP request headers (e.g., Idempotency-Key: <uuid>).
    • Error Filtering: Use resile.WithRetryIfFunc to explicitly prevent retrying on 400 Bad Request or 401 Unauthorized, restricting retries exclusively to 500 Internal Server Error, 502 Bad Gateway, or 504 Gateway Timeout.
  • Acceptance Criteria:

    • The example must clearly show the difference between transient network errors (which get retried with the same key) and terminal business-logic errors (which push back and abort).
    • Target 90% code coverage on the custom error-filtering function to ensure no unsafe HTTP statuses are accidentally retried.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions