Scenarios
Longer problems, like those in senior system design interviews. A strong answer estimates with numbers first, names the mechanism, then recommends a fix and says what it costs.
1Dashboards on an events table slowed from 4 seconds to 90 over six months, while traffic grew only 20%. What do you check, and what do you do?Show the answer
Hypotheses
File count and size, overlap depth on the filtered column, manifest size and planning time, the age of statistics, and whether a maintenance job was switched off.
Tests
Count files and their median size; compare planning time with execution time in the query profile; measure overlap depth at random values.
Typical finding
Millions of files under 1 MB (writers × partitions × commits), planning taking tens of seconds, and wide overlap. Per-file overhead dominates the scan.
Fix
Shuffle before writing, or reduce writers per partition; lengthen the commit interval; compact to 256 MB with selection aware of key ranges; compact manifests.
Prevent
Make maintenance automatic and not optional, with alerts on file count, median file size and overlap depth: work nobody asked for has no one to argue for it. The trade-offs are freshness, background compute, and more history in storage.
Read moreOptimal file sizeOverlap depthWhy maintenance gets switched off
2Design the maintenance for a lakehouse table written by 50 writers into 100 partitions every minute, which must stay queryable with 5-minute freshness.Show the answer
Estimate
Left alone, 5,000 files a minute.
Reduce the producers first
Shuffle by partition so one writer owns each partition, and commit every 5 minutes: at most 100 files per commit, about 20 a minute instead of 5,000.
Then maintain
Compact to 256 MB, triggered per partition by cost (T = √(2C / r)), sorting by the most common filter column. Use narrow conflict detection and jobs of about 500 files, so compaction commits over new appends. Compact manifests on their own schedule. Keep 3 days of history with the rewrite rate measured, so storage stays bounded.
Failure modes
Compaction and writers repeatedly conflicting on the hot partition; a retention window shorter than the longest query; silent corruption (add fingerprint checks).
Recommend
Maintenance built into the table, not a separately scheduled job.
Read moreWhy small files appearTrigger policyConcurrencySnapshot expiration
3Finance wants storage costs cut by 60%. The table is 40 TB live, keeps 14 days of time travel, and is compacted every hour. Where do you look?Show the answer
History first
Storage ≈ live size × (1 + f × R). Hourly compaction might rewrite half the data each day: 40 × (1 + 0.5 × 14) = 320 TB. Cutting history to 3 days and compacting only changed partitions (f = 10%) gives 40 × 1.3 = 52 TB.
Then
Move partitions that have gone unread longer than the break-even (retrieval fee ÷ monthly saving) to a cold tier, but only large files. Remove orphan files, with a grace period of days.
Trade-offs
Shorter time travel, a lower limit on how long queries may run, and retrieval fees if old data is read.
Check first
The longest real query, so the retention window never falls below it.
4Legal asks you to delete one customer's data from a petabyte-scale table within 30 days, and also to preserve another customer's data under a legal hold.Show the answer
Deletion
Find the files holding the customer's rows from manifest statistics, rewrite them without those rows, expire every snapshot referencing the old files, and verify with counts. The cost follows file size, not row size: with 1 GB files, one row can cost up to 1 GB of rewriting. Time travel can now reach back no further than the regulatory window.
Legal hold
A per-object hold that vacuum, snapshot expiry and orphan removal all check.
Recommend
For new data, a key per person, so deletion is just deleting the key, accepting that the key granularity is fixed forever. For existing data, batch many deletions into each rewrite to spread the cost.
Failure modes
A snapshot that still references the data; a backup copy; a long-running reader; and a legal hold that conflicts with a deletion deadline, which is an organizational decision, not a technical one.
Read moreRetention and legal holdVacuum
5The nightly compaction fails every night on the hottest partition. Fix it.Show the answer
Diagnose
The job is a long transaction that keeps losing the optimistic commit to short appends; its chance of conflict grows with its duration.
Fix
- Narrow the conflict check to "were my input files touched?".
- Split the work into short jobs of a few hundred files, so each commits quickly.
- Run more often, so each job stays small; the interval follows T = √(2C / r) per partition.
- If deletes touch the same files, retry only that group.
Verify
Count and fingerprint before each commit.
Trade-offs
More commits mean more metadata, so compact manifests; and jobs that are too small rewrite more in total, since each compaction level rewrites the data again.
6A product manager proposes moving everything to cold storage after 30 days to save money. Evaluate the proposal.Show the answer
Estimate
The break-even is retrieval fee ÷ monthly saving, about 3.5 months in a typical example. If most data is read again within that time, for example by month-end reports at 60 days, tiering loses money.
Check
Minimum storage-duration charges, and the per-object transition cost: a table of small files pays that per-object price millions of times.
Recommend
Tier only large, compacted files whose dormancy has been measured. Most teams lack per-file read data, so start by collecting it.
Read moreLifecycle tiering
7A PostgreSQL table keeps growing although rows are being deleted and autovacuum is running. What do you check?Show the answer
Check
The age of the oldest transaction (pg_stat_activity: xact_start, backend_xmin), abandoned replication slots, and forgotten prepared transactions. A single old reader stops reclamation of every version written during its lifetime.
Fix
End or limit the transaction (set idle-in-transaction timeouts), put oldest-reader age on the dashboard, and accept the cost of a manual vacuum afterwards.
Also
Reduce version churn with HOT updates and a lower fill factor.
Read moreThe slowest readerThe oldest reader pins everything