System Design Atlas

Digital lending with limited licences

04 / 10Worked example

Interfaces

Retries preserve the same loan. Which conditions enforce this rule?

A response may be lost after allocation.

Starting point Size the index and allocation path separately.

Assumptions for the example case

A fictional library with one licensed copy and reading devices that verify entitlements online. Every new read checks the current entitlement; offline use is outside the scope. All quantities, thresholds and operational targets in this design are illustrative assumptions.

Issuance and return

Issuance and return

Issuance commandA-52
Licence confirmationActive
Return commandA-52
Revocation evidenceReturned

Issuance and revocation use separate keys bound to the same loan identity.

Two commands with separate keys: confirmed issuance makes the loan Active; confirmed revocation makes it Returned.

Proposed domain contracts

  1. POST/titel/T-52/ausleihen

    Allocate a free copy.

    Input
    commandKey, readerId, titleId=T-52, entitlementPolicyVersion
    Result
    A-52 with X-52 allocated and a licensing command, or unavailable.
    Retry behaviour
    An identical replay reads the same loan; a different reader under the same key produces a conflict.
  2. POST/ausleihen/A-52/rueckgaben

    Request withdrawal of rights.

    Input
    returnKey, expectedVersion, licenseReference
    Result
    Return pending; only confirmed revocation makes the copy available.
    Retry behaviour
    The same return command; no second release.

Retries preserve the same loan.

Retries preserve the same loan.

commandKey returns the existing A-52.

A response may be lost after allocation.

Return the existing loan and state. A different reader under the same key produces a conflict; no new allocation.

Alternative considered
Creating a new loan on every retry allocates additional copies.
Trade-off
The client retains command keys.
Reassess
Contract versions require a clear retention policy.

Try it yourself

Compare an identical replay with a retry for a different reader.

A hint for your attempt

A response may be lost after allocation.

Compare with a possible solution
Replay
Return the existing loan and state.
Different reader
Conflict under the same key; no new allocation.

Apply to your project

What is the equivalent of preserving the same loan on retry in your project?

Step 5: an unknown outcome keeps the licence allocated. Which conditions enforce this rule?