Vendor Integration Platform

Talk to a vendor API that may be down, and never lose a request.

VIP sits between an internal REST API and the Fake Store vendor. Creating, updating or deleting an account and executing an order all return 202 Accepted at once; a background worker makes the vendor call with a retry schedule that stretches to 24 hours, and a dead-letter worker compensates when the vendor never confirms. .NET 10, Clean Architecture, CQRS via MediatR.

Order state machine — every transition is a domain method; a disallowed one throws InvalidStatusTransitionException

                    ┌─────────────────────────────┐
                    │           Draft              │
                    └──────┬──────────────┬────────┘
               Execute()   │              │  Cancel()
                           ▼              ▼
              PendingVendorConfirmation  Cancelled (terminal)
               │           │           │
 MarkAsSucceeded() MarkAsVendorFailed() MarkAsCompensationPending()
               │           │           │
               ▼           ▼           ▼
           Succeeded   VendorFailed  CompensationPending
           (terminal)  (terminal)        │
                                 MarkAsCompensated()
                                         │
                                         ▼
                                     Compensated (terminal)

Start in four steps

You need the .NET 10 SDK and SQL Server LocalDB (ships with Visual Studio) or SQL Server Express.

1 · Restore and configure

dotnet restore, then set the connection string in src/VendorIntegrationPlatform.Api/appsettings.Development.json. The JWT secret there is for development only.

2 · Apply migrations

dotnet ef database update --project src/VendorIntegrationPlatform.Infrastructure --startup-project src/VendorIntegrationPlatform.Api

3 · Run

dotnet run --project src/VendorIntegrationPlatform.Api. On startup it imports the product catalogue from Fake Store before serving requests. Swagger UI is at /swagger.

4 · Seed a user and log in

There is no public registration. Seed a user in the database or uncomment the seed block in Program.cs, then POST /api/v1/auth/login and paste the access token into Swagger's Authorize dialog.

Tests use an in-memory EF Core database and a stub vendor client, so they need neither SQL Server nor the network:

dotnet test src/VendorIntegrationPlatform.Tests                                        # everything
dotnet test src/VendorIntegrationPlatform.Tests --filter "FullyQualifiedName~Unit"        # domain, handlers, validators
dotnet test src/VendorIntegrationPlatform.Tests --filter "FullyQualifiedName~Integration"  # full HTTP flows

How it works

Four layers, one dependency rule: each depends only on layers further in, and the Domain has no external dependencies.

Outbox: entity and event in one transaction

A request writes the entity and an outbox message atomically. The worker polls every 10 seconds for messages that are Pending, unlocked and due, row-locks each with a per-process worker ID for 30 seconds, and only then calls the vendor. Delivery is at-least-once.

Retry schedule
Attempt 1   immediate    quick transient failures
Attempt 2   1 minute     quick transient failures
Attempt 3   5 minutes    short outages
Attempt 4   60 minutes   vendor downtime
Attempt 5   6 hours      extended outage
Attempt 6   24 hours     covers SLA window
Dead        —            Dead Letter Worker compensates

Dead letter: undo what never happened

After the last retry a message is marked Dead. The Dead Letter Worker runs hourly and applies a compensation per event type. The vendor is treated as the source of truth.

EventCompensation
AccountCreatedAccount never reached the vendor → soft-delete it
AccountUpdatedNo vendor user id, or user not found → mark sync failed. Otherwise restore the previous name and phone from the payload
AccountDeletedVendor still has the user → restore from deletion and alert ops. Vendor already deleted → nothing to do
OrderExecutedCart was never created at the vendor → mark the order VendorFailed

Rules live in the domain

An account is Pending until the vendor confirms it, then Synced; updating it re-queues a sync. You cannot update or delete an account that has never reached the vendor, nor delete one with active orders. Orders accept item changes only in Draft. Each rule is a named exception mapped to a stable error code.

One response shape

Every endpoint returns an ApiResult<T> envelope with status, data and error. Error codes are gapped integers grouped by domain: 1xxx generic, 2xxx Account, 3xxx Order, 4xxx Product, 5xxx Vendor. Auth is JWT with a 15-minute access token and a 7-day refresh token; logout always returns 204 to avoid revealing which emails exist.

The API

Everything is versioned under /api/v1/. All endpoints except auth require a bearer token.

MethodEndpointWhat it does
POST/auth/login · /auth/refresh · /auth/logoutGet, renew and revoke tokens
POST/accountsCreate account, 202, vendor sync via outbox
GET/accounts/{id} · /accounts/vendor/{vendorId}Get by internal Guid or vendor integer id
PUT/accounts/{id} · /accounts/vendor/{vendorId}Update; resets sync status to Pending and re-queues
DELETE/accounts/{id} · /accounts/vendor/{vendorId}Soft delete, 202, async vendor sync
POST/ordersCreate order in Draft
GET/orders/{id}Order with items and totals
PUT/orders/{id}Replace items, Draft only
DELETE/orders/{id}Cancel, Draft only
POST/orders/{id}/executeExecute, 202, async cart creation at the vendor
GET/products · /products/{vendorId}Active products (cached 10 minutes) or one by vendor id
POST/products/syncSync catalogue from Fake Store, invalidates the cache on change
Design documents
  1. System Design v2.0 — why Clean Architecture, why the Outbox Pattern, why soft delete, why seven order statuses, why BCrypt, why Polly was not used
  2. Database Design v2.0
  3. API Documentation

The README also documents a known production bug: replacing order items with different product ids hits a concurrency exception because the order is loaded without tracking. Integration tests exercise the safe path only.