Run 4,000 events per minute and a TCP timeout becomes a statistical certainty somewhere in a billing window of any length. The request leaves, the response never comes back, and the agent does what any well-behaved client would: it sends that request again. An ingestion endpoint without idempotency turns the retry into a second billable event. Spread that across a pipeline running eight hours a day for 50 customer accounts and duplicates stop being theoretical.
None of this is glamorous work. It is still mandatory for a billing layer that sees agent-generated traffic. What follows: why agents create duplicates, how to design the key, how deduplication windows behave, and where the mechanism runs out.
The Retry Instinct Is Correct
Agent code normally makes network calls like this: send the request; on an error or timeout, retry with exponential backoff up to a ceiling. That behavior is right. Networks fail, and one transient hiccup should not cancel a pipeline three hours into its run.
Billing is where it gets awkward. At the endpoint, a retry looks exactly like a fresh event unless the agent says otherwise. A POST to /v1/events without an idempotency key is indistinguishable on its first attempt and its fourth. Nothing at the endpoint reveals whether this event has already been accepted.
Sparse traffic hides the problem. One duplicate in a hundred events over a monthly cycle may never reach a customer's attention. High traffic, or aggressive retry settings, compounds it. An agent retrying up to three times on timeout, running at 2,000 events per hour through a stretch of network instability, can produce a 15 to 20 percent duplicate rate in that window without anyone changing a line of code.
What the Key Buys You
The client generates the idempotency key: a stable label for one specific event attempt. On receipt, the endpoint asks whether a key like it was already accepted inside the deduplication window. If so, the original success response goes back and the event is not counted again. If not, processing proceeds and the key is stored.
Precision matters: the key should name exactly one logical event within one pipeline run. evt_wf_8821_step_14_call_001 ties the event to a workflow execution, a pipeline step, and a call sequence number. Three retries of the same call carry the same key; the endpoint keeps the first and discards the other two.
Timestamp-only keys such as evt_1723899012 fail. Two legitimate events from different agents can land in the same millisecond. The key needs enough context to stay globally unique across all customers for as long as the deduplication window lasts.
How Long Keys Are Remembered
The window is the endpoint's memory. Given a 24-hour window, any retry arriving within a day of the accepted event gets deduplicated; one arriving at hour 25 gets counted, whatever the reason.
Two pressures pull against each other when picking a length. Shorter windows cut memory: only recent keys need storing, and expired ones can be purged. Longer windows cover the case where a pipeline dies, restarts, and replays work from a checkpoint older than the original event.
A 72-hour window handles nearly every realistic retry and replay scenario while keeping the key store manageable. Paygentic defaults to 72 hours, held in a Redis-backed sorted set with TTL expiry and indexed by arrival timestamp. Each ingest request checks the key, records the event if it is new, and returns 200 with an idempotent flag in the body noting whether the event was fresh or a replay.
Where the Contract Breaks
Idempotency catches duplicate events that carry the same key. It cannot catch a client bug that mints a new key on every attempt instead of carrying the original through retries. Regenerate the key on retry and each attempt reaches the endpoint as a fresh event. No server-side deduplication repairs a client that mishandles its own keys.
Semantically identical events with different keys also slip through. An agent that processes the same input record twice—because of a pipeline bug or an at-least-once queue delivery—and generates a new key each time gets both accepted. The layer compares keys, not content.
The practical reading: idempotency is a contract of cooperation. The server supplies the mechanism; the client has to generate and propagate keys correctly. Paygentic SDKs handle generation and carry the key through retries automatically. Integrations that call the API directly must include idempotency_key in every payload and keep it stable across attempts.
What the Duplicates Cost
Take a customer processing 3 million events a month with a 5 percent duplicate rate: 150,000 extra billed events. At $0.0001 each, that is $15 a month for that one account. The dollar figure is not the real damage. A customer who finds a double charge traced to billing infrastructure rarely extends the benefit of the doubt. They leave, and they tell others.
Idempotent ingestion from day one avoids the whole sequence. Implementation is modest: a unique key field in the schema, a key store with TTL, a check on every ingest. One engineering investment, permanent correctness payoff. Retrofitting after an incident is the same work plus repairing the customer relationship.