PostgreSQL
medium 32 minPostgreSQL is an open-source relational database that never overwrites a row: every change adds a new version, readers pick the version their snapshot may see, and vacuum clears away versions nobody needs.
When it comes up
The moments this idea belongs in a design interview, and the moments it does not.
Signals
When to bring it up
| You hear | Say | Because |
|---|---|---|
| Orders, payments, bookings | PostgreSQL, with constraints and transactions | Wrong data costs more than latency |
| Filters nobody has planned yet | A relational store with indexes | New questions need no new data model |
| Nearby places | PostGIS | The index understands distance |
| Background jobs, modest rate | A jobs table with SKIP LOCKED | One less system to run |
| Millions of writes a second | Not one primary | Partitioned log or wide-column store |
| Thousands of functions | A pooler | Every connection is a process |
In the interview
- Give one reason from the data, not from fame
- Name the standby and the pool without being asked
- State the trigger for replicas and for sharding
- Mention vacuum when updates are heavy
Avoid
- Sharding 200 GB
- Calling a replica a backup
- Promising zero loss with asynchronous standbys
- One connection per request
Options
Explain your choices
A busy orders table has become slow and three times its normal size. What do you do?
BreaksTurn autovacuum off and shard
- How
- Stop the background load and split the table over servers.
- Limit
- Bloat grows on every shard and ids move towards wraparound.
- Choose when
- Never as a first step.
WorksVACUUM FULL tonight
- How
- Rewrite the table in a window.
- Limit
- It locks out everyone, and the bloat returns because the cause is still there.
- Choose when
- Once, after the cause is fixed, if a window exists.
StrongFind what holds vacuum back, then repack online
- How
- Find the oldest transaction or slot, end it, add timeouts, lower the table's scale factor, then use REPACK CONCURRENTLY.
- Limit
- Needs space for a second copy and version 19, or an extension on older ones.
- Choose when
- The normal answer.