Rounds 6–10
Round 6 — Schema Design
Scenario: design a multi-tenant project/task SaaS schema.
Questions
- Identify entities, candidate keys, relationships and invariants before writing DDL.
- Choose UUIDv7 vs bigint IDs and justify.
- Enforce tenant-scoped project slug uniqueness and prevent cross-tenant task→project references.
- Explain where JSONB is appropriate and where it weakens the model.
- Design zero-downtime evolution for a new required
project_type.
Strong-answer checkpoints: composite tenant-aware keys/FKs, constraints as invariant guardians, normalization first, typed stable fields, expand/backfill/validate/contract.
Scoring emphasis: modelling 35, constraints 25, evolution 20, tenancy/security 20.
Follow-up: When would you move one large tenant to a dedicated database?
Round 7 — Indexing
Scenario: orders has 500M rows; hot query filters tenant/status and sorts newest first.
Questions
- Design a candidate B-tree and explain column order.
- When would a partial index be better?
- Explain
INCLUDEand index-only scan requirements. - Compare B-tree, GIN, GiST, BRIN and Hash with one workload each.
- What write/HOT/WAL/storage costs must be reviewed before adding the index?
Strong-answer checkpoints: equality keys before ordered range where appropriate, workload not cardinality slogans, visibility map, operator class/access method fit, redundant-index audit.
Scoring emphasis: access-path reasoning 35, PostgreSQL mechanics 25, write trade-offs 25, validation plan 15.
Follow-up: Why might PostgreSQL still choose a Seq Scan after your index exists?
Round 8 — Transactions
Questions
- Explain ACID with PostgreSQL mechanisms, not definitions only.
- Describe autocommit and what happens after an error inside an explicit transaction.
- Show a savepoint use case and explain why it is not an independently committed nested transaction.
- Define a business transaction boundary for checkout.
- Explain why an external payment HTTP request should not stay inside an open DB transaction.
Strong-answer checkpoints: WAL/durability, constraints/consistency, isolation/concurrency, aborted transaction state, outbox/idempotency for external effects.
Scoring emphasis: transaction semantics 40, application boundaries 30, failure handling 20, communication 10.
Follow-up: Which work belongs in the same transaction as an outbox row?
Round 9 — Concurrency
Scenario: two users try to buy the final unit; other workers claim jobs simultaneously.
Questions
- Show the read-modify-write race and fix it with atomic conditional UPDATE.
- Optimistic version column vs
SELECT FOR UPDATE: when choose each? - Explain Read Committed, Repeatable Read and Serializable in PostgreSQL.
- Give a write-skew example and explain SSI retries.
- Design a
SKIP LOCKEDworker claim with lease/idempotency.
Strong-answer checkpoints: affected-row protocol, deterministic lock ordering, whole-transaction retry of 40001/40P01, SKIP LOCKED intentionally incomplete view, short claim transaction.
Scoring emphasis: correctness under concurrency 45, isolation mechanics 25, failure/retry 20, communication 10.
Follow-up: How do deadlocks differ from serialization failures?
Round 10 — EXPLAIN
Scenario: an endpoint query rose from 40 ms to 2 s.
Questions
- Read a plan node’s cost, estimated rows, actual rows and loops correctly.
- Explain why
rows × loopsmatters. - Compare Seq Scan, Index Scan, Index Only Scan and Bitmap Heap Scan.
- Diagnose a Hash Join whose estimated build input is 500 rows but actual is 500k.
- Use BUFFERS/WAL/SETTINGS and distinguish execution from lock waiting.
Strong-answer checkpoints: first estimate divergence, plan node multiplication, visibility map for index-only, statistics/skew/extended stats, representative parameters, pg_stat_activity for waits.
Scoring emphasis: plan interpretation 45, root-cause method 30, evidence discipline 15, safety 10.
Fail condition: calls every Seq Scan bad or proposes disabling it globally.
Follow-up: Why is EXPLAIN ANALYZE DELETE ... dangerous?