
Concurrent retries must converge on one persisted application operation and one Imagild idempotency key. Two workers generating separate keys for the same approved action are submitting separate operations, even if their JSON bodies match. Use a database uniqueness boundary locally, then reuse the winning record's key at the remote boundary.
Key Takeaways
- Coordinate intent in durable storage rather than only an in-memory lock.
- Every worker recovering one operation must use its saved request and key.
- Local coordination plus remote reuse reduces duplicates without proving global exactly-once execution.
Identify the race you need to prevent
Suppose a queue delivers the same message twice. Worker A and worker B each load the same creative brief. If each calls randomUUID() immediately before submission, both requests have distinct identities and can authorize two paid generations.
An application mutex can reduce overlap inside one process, but it does not coordinate another process or survive a restart. Make the approved action a durable database record before either worker calls the paid endpoint.
AWS's safe-retry discussion explains why distributed retries need explicit operation identity. The relevant Imagild contract is same-account, same-key reuse with the same parsed parameters.
Put uniqueness around the approved intent
This PostgreSQL example illustrates the local coordination boundary. It is an application table, not an Imagild API object or a complete authorization implementation.
CREATE TABLE media_operation (
account_ref text NOT NULL,
intent_id uuid NOT NULL,
remote_key varchar(128) NOT NULL,
request_snapshot jsonb NOT NULL,
task_id uuid,
local_state text NOT NULL DEFAULT 'prepared',
PRIMARY KEY (account_ref, intent_id),
UNIQUE (account_ref, remote_key)
);
Here account_ref identifies the intended owning Imagild account in your application's records. It must not contain the API secret. Enforce your own tenant permissions before allowing a user or worker to read or update this table.
When two transactions attempt to create the same approved intent, only one record should become authoritative. The losing transaction must reload that persisted record and use its key. Do not continue using a locally generated candidate key that lost the database race.
Keep dispatch and response recording separate
A worker can follow this sequence:
- Load the authorized operation and its saved request snapshot.
- Claim dispatch work through your application's transaction or lease policy.
- Submit the stored payload with the stored
Idempotency-Key. - Save the returned
data.idagainst that operation. - Poll by task ID, updating status without replacing the original request.
A lease can expire while a slow network call is still in flight. That is why the remote key remains necessary even when local dispatch is coordinated. If a second worker recovers the same operation, it sends matching parameters and the same key rather than treating lease expiry as permission for a new generation.
The API console documents task submission and reuse. Changed parsed parameters under the same key produce a conflict; investigate the mismatch instead of silently replacing the key.
Test a crash at each boundary
Use fixture responses to simulate a crash after the local record is committed, after the remote request is sent, and after acceptance arrives but before task_id is saved. In each case, restart the worker and inspect the outbound operation key.
The expected property is stable identity and recoverable state. Do not claim that these checks prove every upstream side effect happened exactly once. If the task reports an unknown outcome, keep the record unresolved and reconcile it.
Also verify that concurrent status updates cannot erase an already saved task ID or overwrite a terminal result with a stale local state. Database constraints and update conditions belong to your implementation.
Protect the shared budget
A new 1K image uses 10 points, 2K uses 15, and 4K uses 20 under the current model market schedule. Active membership is required, and keys under one account share its resources.
Use points and job planning to quote intentional work. Follow the failed-job decision guide for uncertain or failed tasks. Concurrency control should preserve the original approval, not hide extra generations behind an automatic retry policy.
Related tasks
- Imagild Points, Resolution and Jobs: Plan a Creation Before You Spend
- What Should You Check Before Retrying a Failed Image or Video Job?
Sources and scope
- Imagild API console: Same-account idempotency reuse, parameter conflicts and asynchronous task recording.
- Imagild model market: Current price schedule for intentionally new image operations.
- AWS safe retries with idempotent APIs: Explicit caller identity and durable intent are needed when distributed retries race or outcomes are uncertain.
Product instructions were checked against the current Imagild API contract and the public model catalog. Code, budgets and acceptance checks are illustrative; this article does not claim a new paid generation test, an uptime measurement, a search-volume study or a ranking of AI citations.
Prepared by Imagild Editorial, the company editorial team responsible for these guides. AI assisted research and drafting. This is documentation-based guidance with proposed examples, not a claim of hands-on testing or an independent product review. Report a correction.
Cover: Original Imagild product screenshot captured on 28 October 2026; model availability and prices may change. This image is not an API response or a performance benchmark.