A design example connecting library work and implementation
Design edition 1.0 | October 6, 2026
This booklet describes a fictional library. Members, books, dates, and operating limits are illustrative. No implementation or acceptance test has been run.
01 / 12 DESIGN BASIS
Create one shared record so members can find and reserve titles while staff handle returns, pickups, and loans. The design centers on two guarantees: a physical copy is never assigned to two people at once, and reservations keep their accepted order.
| Included | Outside this edition |
|---|---|
| Catalog search, available copy count, reservation and cancellation | Acquisition, withdrawal, interlibrary loans, ebooks |
| Loans, returns, holds, and desk pickup | Renewals, fines, delivery, notification dispatch |
| Member and staff permissions, audit events, key exceptions | Branch transfers, offline desk work |
QUEUED and READY are active; a member cannot hold two active reservations for one title.QUEUED entries by accepted_at in JST, then reservation ID. A READY hold leaves the displayed queue.Available count is the number of copies with status AVAILABLE. It excludes copies on loan, on hold, or in inspection; it is distinct from total copies and people waiting. Count changing transactions lock the title row, then relevant member rows, and check each member's totals across all titles within that transaction.
02 / 12 REQUIREMENTS
P0 is essential for launch, P1 for normal operation, and P2 a possible improvement. These acceptance conditions use the fictional rules in this booklet.
| ID | Priority | Requirement and acceptance condition |
|---|---|---|
| F-01 | P0 | Members search titles and see total copies, available copies, and queued members. |
| F-02 | P0 | Members reserve titles; reject duplicates and a third active reservation, including concurrent actions on different titles. |
| F-03 | P0 | A return places its copy on hold for the first queued reservation and updates queue positions. |
| F-04 | P0 | After identity and copy checks, staff check out a READY hold; recheck the three loan limit. |
| F-05 | P0 | Staff check out and return copies; ordinary loans obey the same member limit. |
| F-06 | P1 | Members cancel their own QUEUED reservations; staff cancel READY holds. |
| F-07 | P1 | Expire overdue holds and immediately allocate to the next eligible reservation. |
| F-08 | P1 | Members view their own loans and reservations; staff see member details needed for service. |
| F-09 | P1 | Audit state changes with actor, time, action, and target ID. |
| N-01 | P0 | Serialize title queue and copy assignment, and member limits across titles. |
| N-02 | P1 | Use a transaction ID to return the same result on retry without duplicate writes. |
| N-03 | P1 | Minimize displayed member identifiers; control access in transit and at rest. |
A title is the catalog record for a work and edition. A copy is one barcoded physical item. A reservation is a place in a title's queue. A hold temporarily links one reservation to one copy.
03 / 12 PEOPLE AND TASKS
| Actor | Can do | Boundary |
|---|---|---|
| Member | Search, reserve, cancel own queued reservation, view own activity | Cannot cancel a ready hold or see another member's activity. |
| Desk staff | Check out and return copies; verify and complete pickup; cancel ready holds | Cannot reorder the queue manually or run the expiry job. |
| Expiry job | Expire overdue holds and reassign their copies | Does not perform staff hold cancellations. |
A member selects a title → joins its queue → a returned copy is held for the first reservation → staff match the library card and copy barcode → the hold becomes a loan. Joining the queue alone does not claim a copy.
04 / 12 CONSISTENCY EXAMPLE
This fictional 2026 example uses title BK-104, Weaving Stars, and copies CP-01 and CP-02. All displayed times are JST. M-01 and M-04 are initial borrowers; M-02 and M-03 are reserving members.
| Time and action | CP-01 | CP-02 | Queued order | Ready hold | Available |
|---|---|---|---|---|---|
| Jun 10, 10:00 · initial | On loan to M-01 | On loan to M-04 | 1 R-01/M-02 → 2 R-02/M-03 | None | 0 |
| Jun 10, 10:30 · CP-01 returned | On hold for R-01 | On loan to M-04 | 1 R-02/M-03 | R-01/M-02 | 0 |
| Jun 11, 18:00 · R-01 picked up | On loan to M-02 | On loan to M-04 | 1 R-02/M-03 | None | 0 |
| Jun 12, 11:00 · CP-02 returned | On loan to M-02 | On hold for R-02 | None | R-02/M-03 | 0 |
| Jun 16, 00:00 · R-02 expired | On loan to M-02 | Available | None | None | 1 |
R-01 was accepted Jun 10 at 09:00; R-02 at 09:05. Pickup deadlines are Jun 13 and Jun 15 at 23:59, respectively. R-01 is collected on Jun 11; its loan is due Jun 25 at 23:59 JST. R-02 is never collected. In every row, 2 total copies = on loan + on hold + available + in inspection.
READY reservation.QUEUED or READY) reservations, counted across titles.05 / 12 SCREEN DESIGN
| View | Key display or action | Design note |
|---|---|---|
| Member · search and detail | Jun 10, 10:00: total 2, available 0, 2 queued; Reserve starts the request. | Display counts are a snapshot; recheck on confirmation. |
| M-02 · my reservations | Jun 10, 10:30: only M-02's R-01 appears as ready. |
R-02 belongs to M-03 and is hidden. |
| Staff · return | Jun 10, 10:30: put CP-01 on hold for R-01. |
After confirmation, only R-02 remains queued. |
| Staff · pickup | Match R-01, M-02, and CP-01, then check out. |
Confirm identity and recheck the loan limit first. |
On small screens, stack information vertically. Pair numbers with words such as “0 available copies” and “Ready for pickup.” Confirmation includes reservation and copy IDs so staff can verify the result aloud at the desk.
06 / 12 INFORMATION MODEL
| Entity | Key and main attributes | Constraint |
|---|---|---|
| Book | book_id, title, author |
Lock by title for queue and allocation. |
| Copy | copy_id, book_id, status, version |
AVAILABLE / ON_LOAN / ON_HOLD / INSPECTION |
| Member | member_id, display_name, active |
Lock row before recounting member totals across titles. |
| Loan | loan_id, copy_id, member_id, due_at, returned_at |
At most one unreturned loan per copy. |
| Reservation | reservation_id, book_id, member_id, accepted_at, status, allocated_copy_id, pickup_deadline |
At most one active reservation per member and title. |
| AuditEvent | event_id, actor_id, action, target_id, occurred_at |
Append only. |
Derive available count from Copy.status = AVAILABLE. Order QUEUED reservations by (accepted_at, reservation_id). Reservation states are QUEUED / READY / FULFILLED / CANCELLED / EXPIRED; only the first two are active. Index title, member, status, and order fields, plus loan member and return time. allocated_copy_id is non null only in READY.
07 / 12 TRANSACTION ORDER
CP-01. The API locks title row BK-104, then member rows for old borrower M-01 and prospective recipient M-02 in ascending ID order, before closing the unreturned loan.R-01, marks CP-01 on hold and R-01 ready, due Jun 13 at 23:59. R-02 becomes queue position 1. Available count stays 0.M-02 / R-01 / CP-01. The API locks BK-104, then M-02, checks that M-02 has fewer than 3 unreturned loans across titles, creates the loan, and fulfills R-01.Every write locks title IDs ascending, then member IDs ascending. A return gathers the former borrower and allocation candidates before locking member rows in order. After member locks, recount active reservations or unreturned loans across all titles and update in the same transaction. Deactivation first locks related titles in order; if the set expands, roll back and retry. Any failure rolls back the whole operation. A retry with the same Idempotency-Key returns the committed result.
08 / 12 RESPONSIBILITIES
| Operation | Input → result | Rule enforced |
|---|---|---|
placeReservation |
book, member → ID and state | Check active member, duplicate, and two active reservations across titles; hold immediately if a copy is available. |
returnCopy |
copy, transaction ID → return and allocation | Close the loan and assign the copy to the first eligible reservation. |
pickupReservation |
reservation, member, copy → loan ID | Check active member, deadline, identity, copy, and three loans across titles. |
loanAvailableCopy |
copy, member → loan ID | Use the same member lock and three loan limit for ordinary checkout. |
cancelReadyHold |
reservation, reason → reallocation | Staff cancel the ready hold and pass its copy to the next member. |
expireHolds |
reference time → count expired | Process only past deadline, then reassign. |
CirculationService locks title then member rows and recounts limits. ReservationPolicy decides order, limits, and deadlines. Skip and cancel reservations for inactive members during allocation, then continue to the next. Screens never calculate queue position or availability independently.
09 / 12 LIFECYCLE
Figure 6 shows the main return, reservation, and pickup path. The table also covers returns without a queue, ordinary loans, immediate holds, and inspection.
| Trigger | Reservation | Copy | Example or guard |
|---|---|---|---|
| Place reservation | New → QUEUED; if copy available, New → READY |
Available → on hold if assigned | Initially R-01/R-02 are queued. |
| Return and allocate | First QUEUED → READY |
On loan → on hold | Jun 10: R-01 and CP-01 move together. |
| Pickup | READY → FULFILLED |
On hold → on loan | Jun 11: R-01 and CP-01 move together. |
| Expiry | READY → EXPIRED |
On hold → next hold or available | Jun 16: R-02 expires; CP-02 is available. |
| Cancellation | QUEUED / READY → CANCELLED |
Reassign held copy or make available | Member cancels queued; staff cancels ready. |
| Return without queue | No change | On loan → available | No queued reservation exists. |
| Ordinary checkout | No change | Available → on loan | Check active member and three loan limit. |
| Immediate hold | New → READY |
Available → on hold | Allocate to the first reservation. |
| Inspection | No change | Available → inspection → on hold / available | Release assigns the copy to the first queued reservation; with no queue, it becomes available. |
Do not move a loaned or held copy directly to inspection. For a damaged return, close its loan and move the copy to inspection without allocation. When released, hold it for the first queued reservation if one exists.
10 / 12 INTERFACE
Use JSON under /v1. Store instants in UTC and show dates in JST. A loan is due 23:59 JST, 14 calendar days after checkout. Writes require Idempotency-Key; the server determines the authenticated actor.
| Method and path | Actor | Purpose and success |
|---|---|---|
GET /v1/books?q= |
Member, staff | Titles, total and available copies, queued count · 200 |
GET /v1/books/{bookId} |
Member, staff | Current inventory summary · 200 |
POST /v1/books/{bookId}/reservations |
Member | Create own reservation · 201, ID, state, position or deadline |
DELETE /v1/me/reservations/{id} |
Member | Cancel own queued reservation only · 204 |
GET /v1/me/circulation |
Member | Own loans and reservations · 200 |
GET /v1/staff/members/{memberId}/circulation |
Staff | Member state and loan count for pickup · 200 |
POST /v1/staff/copies/{copyId}/returns |
Staff | Return and first allocation · 200, recipient and available count |
POST /v1/staff/reservations/{id}/pickup |
Staff | Verify identity and copy; check out · 201, loan ID |
POST /v1/staff/reservations/{id}/cancel |
Staff | Reason; cancel ready hold and reassign · 200, result |
POST /v1/staff/copies/{copyId}/loans |
Staff | Ordinary checkout; check active member and three loan limit · 201 |
POST /v1/internal/holds/expire |
Job | Expire holds · 200, processed count |
For POST .../returns with CP-01: {"copyId":"CP-01","copyStatus":"ON_HOLD","reservationId":"R-01","availableCount":0}. At that point R-02 is first in the remaining queue. Retry a conflict with the same transaction ID.
11 / 12 FAILURE AND ACCESS
| Code | HTTP | When it occurs | User response |
|---|---|---|---|
RESERVATION_LIMIT |
409 | Member already has 2 active reservations | Explain limit and show existing reservations. |
DUPLICATE_RESERVATION |
409 | Active reservation for same title | Link to the existing reservation. |
COPY_UNAVAILABLE |
409 | Copy cannot be checked out | Refresh and show current state. |
PICKUP_MISMATCH |
409 | Member, reservation, and copy do not match | Ask staff to recheck at the desk. |
PICKUP_EXPIRED |
409 | Pickup is past deadline | Refresh reservation state. |
LOAN_LIMIT |
409 | Pickup or ordinary loan would exceed 3 | Keep ready hold; advise return of a copy. |
MEMBER_INACTIVE |
409 | New reservation, loan, or pickup for inactive member | Reject and refer to staff. |
VERSION_CONFLICT |
409 | Concurrent update collision | Refresh and retry. |
FORBIDDEN |
403 | Unauthorized read or action | Reject without revealing details. |
| Action | Member | Staff | Job |
|---|---|---|---|
| Search catalog | Yes | Yes | - |
| Create or cancel own queued reservation | Yes | - | - |
| View own activity | Yes | - | - |
| See member state needed for pickup | - | Yes | - |
| Return, loan, pickup, cancel ready hold | - | Yes | - |
| Expire holds | - | - | Yes |
Take member ID from the authentication token, never from a claimed identity in a path. Audit staff actions with target ID and reason. Use common responses for missing targets (404), unauthenticated requests (401), and invalid input (422).
12 / 12 ACCEPTANCE TEST PLAN
These are planned, unrun checks for a fictional design, not reported outcomes. A later run should record input, expected and actual states, time, and transaction ID. The base data is BK-104 on page 5.
| Test ID | Requirements | Expected result |
|---|---|---|
| T-01 | F-01 | Initially show 2 total copies, 0 available, 2 queued members. |
| T-02 | F-02, N-01 | R-01 precedes R-02; reject duplicate and third active reservation. |
| T-03 | F-03, F-05, N-01 | CP-01 return makes R-01 ready, R-02 first, available 0. |
| T-04 | F-04, F-05 | R-01 pickup loans CP-01; due Jun 25, 23:59 JST. |
| T-05 | F-07 | CP-02 return holds for R-02; after Jun 16 expiry, available is 1. |
| T-06 | F-06 | Queued cancellation closes the gap; staff ready cancellation reallocates. |
| T-07 | F-08, N-03 | M-02's /me omits R-02; a member calling a staff API gets 403. |
| T-08 | F-09 | Audit return, allocation, pickup, and expiry events. |
| T-09 | N-02 | Retrying one transaction ID creates only one loan or reservation. |
| T-10 | F-03, N-01 | Concurrent returns never assign the first reservation twice. |
| T-11 | F-02, N-01 | Concurrent reservations on other titles keep member total at 2 or less. |
| T-12 | F-04, F-05, N-01 | Pickup racing ordinary checkout on another title keeps unreturned loans at 3 or less. |
| T-13 | F-02, F-04 | Reject inactive member's new actions; cancel and reassign existing active reservations. |
After implementation, confirm T-01 through T-13. At each step inspect the copy total breakdown, one to one hold and ready reservation link, unique copy assignment, and member limits. There are no measured results or executed tests yet.