Systems and executionIntermediate25 min read

The same message twice should not create two economic effects

Understand idempotency through hypothetical robot records: event identity, repeated fills, concurrent processing, ambiguous responses, retention and corrections.

Two identical cream envelopes beside a single brass letter slot in a deep blue door
Conceptual photograph: repeated delivery does not necessarily mean a new intention.

The second envelope contains the same event

A hypothetical account report confirms a twenty-unit partial execution. The research adapter records twenty units. A connection interruption occurs, the event stream resumes and the same confirmation appears again. If the adapter adds another twenty, the local ledger now claims forty units even though the external event occurred only once.

The network did not necessarily fail by repeating the message. Repeated delivery can be part of a recovery mechanism that prefers replaying uncertain information to silently losing it. The failure is in treating every arrival as a new economic fact. A count of received messages is not a count of distinct executions.

Idempotency means that repetition preserves the intended effect. In this example, processing the same identified execution again should leave the economic record at twenty units. The second arrival can still be logged for diagnosis. Preventing a duplicate position does not require pretending that the repeated message never arrived.

This article uses hypothetical records and documentary tests to explain that distinction. It does not contain executable account instructions. The objective is to help a researcher review an adaptation’s treatment of identity, retries and uncertainty before relying on its reports. Correct duplicate handling improves the integrity of evidence; it does not establish a trading edge or guarantee an external service’s behavior.

Name the effect before claiming it happens once

The word idempotent is meaningful only in relation to a defined effect. Repeating an assignment that sets a field to a specified value can leave the same final field value. Repeating an instruction that increments that field usually changes it again. The two operations can use identical-looking inputs while having different repetition semantics.

The HTTP semantics standard defines idempotency in terms of the intended server-side effect of repeated requests, rather than requiring identical response bytes or prohibiting every diagnostic side effect. RFC 9110, idempotent methods. Our robot examples apply the underlying distinction to documentary state transitions; an HTTP method name alone does not establish an application’s economic guarantees.

For the partial-execution example, define the effect as incorporating one externally identified twenty-unit execution into a local economic ledger. A repeated arrival should not increase quantity, realized result, fees or the strategy’s execution count again. A receipt log may contain two arrivals because that log describes transport observations rather than distinct economic events.

Exactly one intended effect is not the same claim as exactly one message delivery. A design can tolerate repeated delivery while protecting a local effect. Conversely, a transport that appears to deliver each message once does not protect against a user importing the same file twice or two components independently interpreting one decision as new.

Write the invariant in plain language before considering mechanisms: one identified event contributes its quantity once to this ledger under this scope and version. That sentence exposes the boundaries of the claim. It also makes clear which effects still need separate reasoning, such as a notification, a report export or an external action not covered by the local ledger.

Separate a decision, a request and an execution

A trading-related workflow contains several identities. A strategy decision describes an economic intention under a particular information set. A request is one attempt to communicate or query something about that intention. An execution is an externally reported event. These identities can have one-to-many relationships and should not be collapsed into a single timestamp.

In a hypothetical record, decision D17 leads to request attempts R31 and R32 after a response is lost. Both attempts refer to the same decision. The external record later contains execution E80 for twenty units and E81 for thirty units. E80 and E81 are distinct partial executions belonging to the same broader intention, not duplicates merely because the decision identifier matches.

Choose the identity at the level of the effect being protected. Deduplicating all execution reports by decision D17 would incorrectly discard E81. Deduplicating new decisions by request attempt would fail to recognize that R31 and R32 may describe the same intention. A useful schema preserves the relationships instead of asking one identifier to answer every question.

A timestamp alone is often insufficient. Two legitimate events can share a timestamp at the available resolution, and a repeated event can arrive at a different local time. Price and quantity alone are insufficient for a similar reason: two distinct partial executions can legitimately occur at the same price and size.

The order-lifecycle article explains the broader event vocabulary. For idempotency, the practical question is narrower: what evidence proves that this arrival refers to the same effect already incorporated? If the source does not provide an adequate identity, the limitation should be explicit rather than hidden behind a convenient equality test.

A hypothetical decision D17 has two request attempts R31 and R32 and two distinct execution events E80 and E81; identifiers protect different levels of effect
One intention can involve multiple attempts and multiple genuine executions. Duplicate detection needs the right identity level.

Identical parameters can still express a new intention

Suppose two hypothetical decisions both concern the same instrument, side and quantity. The first is made in one eligible session; the second is made later after the rules independently produce another signal. Their parameter lists can be identical while their economic intentions are distinct. A hash of parameters alone can wrongly suppress the second.

The opposite problem occurs when a retry receives a fresh identity every time. The same unresolved intention can then look like several new operations. The design needs a stable identifier for repetition of one intention and a genuinely new identifier for a separately authorized intention. Similar appearance does not decide which category applies.

AWS’s Builders’ Library discusses caller-provided request identity and the danger of inferring duplicate intent solely from matching parameters. It also describes rejecting a reused identity paired with changed parameters. Making retries safe with idempotent APIs. These are useful design concepts, not evidence that a particular trading provider implements that contract.

Identity and meaning must remain linked. If the record says request K9 originally described one hundred units, a later arrival using K9 for two hundred should not silently inherit the first request’s success or create an unexplained additional effect. It represents a semantic conflict that needs a defined outcome in the documentary model.

A content digest can help detect such a conflict after identity is established. It should cover the relevant canonical meaning, not incidental differences such as whitespace or a local receipt timestamp. The digest is an integrity aid; it does not replace the decision about whether two otherwise identical parameter sets represent one intention or two.

There is an upstream failure that a technically correct duplicate filter cannot repair. Imagine a hypothetical decision loop that evaluates the same completed bar twice and invents a fresh decision identity each time, even though the rule permits only one intention for that bar and signal. Every downstream key is unique. The duplicate filter correctly sees distinct identifiers while the strategy has already violated its own decision contract.

That case requires examining what creates a new intention. A bar reference, strategy version and signal occurrence can help document the intended decision boundary, but they are not a universal key recipe. Some rules legitimately permit several decisions within one bar; others permit only one across a longer episode. The identity design must reflect that meaning rather than suppress activity by an arbitrary clock bucket.

Keep the two review questions separate. First, did the strategy create the right number of distinct intentions under its stated rules? Second, did communication and event processing preserve each intention’s intended effects under repetition? Passing the second does not establish the first. A reliable delivery mechanism can faithfully carry an incorrectly duplicated business decision.

For a paper test, include a repeated evaluation of the same frozen information set and state what novelty the rule permits. If the expected answer is one intention, the test should inspect decision creation before transport. This closes a gap that would remain invisible in tests containing only repeated messages with an already stable identifier.

Scope keeps unrelated events from colliding

An external event reference may be unique only within an account, provider, session or another documented namespace. Treating it as globally unique can cause a legitimate event from one scope to be discarded because another scope previously used the same reference. A short identifier that looks distinctive is not proof of global uniqueness.

Imagine hypothetical account A and account B both reporting event 700. They are separate events in their respective account namespaces. A deduplication record keyed only by 700 would incorrectly treat the second as a duplicate. A documented composite scope preserves account identity along with the source’s event reference.

The scope of uniqueness belongs in the contract. Include only fields necessary to distinguish the intended domain, and keep their interpretation stable. Adding an ever-changing process identifier can defeat deduplication across restarts. Omitting the environment can merge demonstration and other records that should remain separate. Both mistakes arise from treating an identifier as a magic string rather than a scoped claim.

Version changes require similar care. A new interpretation of an event may need a new derived-report version, but it does not make the original economic event happen again. The same source identity can be associated with multiple explicitly versioned analytical views while contributing only once to each defined view.

The restart-state discussion shows why identity must survive an interruption. If a new process invents a fresh namespace for every old event, the durable record cannot recognize replayed history. The identifier design should match the effect’s intended lifetime, not the convenience of the current in-memory session.

Incremental and cumulative quantities require different reasoning

Return to the hypothetical twenty-unit execution E80. If the source reports a new incremental fill of twenty, incorporating that unique event increases cumulative filled quantity by twenty. Receiving E80 again should leave the cumulative total unchanged. A distinct event E81 for thirty increases it to fifty.

Another source view might report cumulative filled quantity directly. A first summary says twenty; a later summary says fifty. Adding both summaries as if they were incremental fills would produce seventy, even without any duplicated message. The problem is semantic interpretation before it is duplicate handling.

Know whether a quantity is a change or a total. In the cumulative view, repeating the same twenty-unit summary may be harmless under an appropriate state-assignment model, but applying a stale twenty after a newer fifty can incorrectly move the state backward. Idempotency for repeats does not automatically solve ordering between different updates.

For a documentary ledger, preserve the source field’s meaning, event identity and version or ordering reference. A derived cumulative quantity can then be checked against the sum of unique incremental events where both views are available. Agreement is useful evidence; disagreement points to missing events, repeated application, corrections or an interpretation mismatch.

The example’s correct final quantity is fifty, not seventy and not twenty. The route to fifty depends on whether the input consists of unique deltas or ordered cumulative states. A generic operation that adds every received number cannot distinguish these cases, even if the surrounding software calls itself event-driven or reliable.

Unique increments of twenty and thirty total fifty; a repeated twenty is ignored economically, while cumulative summaries twenty then fifty must not be added to seventy
Repeated delivery and confused field meaning are different sources of duplication. The expected total must be defined independently of the arrival count.

Two simultaneous readers can both believe an event is new

A conceptual check-then-record sequence can fail under concurrency. Imagine two workers reading the same hypothetical event E80. Each checks a local record and sees that E80 has not yet been incorporated. Each then applies twenty units. The final ledger contains forty, even though each worker performed a duplicate check.

The missing property is not another string comparison. It is a consistency boundary that prevents both workers from claiming the same effect independently. A documentary review should ask whether recording the event’s accepted identity and updating the protected state occur under an appropriate atomic rule for the actual shared storage.

A uniqueness rule is useful only at the scope where competing writers meet. Two separate in-memory sets do not coordinate with each other. Two files on unrelated machines do not become one authority because they use the same filename. The mechanism must cover the writers whose concurrent behavior the claim is intended to constrain.

SQLite documents unique constraints as a database mechanism for excluding repeated key combinations, subject to its defined semantics. Table constraints. A constraint can help protect a local record, but it does not by itself prove that every associated external effect occurs once. The transaction boundary and field semantics still matter.

In a paper test, represent the competing interleavings explicitly. Both workers observe absence; one obtains the right to incorporate; the other recognizes the existing result or a documented in-progress state. The expected ledger should contain one twenty-unit contribution. This is a review of a consistency requirement, not a prescription for an operational account-control implementation.

Protecting one record does not protect every side effect

Suppose processing E80 updates a local quantity, appends an analytical row and creates a notification record. A duplicate check around only the quantity update can leave the other effects duplicated. Conversely, marking the event processed before any effect completes can cause a later replay to skip work that never actually happened.

The word processed therefore needs a defined boundary. Does it mean the event was received, validated, incorporated into the ledger or reflected in every downstream view? A single boolean can blur those stages. A more precise documentary state model makes partial completion visible and identifies which effects can be reconstructed from authoritative inputs.

Each protected effect needs its own completion evidence. A derived report that can be rebuilt from unique ledger events has a different recovery problem from an external action whose outcome may be unknown. The local ledger can be the source for replayable analytical views without pretending to control every remote system atomically.

For the hypothetical notification, repeated delivery might be undesirable but economically different from a duplicated position. The design can treat receipt logs, analytical materializations and user-facing messages under distinct policies. The important point is to avoid claiming end-to-end exactly-once behavior from a guarantee that covers only one local table.

The review should draw the boundaries of the claim: which state transition is atomic, which downstream work can repeat safely and which unresolved effects need reconciliation. That boundary diagram is often more informative than a broad assurance that the pipeline handles duplicates, because it identifies precisely where that assurance stops.

A timeout tells you about a response, not necessarily the outcome

A hypothetical client waits for a response and reaches its time limit. That establishes that it did not receive the expected response in time. It does not establish whether the remote service received, accepted or completed the underlying intention. The outcome may be unknown even though the local timeout is perfectly clear.

Treating every timeout as a rejection can create repeated economic intentions. Treating every timeout as success can invent an outcome. A documented idempotent contract may permit a repeated request under the same identity, but the existence and limits of that contract must be established for the actual service and operation.

Retry policy and duplicate protection solve different questions. A waiting interval or a limited number of attempts can reduce load and control how long a process keeps asking. Neither creates idempotency if each attempt is interpreted as a new effect. Conversely, an idempotent effect does not guarantee that the client will ever receive a usable response.

For a documentary study, classify the result as confirmed, explicitly rejected or unresolved according to the available evidence. Preserve the request identity and the source’s status information. If the system cannot determine the outcome after its allowed observation process, the report should keep uncertainty rather than reclassify it to make a workflow appear complete.

Missing confirmation is not proof of missing effect. This distinction is especially important when comparing a local research ledger with an external record after an interruption. The purpose of a repeated observation or reconciliation is to learn what happened, not to manufacture certainty by assuming that silence means nothing occurred.

Duplicate handling does not make event order irrelevant

Two distinct events can each be processed once and still produce a wrong result when applied in the wrong order. Consider hypothetical cumulative state updates: version eight reports fifty units, while older version seven reports twenty. If version seven arrives later and blindly replaces the current value, the record moves backward despite perfect duplicate detection.

The ordering reference must follow source semantics. A larger-looking identifier is not necessarily a universal timestamp, and local receipt order may differ from event order. Some changes commute, meaning their order does not alter a particular aggregate; others do not. The report should establish which case applies instead of assuming every event stream is an unordered bag.

Idempotency, ordering and completeness are separate properties. Removing duplicate arrivals does not recover an event that never arrived. Correct ordering of received events does not prove that the interval has no gaps. A consistent reconstruction needs appropriate evidence for all three dimensions that matter to its state model.

In a small test, provide events in ordinary order, reverse receipt order and an order containing duplicates. Define the expected state using the source’s actual version or event semantics. If an event gap prevents a valid answer, the expected result can be an unresolved state rather than a guessed total.

Do not let a duplicate filter hide a missing-event problem. A high rate of discarded repeats can coexist with an incomplete history. The useful diagnostic distinguishes unique received events, repeated arrivals, rejected conflicts and unresolved sequence gaps. One count labeled errors cannot explain which property failed.

A retention window limits how long repetition can be recognized

Duplicate recognition depends on retaining enough identity and completion evidence. If a hypothetical system remembers processed events for one hour, a replay arriving two hours later may look new after its record has been discarded. The protection claim is therefore bounded by the retention design and the possible age of repeated messages.

This is not solved simply by keeping every full payload forever. The necessary retained evidence may differ from the detailed diagnostic body, and privacy, storage and operational needs can vary. The documentary question is what minimum evidence preserves the intended identity contract for the relevant replay and recovery interval.

Deleting a completed object does not necessarily erase the need to remember its identity. A late repeat can refer to an intention whose visible object no longer exists. If absence is mistaken for never happened, the system may treat an old request as new. A retained completion marker can serve a different purpose from the active object’s current state.

For a hypothetical archive replay, define whether the exercise reconstructs a new analytical view or continues an existing effect ledger. A new view can intentionally process old source events once under its own versioned scope. Continuing the old ledger must recognize events already incorporated. Confusing these two activities can either double the result or suppress a legitimate rebuild.

The lifetime of the identity should match the lifetime of the claim. A short cache may be appropriate for a narrowly defined transient duplicate problem while being inadequate for recovery from an older backup. State the boundary rather than describing every use of a cache as permanent protection against repetition.

A correction is not the same as a repeated original event

An external or research source may correct a previously reported value. A hypothetical execution E80 was initially recorded with a fee of two units, then a later correction establishes three. Treating the correction as an identical repeat would preserve the wrong fee. Treating it as another full execution would duplicate quantity and potentially other amounts.

The correction needs its own documented relationship to the original event. A source may provide a revision identifier, a replacement version or an explicit reversal and new record. The local analytical model should follow that contract while retaining enough provenance to explain the change. It should not invent a correction convention solely from a changed payload.

Same identity with changed meaning is a conflict until the source semantics explain it. Sometimes it is a legitimate revision; sometimes it is corruption or an accidental reuse of a key. The report should distinguish those cases based on evidence, not automatically accept whichever payload arrived last.

In the hypothetical fee revision, the net analytical adjustment is one additional unit of cost, with no additional quantity. A replay of the same identified correction should not add another unit again. This demonstrates that correction events can require their own idempotency treatment even when the original execution was handled correctly.

Keep the original record and the revision relationship inspectable. Rewriting history in place without provenance can make a final total look correct while preventing a reviewer from explaining why an earlier report differed. A reproducible research archive should be able to distinguish the evidence available then from the corrected evidence used now.

Reimporting a CSV is the same problem in quieter clothing

Duplicate handling matters even in a research workflow with no continuous event stream. A person can import the same historical file twice, rename a copy or combine overlapping exports. If every row becomes a new trade without a source identity, a report can double profit and trade count while appearing statistically more substantial.

A file checksum identifies a particular byte artifact, but it does not automatically identify economic rows across different exports. Two files can contain the same trades with different column order or decimal presentation. Conversely, an identical-looking row can represent two legitimate events if the export omitted the identity that distinguishes them.

Define the import’s unit of identity before deduplicating. A provider event reference with its documented scope is stronger evidence than a guessed combination of price, size and timestamp. If the archive lacks a reliable identity, report the ambiguity and inspect overlaps rather than silently deleting rows that merely resemble each other.

For a hypothetical dataset containing E80 and E81, importing the same source records twice should leave one contribution per event in a continued ledger. Building a new versioned analytical dataset from the same raw archive is a different intended effect and should remain possible. The scope distinguishes an accidental repeated import from a deliberate reproducible rebuild.

This connection is useful when studying the free demo’s source material. Before interpreting an improved performance statistic, verify that the expanded sample contains new evidence rather than another copy of existing events. A larger file and a larger trade count do not establish a longer or more independent economic history.

A repeated response can differ without changing the original effect

Idempotency does not always require every repeated observation to return the same text. A request can refer to an object whose status has progressed since the first response. The client needs to understand whether it is receiving the recorded result of the original intention, a current status view or a conflict explaining that the identity was reused incorrectly.

For a hypothetical intention K9, the first usable response may say accepted and a later status view may say completed. Those statements can describe one evolving intention. A response saying already exists can be ambiguous if it fails to identify whether the object belongs to K9 or another earlier intention. The response contract should preserve traceability, not merely avoid another mutation.

Stable meaning matters more than identical display text. A reviewer should be able to connect each response with the protected identity and determine what evidence it supplies. A changed receipt timestamp is usually diagnostic; a changed quantity or account identity is semantically material and needs explanation.

Record enough information to distinguish successful duplicate recognition from silent suppression. If the system discards an arrival without explaining which prior effect it matched, later investigation becomes difficult. A concise duplicate record can contain the scoped identity, original incorporation reference and classification reason, without copying unnecessary sensitive payloads into every log.

The purpose is an auditable relationship between attempts and effects. A user or researcher should not have to infer from a green success message whether a new effect occurred, an existing result was recognized or the outcome remains uncertain. Precise status language is part of the reliability of the evidence.

A test matrix should include repetition, conflict and legitimate novelty

Begin with a simple hypothetical invariant: E80 contributes twenty units once and E81 contributes thirty once. Ordinary input E80 followed by E81 produces fifty. E80, E80, E81 also produces fifty. E81 followed by E80 can produce fifty for a sum of independent unique deltas, while cumulative-version updates require their separate ordering rule.

Then test cases that a simplistic filter gets wrong. Two distinct event identities with identical price and quantity should both remain. One identity in two valid account scopes should remain distinct. The same scoped identity with an unexplained changed quantity should become a conflict. An identified fee correction should change cost once while leaving quantity unchanged.

Test the absence of false suppression as well as duplicate prevention. A filter that discards every incoming record prevents duplicates perfectly and destroys the dataset. Correctness requires preserving legitimate new effects under the declared identity contract. This is why a good test set contains both repeated events and deliberately similar distinct events.

Add competing-worker interleavings, recovery from a checkpoint and a replay older than the retained identity window. The expected result should state which guarantees apply under those conditions. Where the design lacks evidence, require an explicit unresolved outcome rather than a fabricated complete result.

Expected results must come from the contract, not from the implementation under review. A hand-reconciled twenty-plus-thirty example is valuable precisely because it is independent of the software’s internal logic. The independent-code-review article explains how to preserve that separation when an AI helps write or inspect a research adapter.

A hypothetical test matrix preserves fifty units for E80 and E81 with repeats, keeps distinct identities, flags changed meaning under one identity and applies a fee correction once
A useful test set protects both sides of the contract: repeated effects do not multiply, and legitimate new events do not disappear.

A diagnostic count should also distinguish arrivals from identities. In a hypothetical interval, one hundred arrivals containing eighty unique scoped event identities have twenty extra arrivals. That can mean twenty events were each delivered twice, or one event was delivered twenty-one times while the other seventy-nine arrived once. Both cases have the same twenty-percent repeated-arrival share, but their timing and likely transport investigation differ.

Neither pattern proves that the economic ledger is wrong. If each identity contributes once, the protected total can remain correct despite a noisy transport. Conversely, zero observed repeats does not prove that legitimate events were never suppressed by an overbroad key. The diagnostic should therefore include both duplicate classifications and reconciliation against the authoritative event set where available.

Preserve a small trace for the cases that matter: the first incorporation reference, the repeated arrival references and the reason they were matched. This makes the metric explainable without turning every replay into an alarm or burying conflicts among harmless duplicates. Counts summarize behavior; identity-level evidence explains it.

Make the claim narrow enough to verify

A meaningful idempotency statement names the effect, its identity scope, the completion boundary, the retention interval and the handling of conflicts or corrections. It also states what remains outside the guarantee. That is more useful than saying the robot cannot duplicate anything, which combines several different technical and economic claims into an untestable promise.

For a bounded AI-assisted exercise, provide a small invented event ledger and ask for identity relationships, expected totals and a documentary test matrix. Require the assistant to separate duplicate arrival, distinct partial execution, cumulative summary, correction and unresolved response. The output should explain the evidence and its limits rather than control an account.

The free TradeAndRoll demo includes ten Forex systems, source material and original market CSVs for research. One event should contribute once to the effect you have actually defined. Learning to state and test that contract helps make an adaptation’s records trustworthy. It does not establish future profitability or remove execution and capital risk.

An idempotency review contract names the protected effect, scoped identity, completion boundary, retention interval and treatment of conflicts and corrections
A narrow, explicit contract can be tested. A broad promise about every message and every system cannot substitute for those boundaries.
Back to the Blog