System Design Atlas

Rental and sharing system

07 / 10Worked example

Critical flow

How does a booking remain traceable in the event of errors?

The local storage and the external payment check run separately in time. An authorization reserves an amount; the later debit is part of the billing. We compare the normal process with a crash and a delayed response.

Starting point From step 6: API, database and worker together carry the booking path; K-17 and R-17 are stored as stable identities.

Assumptions for the example case

Example design: an operator, specifically assigned vehicles, planned periods and a region. Figures are illustrative design assumptions, not company data.

From request for reservation to confirmation

Example: Vehicle 09:00–12:00 · Hold 10 minutes · Order K-17 · Reservation R-17
Local transactionHold and order are committed together
  1. App Rental APIReservation request K-17Vehicle · 09:00–12:00 · Hold 10 minutes
  2. Rental API SQLHold + Outbox in one transactionStore R-17 and the payment request together
  3. SQL Rental APICommit confirmedheld · Order remains permanently visible
  4. Rental API App201 · Hold storedThe app knows the local status
Background workThe worker takes over the stored order
  1. Worker SQLOutbox queriesWorker actively asks for due orders
  2. SQL WorkerDeliver order K-17SQL responds; the database does not push a message
  3. Worker ProvidersAuthorization requestsOutside of the local transaction · Permanent key A-17
  4. Providers WorkerAuthorisation confirmedProvider reference P-17 comes back
  5. Worker SQLCheck the result + held → confirmedCheck state held and the deadline; store authorization and transition atomically
  6. SQL WorkerCommit confirmedResult, reference and status are permanently stored
Reading statusThe API reads the stored state; no new transition occurs
  1. App Rental APIRead the status of R-17The app queries the rental API
  2. Rental API SQLRead status onlyGET /reservations/R-17 does not trigger a change of status
  3. SQL Rental APIconfirmed + P-17SQL returns the state stored by the worker
  4. Rental API AppShow your booking confirmedR-17 · 200 · Vehicle bindingly assigned
The normal process requires a valid hold. The error case shows how a stored order leads to the clarification of an external effect after a crash.

Targeting interruptions

Further reading
SituationProceedings guaranteed
Two reservations arrive simultaneouslyThe database allows at most one effective occupancy for overlapping periods. The other request receives 409.
API will fail after committingA repeat attempt with K-17 finds the same hold. The already stored follow-up order remains processable.
Authorization Successful, Worker Crashed Before StorageThe provider reference P-17 and the stable authorization key A-17 allow the status reconciliation. The worker clarifies whether the amount has already been authorized before executing the order again.
Success comes after the hold expiresThe state machine rejects the confirmation of the elapsed hold. As compensation, the existing authorization is cancelled; an already completed charge is refunded or clarified as a separate billing process.
Webhook arrives several times or in another orderEvents and state transitions are deduplicated or checked. If there is an objection, the current provider status is queried.

Two reservations arrive simultaneously

Proceedings guaranteed
The database allows at most one effective occupancy for overlapping periods. The other request receives 409.

API will fail after committing

Proceedings guaranteed
A repeat attempt with K-17 finds the same hold. The already stored follow-up order remains processable.

Authorization Successful, Worker Crashed Before Storage

Proceedings guaranteed
The provider reference P-17 and the stable authorization key A-17 allow the status reconciliation. The worker clarifies whether the amount has already been authorized before executing the order again.

Success comes after the hold expires

Proceedings guaranteed
The state machine rejects the confirmation of the elapsed hold. As compensation, the existing authorization is cancelled; an already completed charge is refunded or clarified as a separate billing process.

Webhook arrives several times or in another order

Proceedings guaranteed
Events and state transitions are deduplicated or checked. If there is an objection, the current provider status is queried.

Compensation offsets an external effect that already occurred by issuing an appropriate follow-up command. Here, cancelling the authorization releases the reserved amount again. This compensation is pursued as a separate order; a local database rollback cannot reverse the reservation of the amount with the payment provider.

Vehicle access as a second controlled transition

Recheck before pickup
Booking, person, driving authorization, current period and operating state must fit. A current or late-ended rental blocks the release.
Confirm physical unlocking
An accepted opening order first leads to release_pending. Only the confirmed vehicle response allows active; in case of uncertainty, the order remains under reconciliation.

Terms in this step

Compensation
Offset an effect that already occurred with a domain action, for example cancel a payment authorization again.
State machine
A model of the allowed status changes and conditions. Here, held is only confirmed with present payment authorization and valid deadline; an expired hold remains excluded from the confirmation.

Try it yourself

The provider has authorized A-17. The worker crashes before saving the response; P-17 is still locally unknown. What happens if the hold has expired?

A hint for your attempt

A-17 was stored before the call. Check the provider over this key and maintain the local deadline.

Compare with a possible solution
Determine the result
The new worker compares A-17 according to the provider contract or repeats the same idempotent call. Thus, it receives the existing status and P-17.
Respect the deadline
R-17 transitions to expired. A late authorization must not change it to confirmed.
Compensate the effect
The worker initiates the cancellation of the authorization. If their outcome remains unclear, a stored clarification order leads to customer service.

Apply to your project

Transfer the error to your own process and note which effect a local rollback cannot take back.

Step 8 uses three diagnostic paths to measure which bottleneck or which external waiting time actually limits the sequence.