How to read this chapter
Asha and Bharat both try to book the same theatre seat. This guide explains how a database chooses a valid outcome, preserves it after a crash, and answers queries about it.
Read in order to follow the complete mechanism, or use the contents for revision. After each drawing, explain what changes, what remains protected, and what could fail. The orange map locates the current part.
Each part ends with an “In one breath” recap. The interview page has short questions, graded reasoning exercises, and worked solutions. Explain the assumptions before consulting a formula.
Meet Heron in Pune
Heron is an illustrative Pune theatre-booking database. Asha, Bharat, and Charu are its query-fixture customers. The prices are ₹120, ₹120, and ₹80; amounts are integer rupees. This is a teaching service, not a real booking platform.
| Setting | Symbol or table | Value | What it controls |
|---|---|---|---|
| Customers | users |
100 rows | Owners of bookings |
| Performances | shows |
8 rows | Distinct seat inventories |
| Seats per performance | 100 | Capacity per show | |
| Inventory | show_seats |
800 rows | One row per show and seat |
| Existing bookings | bookings |
160 rows | Query and join examples |
| Replicas | 3 | Quorum examples |
The table defines the shared fixture. Toy storage sizes are not PostgreSQL’s physical layout; engine-specific behavior is identified separately. The companion calculation script is scripts/fundamentals/numbers.py.
What is inside
Read in order for the complete mechanism, or use the contents to revise one topic. Each part highlights its place in the same map.
- 01What the database promisesSections 1 to 3. Two theatre buyers can act on the same stale availability.
- 02Identity and relationshipsSections 4 to 6. A seat belongs to a performance, while a booking belongs to a customer.
- 03Relational algebra and SQLSections 7 to 13. A query needs precise row semantics.
- 04Dependencies and normalizationSections 14 to 22. Repeated facts can become contradictory updates.
- 05Storage and indexesSections 23 to 29. Finding a seat requires navigating physical storage.
- 06Query execution and optimizationSections 30 to 33. The same SQL can use several physical plans.
- 07Transactions and schedulesSections 34 to 38. A booking must remain correct across concurrent actions and crashes.
- 08Locks, versions and validationSections 39 to 43. Readers and writers can need different views of the same record.
- 09Recovery and storage enginesSections 44 to 48. A committed booking must survive its promised failures.
- 10Distributed databasesSections 49 to 52. Copies and shards add new state boundaries.
- 11Application design and PostgreSQLSections 53 to 56. Theatre bookings combine constraints, queries, and uncertain retries.
- 12The complete reservation querySections 57 to 60. Asha's receipt depends on more than finding a row.
- +Interview prepInterview question bank, graded exercises and worked solutions.