The complete reservation query
Asha’s receipt depends on more than finding a row. Several mechanisms must agree before success is acknowledged. Follow the claim through planning, storage, concurrency, and durable recording.
#Section 57A reservation from SQL to durable commit
Asha’s booking crosses validation, SQL planning, execution, and concurrency rules before commit. No single fast lookup establishes the whole outcome.
The access path traverses index structure and locates the row. A buffer hit can serve a logical page visit without physical device I/O.
A conditional update can claim the seat only while it is available. The transaction records a booking and publication intent only if it obtains that claim. The engine preserves required WAL before the associated changed page reaches persistent storage, and the configured durable commit boundary precedes a success response. Pages can remain dirty in the buffer pool after a no-force commit.
BEGIN;
UPDATE show_seats
SET state = 'held', version = version + 1
WHERE show_id = :show AND seat_id = :seat AND state = 'free'
RETURNING show_id, seat_id, version;
COMMIT;This short statement shows the claim mechanism, not the complete application transaction. The handler must inspect the returned row count and insert the booking and outbox in the same transaction before commit. If no row is returned, it cannot create a successful booking. The actual identifier types and SQL parameter syntax depend on the driver.
Reconcile a lost response with the same stable submission identity. Schema, access, concurrency, and durable receipt each support a different part of the successful booking.
#Section 58Two buyers and one seat
Bharat’s browser may still show free while Asha’s claim is open. Recheck the admitted state at the atomic write boundary.
Under a row-locking path, Asha’s update obtains the needed lock. Bharat’s conflicting update waits or fails under the configured policy. After Asha commits, Bharat must evaluate the current permitted row state under the engine’s isolation behavior. At PostgreSQL Read Committed, a conflicting update can wait and then re-evaluate its condition on the updated row; an available-state condition cannot keep winning merely because Bharat’s original view was free.
An optimistic claim compares and increments the version atomically. The stale buyer then conflicts. A separate version read followed by an unconditional write would recreate the race.
A uniqueness constraint is a final enforcement boundary when the schema models active seat claims as unique rows. The application still needs to interpret the conflict and handle expiration, cancellation and confirmation under one allowed state machine. Deleting and recreating claim rows casually can let a late payment confirm the wrong booking generation.
The interview answer should identify the invariant first, one valid active owner per show-seat. Then name the atomic conditional operation or lock, the database constraint where applicable, and the retry identity. Isolation labels alone do not prove that a particular application’s sequence implements its invariant. PostgreSQL’s locking reference describes the concrete conflicting row-lock behavior used in this trace.
#Section 59Storage overhead and model assumptions
The storage figure uses a declared toy layout. It illustrates why partially filled pages and index levels cost space, rather than defining PostgreSQL’s real layout.
Page headers and slots consume space, so capacity admits only whole records that fit. The last partially filled page still occupies a complete allocation.
Packed page arithmetic describes a teaching layout. Live occupancy changes with versions, variable records, and reserved free space.
Index leaves and routing pages add their own storage. Their cost is separate from heap rows and must follow the chosen layout.
Replicas copy the modeled footprint, but WAL, retained history, backups, and metadata add other costs. Estimate the real engine with its own physical inputs.
#Section 60Responsibilities of every database component
Asha’s held-seat receipt requires several mechanisms to agree. An index locates data, concurrency control protects the claim, and durable recording preserves it.
| Component | Contribution | Failure it does not solve alone |
|---|---|---|
| Schema and constraints | Valid identities and references | Race in an unchecked application sequence |
| Relational query and SQL | State the required row computation | Storage and scheduling cost |
| Optimizer | Choose an estimated access plan | Wrong or stale selectivity evidence |
| Index | Locate ordered keys efficiently | Permission and tuple visibility |
| Buffer manager | Reuse pages with pin and dirty rules | Durable commit acknowledgement |
| Locks and atomic predicates | Coordinate competing effects | Replay of an external command |
| MVCC and snapshots | Select allowed row versions | Reclamation without maintenance |
| WAL and recovery | Restore the durable state contract | Loss outside that configured boundary |
| Replication | Maintain additional state copies | Promotion without valid authority |
| Outbox and identity | Recover publication and repeated attempts | Atomic remote effects without a protocol |
Logical rows, resident pages, and retained physical versions are different counts. One booking can add a logical header while changing existing inventory and producing additional physical history.
The study loop is to redraw the reservation path and change one assumption. Remove the index, hold an old snapshot, lose power after durable commit, let the response disappear, or promote a lagging follower. Each change should lead to a named mechanism and a permitted outcome rather than another vague claim that the database is safe.
This chapter did not implement a SQL optimizer, a full consensus protocol, storage-device guarantees or a payment provider. Computer Networks follows the packets that carry the request. Operating Systems follows the process, memory and I/O machinery on which the database depends. The database boundary is now explicit enough to know what those next chapters must supply.