FDE Times dataFDE jobs open 911▼17 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 66Companies hiring 200Remote-friendly 24%Median US pay $200kTop hirer Databricks 106
中文VI

The newspaper of the Forward Deployed Engineer

Guides

Write client integrations as if every request arrives twice

A single retry after a timeout can charge a customer twice, and Stripe's recommended defense is an idempotency key that lets the server recognize a resent request.

ShareLinkedInFacebookX

In brief

  • After a network error or a 500, you do not know what the server did. Retry with the same idempotency key and the same parameters, then reconcile through webhooks.
  • Webhooks can arrive more than once and out of order. Deduplicate by event ID and never rely on ordering.
  • Return 2xx fast, push heavy work onto a queue, and know which providers will not resend webhooks on their own.
Infographic in two parts. Sending: an order has an idempotency key generated once. Attempts 1 and 2 time out and attempt 3 returns a result, all sent with the same key. The server remembers the result by key, so the customer is charged only once. On a 500 error, the order is marked “unknown” and the sender waits for the webhook. Receiving: a webhook passes four steps: get the raw body, verify the HMAC-SHA256 signature with a clock skew of at most 5 minutes, deduplicate by event ID, then return 2xx at once and push to a queue. A worker then reads the current state to do the heavy processing. Notes: Stripe live mode retries webhooks for up to three days, while GitHub does not retry automatically.
When sending, every retry must use the same key and parameters. When receiving, webhooks must be deduplicated before they are processed.

At nine on a Monday morning, the client’s accountant sends over a screenshot: the same order, charged twice. The logs show the network wobbled for a while over the weekend, the request to create the payment timed out, and your job dutifully retried, exactly as it had been told to.

The code has no syntax errors and it never crashed. What failed was an assumption: that a request arrives exactly once, in the right order, and always gets a clear answer. For a Forward Deployed Engineer, that assumption breaks almost daily.

Palantir describes the FDE role as embedding engineers alongside customers to solve their most urgent problems. Working inside a client’s systems also means that sooner or later you will touch the pipes connecting those systems to others. Build those pipes solidly and you earn trust.

Build them carelessly and you will spend a week explaining why the numbers don’t match.

When you get an error, you don’t know what happened

Start with an uncomfortable truth. Stripe’s error-handling documentation is blunt: after a network error, the client does not know whether the server received the request. A 500 response to a write must also be treated as an indeterminate result, meaning the operation may or may not have run.

Blind retries are therefore dangerous, while not retrying at all can drop orders. The way out is an idempotency key: a string generated by the client, up to 255 characters long, for which Stripe suggests a UUID V4. You attach it to the request so the server can recognize repeat submissions.

Stripe’s mechanism is simple. It stores the status code and body of the first request made with each key, even if that request failed, and returns exactly that result to every retry. If you reuse a key with different parameters, the idempotency layer returns an error to stop the mistake.

Three details often escape newcomers. Keys may be removed after 24 hours, so do not treat them as a permanent record. Every POST accepts a key, while sending one with GET or DELETE has no effect, because those methods are idempotent already.

And after a network error, Stripe’s advice is to retry with the same key and the same parameters until the server returns a result.

A payment job, rewritten properly

Back to that Monday incident. The most important change is that the key must be generated once, when the order is created, and stored with the order, never regenerated on each retry. Regenerate it and every retry looks like a new transaction, which defeats idempotency entirely.

def create_payment(order):
    key = order.idempotency_key          # UUID v4, generated when the order is created, stored in the DB
    payload = {
        "amount": order.amount,
        "currency": order.currency,
        "metadata[order_id]": order.id,  # for reconciliation later
    }
    return send_with_retry(payload, key, order)

The retry loop lives on its own, and every attempt uses that same key:

def send_with_retry(payload, key, order):
    for attempt in range(6):
        try:
            r = requests.post(PAYMENTS_URL, data=payload,
                              headers={"Idempotency-Key": key}, timeout=10)
        except (requests.ConnectionError, requests.Timeout):
            time.sleep(2 ** attempt)     # retry with the same key
            continue
        if r.status_code == 429:
            time.sleep(retry_after(r, attempt))
            continue
        if r.status_code >= 500:
            mark_indeterminate(order)    # wait for webhook/reconciliation
            return None
        return r
    mark_indeterminate(order)
    return None

The 429 branch deserves attention. Rate limits are an everyday part of integration work, and according to MDN a 429 response may include a Retry-After header saying how long to wait before sending a new request. When the server gives you a number, wait exactly that long instead of guessing:

def retry_after(r, attempt):
    wait = r.headers.get("Retry-After")
    return int(wait) if wait and wait.isdigit() else 2 ** attempt

The 500 branch does not retry blindly. The order is marked “indeterminate”, and the truth arrives from the other side: the webhook, plus the order_id metadata that matches the transaction to the order. That is also how Stripe recommends handling it: reconcile through webhooks and metadata.

Webhooks arrive late, twice, and out of order

The reverse direction is harder, because you do not control when someone else calls you. Stripe states plainly that an endpoint may occasionally receive the same event more than once, and that events may arrive out of order. Crossmint’s documentation says its webhooks guarantee “at least once” delivery, which means the receiving side has to be idempotent.

A good handler does four things, in this order.

@app.post("/webhooks/payments")
def receive():
    raw = request.get_data()                       # raw body, not parsed
    sig = request.headers.get("Stripe-Signature")
    try:
        event = stripe.Webhook.construct_event(raw, sig, WEBHOOK_SECRET)
    except Exception:
        return "", 400                             # bad or stale signature
    if not processed_events.insert_if_absent(event["id"]):
        return "", 200                             # already seen: skip
    queue.enqueue(handle_event, event["id"])
    return "", 200                                 # return 2xx immediately

The first step is capturing the raw body. Stripe signs every webhook with HMAC-SHA256 via the Stripe-Signature header, and verification needs the exact original body. If the framework has parsed and re-serialized it, a single changed space is enough to break the signature, and you will lose half a day suspecting the secret.

The signature also includes a timestamp to guard against replay attacks, and Stripe’s library by default accepts a gap of up to 5 minutes between that timestamp and the current time. In practice, if the client’s server clock drifts far enough, every webhook will be rejected even though the secret is perfectly correct.

Next comes deduplication by event ID, then a 2xx before any heavy work. Stripe recommends processing events through an asynchronous queue to absorb sudden spikes. In the worker, do not assume a “paid” event always arrives after a “created” event. It is safer to read the object’s current state before updating the order.

Every provider promises something different, so read the promise closely

This is where an FDE earns trust: reading each provider’s documentation closely enough to know who is responsible for resending when your system goes down.

Stripe GitHub
Response deadline Return 2xx before running heavy logic Must return 2XX within 10 seconds
When delivery fails Live mode resends automatically for up to three days, with exponential backoff No automatic redelivery
Your job after an outage Cope with a backlog of old events arriving at once Redeliver missed webhooks yourself once the server is back

The difference shapes the architecture. With Stripe, a two-hour outage usually heals itself, provided the handler can absorb the flood of events. With GitHub, without a redelivery script or procedure, missed data is gone for good, and the runbook handed to the client must spell that step out.

The mistakes that keep recurring

The most common is generating a fresh idempotency key inside the retry loop, which renders the protection useless. Close behind is reusing an old key with changed parameters, such as a corrected amount, then being surprised by the error. Changing the parameters makes it a new operation, and a new operation needs a new key.

The second is treating a 500 as “definitely failed” and recreating the transaction with a different key. The third is running all the business logic inside the webhook handler: writing to the database, calling the ERP, sending email. One slow ERP response pushes it past the timeout, the provider counts the delivery as failed, and the resend cycle begins.

The last gets little attention: having no reconciliation path. However good the code, you still need a periodic job that compares state on both sides through metadata, because one day an event will be missed.

Putting this skill on your CV

When reading job descriptions for FDE or solutions engineer roles, look for phrases such as “integrations”, “webhooks”, “customer systems” and “data pipelines”. When you see them, have a story about idempotency and webhooks ready. Show that you have dealt with real failures, not just called APIs.

So instead of writing “Integrated Stripe”, be specific: added idempotency keys and webhook-based reconciliation to eliminate duplicate transactions; moved the webhook handler to queue-based processing with deduplication by event ID. If it comes up in an interview, walk through the incident, its cause and how you proved it would not happen again.

This week’s exercise: take an integration you are running, pull the network cable in the middle of a POST, then resend the same webhook three times. If the data is still correct after both tests, you have done the part of the job the client will never see, and it is the part that decides whether they trust you.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
7 sources
Read next on the roadmap · Stage 2: Broad engineeringODBC Driver 18 is installed, and the script still can't find itVersions 17 and 18 register under separate names, so check the driver, certificate and database version before blaming the Python code.