System Design Atlas

Digital lending with limited licences

10 / 10Worked example

Final design

The end-to-end test finishes with renewed availability. Which conditions establish completion?

Issuance alone does not test the return path.

Starting point Block affected copies until reconciliation.

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.

Loan architecture with evidence

Index alongside licence state

Search interfaceForecast
Lending interfaceLoan + online reading
Lending APIAllocation + entitlement
Relational licence datastoreX-52 · A-52 · Inbox
Licensing workerIssuance + revocation
Indexing workerProjection
Search indexDerived
Licensing serviceExternal
Search interface → Search indexSearch titles
Lending interface → Lending APILoan / return / entitlement check
Lending API → Relational licence datastoreA-52 + X-52 + Inbox
Relational licence datastore → Licensing workerCommitted command
Licensing worker → Licensing serviceIssuance / revocation
Licensing service → Lending APIState for A-52
Relational licence datastore → Indexing workerTitle + availability
Indexing worker → Search indexProjection

The index estimates availability; the API and licence datastore decide allocation; online reads check entitlements through the same API.

Topology from step 6, with last-copy allocation, exclusive expiry and return confirmation; revisit steps 2, 5 and 7.

Test plan with expected outcomes

Input and initial stateExpected resultReturn to an earlier step
X-52 available → concurrent allocation attempts by readers A/B and B/AOne winner, the other receives unavailable; exactly one allocation.Step 5
A-52 allocated → identical replay; a different reader under the same keyThe same loan is returned; changed replay content produces a conflict.Step 4
Expiration=D-52 → now=D-52−1 ms /D-52 /D-52+1 msAccess at the first instant is allowed while Active; access at the other instants is denied; the copy becomes available once.Step 2
Return pending → lose the response, attempt another loan, confirm revocation twiceNo reallocation before evidence arrives; then available once; duplicate confirmation has no additional effect.Step 7/9

X-52 available → concurrent allocation attempts by readers A/B and B/A

Expected result
One winner, the other receives unavailable; exactly one allocation.
Return to an earlier step
Step 5

A-52 allocated → identical replay; a different reader under the same key

Expected result
The same loan is returned; changed replay content produces a conflict.
Return to an earlier step
Step 4

Expiration=D-52 → now=D-52−1 ms /D-52 /D-52+1 ms

Expected result
Access at the first instant is allowed while Active; access at the other instants is denied; the copy becomes available once.
Return to an earlier step
Step 2

Return pending → lose the response, attempt another loan, confirm revocation twice

Expected result
No reallocation before evidence arrives; then available once; duplicate confirmation has no additional effect.
Return to an earlier step
Step 7/9

End-to-end test and unresolved agreements

First end-to-end path
Compete for the last copy, lose the licensing response, reconcile a return and test the expiry boundary with online reads.
Clarify before real use
Real licensing terms, offline rights, ongoing reading sessions and revocation require their own contracts. This model covers only newly authorised online reads.

The end-to-end test finishes with renewed availability.

The end-to-end test finishes with renewed availability.

Test returns and expiry separately.

Issuance alone does not test the return path.

One winner for X-52; revisit step 5 on failure. Release only after evidence arrives; revisit steps 4 and 7 on failure.

Alternative considered
Testing only the happy path overlooks copies stuck in allocation.
Trade-off
The test requires a controlled clock and service failures.
Reassess
Extend to further licence types after these tests pass.

Try it yourself

Map last-copy allocation and returns to the relevant earlier steps.

A hint for your attempt

Issuance alone does not test the return path.

Compare with a possible solution
Concurrency
One winner for X-52; revisit step 5 on failure.
Return
Release only after evidence arrives; revisit steps 4 and 7 on failure.

Apply to your project

What is the equivalent of testing through to renewed availability in your project?

Transfer the decisions and their counterexamples to the editable design template.

Start your own design

Choose a small case from your project. The template collects the ten design tasks and leaves space for your sketches, decisions, and open assumptions. You can edit it in your text editor or note-taking app.

Download design template (.md)
Compare the ten tasks with the example case
  1. Purpose and boundary

    What is the equivalent of the title–copy distinction in your project?

    In the example: Allocation binds the specific licensed copy.

  2. Requirements

    What is the equivalent of an exclusive expiry instant in your project?

    In the example: Online access requires now<D.

  3. Scale estimates

    What is the equivalent of search dominating load in your project?

    In the example: Size the index and allocation path separately.

  4. Interfaces

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

    In the example: commandKey returns the existing A-52.

  5. Data and states

    What is the equivalent of retaining allocation while the outcome is unknown in your project?

    In the example: Release only after confirmed non-issuance or access revocation.

  6. Overall architecture

    What is the equivalent of an index that grants no permissions in your project?

    In the example: Online access checks the authoritative entitlement.

  7. Critical flow

    What is the equivalent of waiting for revocation before completing a return in your project?

    In the example: Reconcile the same command.

  8. Bottlenecks and trade-offs

    What is the equivalent of distinguishing stale search results from lost licences in your project?

    In the example: Measure search staleness and pending command duration separately.

  9. Operations and security

    What is the equivalent of reconciling entitlements before resuming in your project?

    In the example: Block affected copies until reconciliation.

  10. Final design

    What is the equivalent of testing through to renewed availability in your project?

    In the example: Test returns and expiry separately.