Reservation Notes Feature: Domain Model, Permissions, Bulk Edits
System DesignModel answerLast updated
Design the object model and system for free-text notes on a reservation, with owner and admin edit rights, change auditing, and a safe path for bulk admin updates.
You are building a feature for a reservation platform (hotels, flights, or similar) that lets a booking carry a short free-text special note, such as "quiet room please" or "arriving late".
Requirements
- Every reservation may have one special note.
- The customer who owns a reservation can add, change, or clear the note on their own booking.
- An administrator can change the note on any booking.
- Administrators also need a bulk operation: apply a note change (for example, a policy notice) to a very large set of reservations, potentially thousands or more, in one action.
What to deliver
- An object-oriented model: the main classes or entities, their responsibilities, and where the permission rules live.
- A high-level system design: API surface, storage layout, and how components interact.
- A bulk update strategy that remains safe for the primary database and for users editing at the same time.
Decisions you should make explicit
- Is the note a single field, or a list or history of entries?
- Do you need to record who changed what and when?
- What scale do you assume (reservation count, write rate, size of a bulk job)?
State your assumptions, justify them, and discuss trade-offs and failure cases.
Hints
Hint 1
Decide early whether you store one current value plus an append-only history, and what that buys you for audit and for concurrent edits.
Hint 2
Put the 'who may edit what' rule in one replaceable policy component rather than scattering role checks, and use a version number or ETag so simultaneous edits cannot silently overwrite each other.
Hint 3
For the bulk path, do not run one giant transaction: plan the target set, split it into chunks, process them asynchronously with idempotency and progress tracking, and think about dry-run, cancel, and revert.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Assumptions
Functional
- Each reservation has one current note, and every change is also stored in an append-only revision history. Reads stay simple and auditing is complete.
- Owners can create, edit, or clear the note only while the booking is active (not cancelled or completed).
- Admins can edit any note and view its history.
- Bulk modes:
REPLACE,APPEND,CLEAR.
Non-functional
- Auditability is mandatory: actor, time, source (user, admin, batch), old and new text.
- No silent lost updates when a user and an admin edit at the same moment.
- Notes are plain text, capped (say 1,000 characters), validated on input and escaped on output.
Scale (assumed)
- About 50M reservations, roughly 100K note writes per day (about 1 QPS average, about 20 QPS peak). Reads are about 10x writes and are served with the booking page.
- A few bulk jobs per day, each touching 1K to 1M reservations.
- Storage is around 25 GB for current values, plus a few times that for history.
Single-row writes are easy at this scale. The real difficulty is authorization, concurrency, and the bulk path.
2. Object model
Actor(id, role)where role isUSERorADMIN.Reservation(aggregate root):id,ownerId,status,note(value object withtext,version,updatedBy,updatedAt). MethodupdateNote(text, actor, expectedVersion, source, now)checks the version, produces the new note, and returns aNoteRevision.NoteRevision(immutable):reservationId,version,oldText,newText,actorId,source,batchJobId?,createdAt.NotePermissionPolicy(strategy):canEdit(actor, reservation). Admin returns true. An owner returns true only if they own the booking and it is active. New roles (for example a travel manager for a team) are added here only.NoteValidator: length, character set, sanitization.NoteService: orchestrates load, authorize, validate, update, persist with revision, publish event.
Why this shape: the aggregate guards its own invariant (versioning), the policy is swappable, and the service stays thin and testable.
3. API
GET /reservations/{id}/notereturns text, version, updatedBy, updatedAt.PUT /reservations/{id}/notewithIf-Match: <version>and body{text}.DELETEbehaves the same way.GET /admin/reservations/{id}/note/history.POST /admin/note-batcheswith anIdempotency-Key, body{selector, mode, text, dryRun}. The selector is an ID list, a filter (company, date range), or an uploaded file reference. It returns202 {jobId}.GET /admin/note-batches/{jobId}returns status and counts (total, succeeded, failed, conflicted).POST .../cancelandPOST .../revert.
A version mismatch returns 412 Precondition Failed, and the client shows the latest text so the user can reapply their edit.
4. Storage
Relational database (for example Postgres):
reservation(..., note TEXT, note_version INT, note_updated_by, note_updated_at). Inline, because it is always read with the booking.note_revision(id, reservation_id, version, old_text, new_text, actor_id, source, batch_job_id, created_at)withUNIQUE(reservation_id, version)and an index onbatch_job_id.note_batch_job(id, created_by, selector, mode, text, status, counts, idempotency_key UNIQUE).note_batch_chunk(job_id, chunk_no, reservation_ids, status, attempts, last_error).outbox(id, type, payload, published_at).
Single write, optimistic concurrency:
UPDATE reservation
SET note = :text, note_version = note_version + 1, ...
WHERE id = :id AND note_version = :expected;
Zero rows updated means a conflict. The update, the revision insert, and the outbox insert commit in one transaction.
5. Architecture
Client goes through the gateway (authentication) to the note service and the database (primary plus read replicas). A transactional outbox feeds a message bus so downstream consumers (supplier sync such as a hotel's special-requests field, search index, notifications) see every change without dual-write bugs. Consumers must be idempotent, keyed on (reservationId, version).
6. Bulk updates
Never run one huge transaction: it holds locks, bloats the log, and blocks normal traffic.
- Validate and plan. Check the caller is an admin, resolve the selector to a snapshot of IDs (or a stable cursor), and offer dry run that returns the count and a sample of before/after.
- Create a job with an idempotency key so a retried request does not start a second job.
- Chunk the IDs (for example 500 to 1,000 per chunk) and enqueue the chunks.
- Workers process each chunk in a short transaction. For each reservation they apply the mode, bump the version, write a revision tagged with
batch_job_id, and write outbox events.APPENDis made idempotent by checking whether the job's marker text is already present or whether a revision with thisbatch_job_idalready exists, so a chunk retry does nothing twice. - Concurrency. The batch uses the same versioned update. If a user edited meanwhile, either re-read and retry a few times (fine for
APPEND) or record a conflict forREPLACE, depending on policy. - Throttling. Cap workers and per-second writes, prefer replicas for selection, and run large jobs off-peak or with backpressure based on database load.
- Progress and control. Update counters, expose status, support cancel (stop dispatching chunks) and revert (replay the revisions of that
batch_job_idbackwards, skipping rows changed since). - Failure handling. Retries with backoff, a dead-letter list for poison chunks, and a report of failed IDs the admin can re-run.
Alternative at much larger scale: shard by reservation ID and run per-shard workers; the chunk model already supports this.
7. Trade-offs
- Single field versus list of notes. A list suits conversations between user and admin but complicates display and supplier sync. The single-value-plus-history approach keeps reads simple. Mention that you would switch to a list if multi-party discussion became a requirement.
- Optimistic versus pessimistic locking. Contention on one note is very low, so optimistic is cheaper and avoids lock waits.
- Inline column versus separate table. Inline saves a join; a separate table is better if notes become large or optional.
- Synchronous versus asynchronous bulk. Asynchronous adds job tracking but protects the primary.
8. Common mistakes
- Role checks scattered through controllers, and forgetting the ownership check (an IDOR vulnerability).
- Last-write-wins with no version, silently discarding an admin's or user's edit.
- No audit trail, or an audit row written outside the transaction.
- A single transaction for the whole bulk job, or a non-idempotent
APPENDthat duplicates text on retry. - Rendering unescaped text, which allows stored XSS.
- Letting a bulk job bypass validation, length limits, or audit.
9. Observability and testing
Track write latency, conflict rate (412s), job duration, chunk failure rate, and outbox lag. Test the policy matrix (owner, other user, admin, cancelled booking), concurrent edits, chunk retry idempotency, and revert correctness.