A Timeout Is Not a Failed Transfer: Designing .NET Payment Workflows for Uncertainty

Imagine a customer initiates an international transfer.
Your application sends the instruction to a payment provider. Several seconds pass. The request times out.
What happens next?
A tempting implementation marks the transfer as failed and invites the customer to try again.
But there are several possible realities:
- The provider never received the request.
- The provider received it but has not finished processing.
- The provider accepted it, but the response never reached your application.
The timeout does not tell you which reality you are in.
Stripe’s error handling documentation makes this distinction explicit: a connectivity failure can leave the caller unable to determine whether the request executed.
The following examples describe an illustrative .NET integration, not a specific employer’s implementation.
1. Model uncertainty instead of hiding it
A transfer model with only Success and Failed cannot accurately represent an unresolved provider request.
A more useful starting point might be:
public enum TransferStatus
{
Created,
SubmissionPending,
AwaitingConfirmation,
Processing,
Completed,
Failed
}
These names need precise definitions.
For this example:
Createdmeans the instruction exists locally.SubmissionPendingmeans durable work exists to submit it.AwaitingConfirmationmeans submission may have occurred, but acceptance is unresolved.Processingmeans the provider has confirmed acceptance.Completedmeans the relevant completion condition has been confirmed.Failedmeans authoritative evidence establishes failure.
Provider acceptance should not automatically mean that a recipient has received funds.
Likewise, “completed” needs a definition that matches the payment rail and provider contract. Reversals and returns may require additional states or separate records.
2. Persist the operation before making the network call
The transfer should have a durable identity before it leaves your system.
public sealed class Transfer
{
public Guid Id { get; init; }
public required Guid CustomerId { get; init; }
public required string ClientRequestKey { get; init; }
public required string ProviderIdempotencyKey { get; init; }
public required string ProviderRequestJson { get; init; }
public TransferStatus Status { get; set; }
public string? ProviderReference { get; set; }
}
The request snapshot is illustrative. In practice, store only the information needed, protect sensitive fields, and define appropriate access and retention controls.
There are two separate duplicate problems:
- The customer retries the request to your API.
- Your worker retries the request to the provider.
A client request key can help identify the first. A provider idempotency key addresses the second, where the provider supports it.
For the client request, enforce a database uniqueness constraint scoped to the relevant customer and operation. An application level “check whether it exists” is insufficient when two requests arrive concurrently.
Also reject reuse of a key with different transaction details. The same key must not silently refer to two different transfers.
3. Make submission durable
Saving a transfer and then placing a message on a queue creates a failure window.
The database save might succeed while the queue publication fails.
One approach is to save the transfer and an outbox entry in the same local database transaction:
await using var transaction =
await db.Database.BeginTransactionAsync(cancellationToken);
db.Transfers.Add(transfer);
db.OutboxMessages.Add(new OutboxMessage
{
Id = Guid.NewGuid(),
AggregateId = transfer.Id,
Type = "SubmitTransfer",
CreatedAtUtc = timeProvider.GetUtcNow()
});
await db.SaveChangesAsync(cancellationToken);
await transaction.CommitAsync(cancellationToken);
A background process then submits the durable work.
The outbox does not make the external payment call atomic with your database. A worker can still crash after the provider accepts the transfer but before the local result is saved.
That is why provider idempotency and reconciliation remain necessary.
4. Retry the same operation, not a newly invented one
For an unresolved attempt, this is the dangerous idea:
var providerKey = Guid.NewGuid().ToString("N");
If that line runs for every retry, the provider may see each attempt as a new operation.
Instead, generate and persist the key when creating the transfer. Reuse it with the same provider request:
var result = await provider.SubmitAsync(
transfer.ProviderRequestJson,
transfer.ProviderIdempotencyKey,
cancellationToken);
Stripe’s idempotency documentation describes how a key allows repeated requests to be recognised as the same operation. That behaviour is provider specific, not a universal property of payment APIs.
Check:
- Which endpoints support idempotency.
- How long keys are retained.
- How concurrent attempts are handled.
- What happens when parameters differ.
- Whether errors are replayed or reevaluated.
Do not retry indefinitely. Once the provider’s safe retry window expires, an old key may no longer protect against duplicate execution.
For example, Stripe’s error handling guidance advises reconciling unresolved operations rather than blindly repeating them after its documented window.
5. Treat webhooks as authenticated, repeatable input
A webhook can confirm what the original response could not.
But the handler must assume that delivery can repeat and that events may arrive in an unexpected order.
Stripe’s webhook documentation explicitly describes both conditions.
A robust processing flow is:
- Verify the signature using the provider’s required payload handling.
- Validate the event’s account and environment context.
- Durably record receipt.
- Deduplicate using a provider scoped event identifier.
- Apply an allowed state transition.
- Commit the business change and processing record together.
A database uniqueness constraint helps make duplicate detection safe under concurrency.
Event deduplication alone is not enough, though. Different events can describe the same business outcome. The transfer transition and any associated ledger effects must also tolerate repeated processing.
Never mark a transfer complete merely because an incoming JSON body contains "status": "completed".
The event must be authentic and correctly associated with the expected operation.
6. Reconcile the transfers that remain unresolved
Webhooks are useful, but unresolved transfers still need an operational path.
A reconciliation worker can examine transfers that have remained in an uncertain state beyond an appropriate threshold.
For each one, it can:
- Query the provider using a known reference or supported lookup.
- Compare the provider outcome with local state.
- Apply a validated transition.
- Flag discrepancies for investigation.
- Escalate cases that exceed an operational deadline.
Use bounded retries and backoff. Avoid turning an outage into a flood of status requests.
Also distinguish operational status reconciliation from financial reconciliation. Matching a provider’s “completed” status does not, by itself, prove that every ledger entry, fee, settlement amount, and currency conversion is correct.
7. Tell customers what you actually know
A misleading failure message encourages risky behaviour.
Compare:
“Transfer failed. Please try again.”
With:
“We have not yet confirmed the outcome of your transfer. Please do not submit it again. We will update this transfer when confirmation arrives.”
The second message is less convenient, but it represents the system’s knowledge honestly.
Pair it with a durable transfer reference and a status endpoint so the customer does not have to create a new transaction to discover what happened.
The design principle
Reliable financial software does not assume that every request ends with an immediate, trustworthy answer.
It preserves identity across retries, records uncertainty explicitly, verifies external evidence, and provides a route to resolution.
A timeout is a transport outcome.
It is not, on its own, a financial outcome.
Comments
Join the discussionNo comments yet. Be the first to comment.



