Interview question bank
Explain what the mechanism protects, how it works, and where it can fail. Use the running example rather than reciting a definition.
Q1. Why use a DBMS rather than a seat-inventory file?
A database coordinates concurrent updates, constraints, queries, and recovery. A file can store “A7 is free” but does not itself prevent Asha and Bharat from both accepting that observation.
Q2. What makes a candidate key different from a superkey?
Both identify a row, but a candidate key is minimal. Removing any of its attributes loses uniqueness. A chosen candidate becomes the primary key; the others remain valid alternatives.
Q3. Why normalize?
Store each fact under the attributes that actually determine it. Otherwise a college student’s name can be repeated across enrollments and inconsistently updated. Decomposition must also preserve the intended join and enforceable dependencies.
Q4. Why does SQL differ from relational algebra?
SQL normally preserves duplicates and uses NULL with three-valued logic. Mathematical relations use sets. The same projection can therefore return different multiplicities unless SQL requests DISTINCT.
Q5. When does an index help?
When its organization matches the predicate, ordering, and data distribution well enough to avoid expensive work. It adds storage and update cost, and a broad scan can still be cheaper.
Q6. What does EXPLAIN establish?
It describes a chosen physical plan. EXPLAIN ANALYZE also executes it and reports observations. Compare estimates with actual work, and remember that running it on a write can change data.
Q7. What do ACID properties require?
Atomicity handles the operation as a unit; consistency preserves declared invariants; isolation constrains concurrent observations; durability preserves acknowledged commits under a stated failure model. Naming the acronym supplies none of those mechanisms.
Q8. Why can two valid transactions still violate a business rule?
Their observations may overlap under an isolation level that permits the relevant anomaly. Constraints, appropriate locking, validation, or serializable execution must protect the actual invariant.
Q9. Why does MVCC not eliminate coordination?
Snapshots let readers see permitted older versions, but conflicting writes still need rules. Old versions also need reclamation, and visibility is separate from the application’s merge policy.
Q10. Why write the log before the data page?
The log must contain durable recovery evidence before a changed page reaches disk. A commit can then survive even while its data page remains dirty in memory, subject to the engine’s flush guarantees.
Q11. What is the limit of replica or quorum arithmetic?
Replica counts and intersecting sets do not define ordering, failure handling, or promotion. The protocol must establish the consistency and durability being claimed.
Q12. Why use an idempotency key for a booking?
A lost response can follow a successful commit. Reusing one operation identity lets the application reconcile that result instead of claiming the seat again under a fresh request.
Exercises
One filled dot is a short explanation, two require diagnosis, and three require a complete design. Draw the mechanism before checking the solution.
E1 ●○○ Asha buys two ₹120 tickets; Bharat buys one ₹80 ticket. Explain why joining users to bookings repeats Asha, and why Charu needs a left join to remain visible.
E2 ●○○ A college stores each student’s name on every enrollment row. What does splitting the tables repair?
E3 ●●○ Asha and Bharat both see theatre seat A7 as free. Describe a commit path that permits only one claim.
E4 ●●○ A booking succeeds, but an immediate replica read says the seat is free. Diagnose the discrepancy.
E5 ●●● Design a retry-safe booking plus confirmation message.
E6 ●●● Plan an investigation of a slow booking-history query.
Worked solutions
Check the reasoning and its assumptions, not only the conclusion.
E1. An inner join emits a row for each matching booking, so Asha appears twice and Bharat once. Charu has no match and disappears. A left join preserves Charu with NULL booking fields. Aggregation groups the repeated matches when totals per user are required.
E2. The name depends on the student, while enrollment facts depend on the student-course pair. Separate those responsibilities so a name change updates one fact. Join them for a report, and check that keys and dependencies preserve the intended records.
E3. Make the seat identity include the show. Perform a conditional update or protected check-and-write inside the transaction, backed by the appropriate uniqueness constraint. The losing request waits, conflicts, or finds no available row. A browser’s earlier read is not the commit decision.
E4. The replica may not have applied the committed update yet. Read from the leader or wait for a replica to reach a known committed position under the promised consistency policy. Do not treat every stale read as a failed commit.
E5. Use one stable submission identity and transactionally claim the seat and record the booking. Record an outbox event in the same transaction. Retry submissions by the same identity; dispatch and deduplicate confirmation separately. This connects the durable booking to eventual messaging without pretending a database commit atomically sends an external message.
E6. Inspect the query and representative parameters, then compare estimated and actual rows in its plan. Check scan predicates, join choices, sorts, page work, and lock waits. Test an index that matches the access pattern and measure its update cost. Keep correctness and concurrency checks alongside timing.