Lesson 1 of 4 · 60 min

Investigate the payment that appears twice

Use a short trace to separate duplicated delivery from duplicated business effect.

A debugging interview measures whether you can reduce uncertainty. Start by translating the reported symptom into an observable claim. Two payment rows in an admin screen might represent two charges, two attempts for one charge, or a rendering error. These explanations require different fixes. Changing retry code before identifying the duplicated object can make the system less reliable.
Ask for one affected operation and the identifiers at each boundary. Useful fields include account, operation key, transport trace, provider charge, event, and local entitlement. Do not ask for full production payloads or credentials. A small redacted trace often carries the necessary relationship without exposing customer details. Time order helps, but stable identity is the stronger evidence when clocks differ.
State competing hypotheses and select an observation that separates them. If two local rows share the same provider charge, the provider probably did not create two distinct charges. The investigation then moves toward projection or deduplication. If the provider identifiers differ for one operation key, inspect the provider key actually sent and the contract used. If a dashboard duplicates one stored row, changing backend writes would be misplaced.
Keep mitigation separate from diagnosis. Temporarily stopping a harmful action can protect users while investigation continues. A mitigation does not prove the cause. Likewise, a local test that reproduces duplicate webhook delivery proves the handler's behavior under that input, not that every production duplicate followed that path.

Worked example

The following invented trace uses the same logical purchase throughout.
code
1R11  operation=P7 provider_key=K7 provider_charge=C9 timeout2R12  operation=P7 provider_key=K7 provider_charge=C9 success3W21  event=E4 provider_charge=C9 entitlement=T8 created4W22  event=E4 provider_charge=C9 entitlement=T9 created
There is one provider charge and two local entitlements. The likely defect is a repeated local effect for event E4. A useful next observation is the transaction that records processed events and grants entitlements. If the handler checks E4, grants access, then separately records E4, two concurrent deliveries can both pass the check. A transaction with a uniqueness rule tied to the business operation can close this race.

Build a hypothesis table before changing code

Use one affected operation to avoid mixing unrelated events. The following table is a teaching investigation plan. It ranks observations by how directly they distinguish the candidate causes, not by which tool is easiest to open.
HypothesisExpected evidenceObservation that weakens it
Provider charged twiceTwo distinct provider charge IDsOne provider charge with two local rows
Consumer repeated local effectOne purchase mapped to two entitlementsOne entitlement rendered twice
Query join duplicates display rowsOne stored entitlement joins multiple audit rowsTwo independently stored entitlement IDs
UI renders duplicate cache entriesOne API record appears twice locallyAPI already returns two records
The table prevents a common diagnostic error: treating a plausible cause as a proven cause. A provider retry bug and a dashboard join bug can produce similar screenshots. Only one requires changing payment request identity. The other may require a corrected query or view representation. Make the next observation cheap and decisive.
Here is an additional invented data artifact:
code
1provider_charges:2  C9 -> purchase P7, amount 12003entitlements:4  T8 -> purchase P75  T9 -> purchase P76webhook_deliveries:7  W21 -> event E4, charge C98  W22 -> event E4, charge C9
This evidence supports a local duplicate effect because T8 and T9 are distinct stored entitlements. It does not yet prove the exact code interleaving. Inspect the handler's transaction and uniqueness rules, then create a controlled test that can demonstrate the harmful schedule.

Reproduce the causal schedule

A vulnerable teaching handler follows three separate steps: read whether event E4 is processed, create an entitlement, then mark E4 processed. Pause worker A after its initial read. Start worker B and let it also read absent. Both can create an entitlement before either marker exists. The defect is the separation between the check and effect, combined with no authoritative uniqueness rule that rejects the repeated business outcome.
The repair must match the invariant. If every event should create one local inbox item, event identity can be the effect key. If multiple events can describe one purchase, purchase identity must protect the entitlement. The regression should include both repeated delivery of E4 and distinct events E4/E5 for P7. A test covering only identical event IDs can miss the broader business duplication.
A useful test reports two attempts, one allowed entitlement, and the losing attempt's defined result. Do not require that the losing worker never runs. Concurrent systems often allow multiple attempts while ensuring only one effect commits. This distinction keeps the test aligned with the business guarantee.

Mitigate without erasing evidence

If duplicate entitlements create a harmful benefit, pause the affected grant path or restrict automatic processing while preserving incoming event identities for later replay. Do not immediately delete duplicate rows before understanding their origin and downstream references. Some users may already have consumed benefits, and an unverified deletion can introduce another inconsistency.
The incident note should state whether the provider charged twice, whether local access duplicated, and which accounts are confirmed affected. Avoid broad claims based on one example. A query can count duplicate purchase-to-entitlement mappings across an authorized dataset, but the query's definition must be reviewed and its output should not expose unnecessary personal data.

Misconceptions to correct

The first misconception is that repeated logs prove repeated business effects. Logging can occur before commit, on retries, or in multiple subscribers. Count authoritative effect records and provider objects, not only log lines.
The second misconception is that the first successful reproduction proves every production incident has the same cause. It proves that the implementation permits one schedule. Compare its evidence pattern with actual affected operations and keep alternate causes open where the pattern differs.

Extend the exercise

Change the artifact so entitlements contains only T8 while an audit join returns T8 twice. The correct investigation moves toward query cardinality or presentation. Propose a fixture with one entitlement and two audit rows, then assert that the user-facing view returns one entitlement with two audit events. Award one point for changing the hypothesis, one for the fixture, and one for preserving audit detail without duplicating the business row.

Exercise and solution

Replace W22's event with E5 while keeping charge C9. Would event-ID deduplication alone prevent the repeated entitlement? No. Different provider events can describe the same business purchase. The model solution uses the purchase or charge identity for entitlement uniqueness, while retaining event IDs for delivery audit. Award one point for noticing distinct events, one for selecting business identity, and one for retaining evidence rather than deleting it.

Interview probe and wrap-up

What observation would disprove your first hypothesis? A strong answer names a specific trace or stored-state result that would change the direction of investigation. Follow up with a customer who really has two provider charges. A weak answer commits to duplicate webhooks before checking charge identity. A good diagnosis ends with a causal explanation, a regression scenario, and a statement about what remains unverified.

Sources

docsStripe idempotent request contractdocs.stripe.comdocsStripe webhook delivery and verificationdocs.stripe.comdocsPostHog engineering work-sample guidanceposthog.com

Checkpoint

One stored entitlement joins two audit events and appears twice in an API response. Which hypothesis is strongest?

AThe queue must have lost an acknowledgement.BTwo provider charges necessarily occurred.CA join or response-model duplication is plausible.DThe entitlement write definitely ran twice.
Sign up free to answer and see why

Checkpoint

Two logs say grant started, but only one entitlement committed. What is proven?

ATwo attempts began, not necessarily two effects.BThe uniqueness rule failed.CTwo benefits were granted.DThe provider charged twice.
Sign up free to answer and see why

Checkpoint

What regression covers distinct events for one purchase?

AOnly replay E4 with the same event ID.BOnly change the transport timestamp.CSend E4 and E5 for different purchases and assert two entitlements.DSend E4 and E5 for P7 and assert one purchase entitlement.
Sign up free to answer and see why

Checkpoint

Why pause two workers after their absent-marker reads?

ATo test only sequential redelivery after the first grant completes.BTo reproduce the harmful check-then-effect interleaving deterministically.CTo check provider key persistence across an outbound timeout.DTo prove a marker written after each committed grant prevents repeated grants.
Sign up free to answer and see why

Checkpoint

A local reproduction succeeds. What claim is appropriate?

AIt explains incidents with different stored-state patterns too.BEvery production duplicate has this cause.CThe code permits this schedule; compare its evidence with affected operations.DThe forced reproduction rate estimates the production incident rate.
Sign up free to answer and see why

Can you distinguish provider duplication, local effect duplication, and display duplication using one operation's records, then design a test that demonstrates the actual race? State the relevant identifiers, failure boundary, and evidence in your own words before selecting your confidence.

Not yetGetting thereConfident

Sources

Free to read · better with Enzo

Learn it with Enzo

Save your progress, answer the checkpoints, and let Enzo quiz you on what you just read.