System Design Atlas

Rental and sharing system

05 / 10Worked example

Data and states

What are the conditions R-17 needs?

Vehicle, reservation and rental have their own identities and life cycles. We plot their relationships, allowed state changes and the boundary of a common database transaction.

Starting point From step 4: API contract and stable keys distinguish accepted orders from confirmed results; vehicle A remains reserved for 9-12 o’clock.

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.

The Central Relationships

CustomerIdentity · Test status
1 : nBooks
ReservationPeriod · Status · Expiration time
n : 1Occupies vehicle
VehicleLocation · Operational status
The reservation shall include:
0..1 rentalActual start, return and usage status
0..n payment requestsPurpose, amount, status and provider reference

1 : n = one person, several reservations. Each payment order belongs to the reservation; later billing orders additionally relate to the rental.

Conceptual relationships. Attributes, field types and the full schema follow during implementation.

Life cycle of a reservation

Reservation and rental separately lead

Reservation R-17

held10 minutes limited
Authorisation + time limit valid
Authorisation to accept confirmation
confirmed
Time limit expired
Release hold
expired
heldconfirmed
held or confirmed · Permitted cancellation
Cancellation of booking
cancelled
The transitions are technically checked; the time alone does not remove a hold.

Rental M-17 for vehicle A

readyTakeover prepared
Start order checked
release_pendingRelease underway
Vehicle response confirmed
activeVehicle taken over
Returns started
return_pendingReturns are ongoing
Return confirmed
completedUse completed
The start checks booking, person, authorization, period and vehicle condition. Only the vehicle response allows active; the confirmed return allows completed. Unclear answers remain in the reconciliation.
Linked orders remain their own states.Payment and access orders can be pending, succeeded or needs_review. These results do not replace either held/confirmed or ready/active.

Time expiration, cancellation and external feedback are conducted as visible transitions. A timestamp alone does not set a reservation status.

Confirmation and expiration check the same hold period. Even an already started payment check does not extend this period.

Hold and follow-up order atomically stored

Secure reservation and follow-up order together

An open transactionExamine occupancy and prepare associated local changes.
Reservation R-17 · heldAuthorisation mandate
Testing and writing processes succeed or fail

Commit · both changes

All local checks and writes succeed.

R-17 and order permanently storedExternal follow-up call can then start

Rollback · Discard local changes

409 · Existing occupationReject reservation; do not store effective new occupancy.
Error status · Writing errorReport errors; roll back the open transaction completely.

The two results show the local transaction limit. External effects cannot simply be rolled back in the event of a later error, but can only be compared or compensated.

The Outbox is a permanently stored follow-up order. The commit makes the later work discoverable; a local rollback does not take back any existing provider effect.

Access patterns determine the data storage

Further reading
AccessRequired property
Find free vehicle for location and periodIndices on search characteristics and a searchable occupancy period.
Write Hold for Vehicle and PeriodA transaction with a binding check that prevents overlapping effective occupancy even in the case of simultaneous requests.
Read your own reservation and rentalDirect access via ID plus verification of the authorized person.
Assigning a provider response to an orderUnique order identity and provider reference; separate payment and access states.

Find free vehicle for location and period

Required property
Indices on search characteristics and a searchable occupancy period.

Write Hold for Vehicle and Period

Required property
A transaction with a binding check that prevents overlapping effective occupancy even in the case of simultaneous requests.

Read your own reservation and rental

Required property
Direct access via ID plus verification of the authorized person.

Assigning a provider response to an order

Required property
Unique order identity and provider reference; separate payment and access states.

The table connects each task to a property of data storage. The vehicle search needs suitable data sets by location and time period; indices speed up this selection. A reservation, on the other hand, must take account of simultaneously arriving booking attempts and securely store associated changes. Therefore, we select data structure and protection rules for the respective access.

Select database types consciously

Further reading
SQL Relational Database

Share bookings and occupancy consistently

Tables represent vehicles, reservations and orders with clear relationships. Transactions aggregate associated changes into one unit. Thus, the application can reliably change booking data together. The specific SQL database product is selected during the technical implementation.

Trade-off
Schema, indices and transaction limits need care. The protection against overlapping periods of time must be implemented appropriately for the selected product and tested under simultaneous access.
Reassess
Re-assess in case of measured overload or new query patterns.
Document/Key Value

Maintain order data initially in relational data store

Tables and direct accesses via unique IDs are sufficient for the described jobs. A dedicated document or key-value store would add storage to reconcile and operate.

Trade-off
For later, very special accesses, the relational model may be less tailored.
Reassess
High telemetry load or an independent document stock with other accesses justify a new check.
Graph

Query relationships across tables and links

The booking core follows fixed relationships: a person has reservations, a reservation occupies a vehicle. These accesses can be mapped directly via the linked tables.

Trade-off
Multi-stage, variable relationship paths would thus be more complex to evaluate.
Reassess
A separate case with frequent path queries, for example via a complex authorization network, could justify a graph projection.

Terms in this step

Transaction
A unit of related database changes. Here, reservation and internal order are confirmed jointly by a commit.
Rollback
The rejection of the changes of a still open transaction. Here, it prevents that only a part of the booking data remains stored after an error.
Hold
A temporary occupancy, while further requirements are examined.

Try it yourself

When storing R-17, the writing of the subsequent order fails. What can be visible after the rollback? Can a payment response still trigger confirmed after the hold period has expired?

A hint for your attempt

Note two limits: shared local data and a permitted change of state before the deadline.

Compare with a possible solution
Rollback
Neither the new Hold R-17 nor its follow-up order will be committed. As a result, no hold is left without a planned payment check.
Delayed response
No. The confirmation checks the state and time limit atomically. The overdue hold transitions to expired; an existing authorization will be cancelled or handed over for clarification.

Apply to your project

Transfer states, transition conditions, and transaction boundary to your own core item and record an earlier design step to revisit that could test an earlier assumption.

Step 6 guides R-17 through the overall architecture and assigns data, API, worker and external vendors to their responsibilities.