Compare
Side-by-side on the decisions that recur: index vs scan, normalize vs denormalize, optimistic vs pessimistic, partition vs shard, and more — with when to choose each.
Index Scan vs Sequential ScanNormalize vs DenormalizeOptimistic locking vs Pessimistic lockingRead Committed vs SerializablePartitioning vs ShardingRead replica vs ShardRelational vs DocumentPostgres + pgvector vs Dedicated vector DBCache-aside vs Write-throughB+ tree storage engine vs LSM tree storage engineHeap table + secondary indexes (PostgreSQL-style) vs Clustered primary index (InnoDB-style)LRU vs Clock (second chance)Synchronous replication vs Asynchronous replication
| LRU | Clock (second chance) | |
|---|---|---|
| Structure | doubly linked list + hash map; move to head on every hit | circular array + one reference bit per frame + a hand |
| Cost per hit | list surgery under a lock — contention on hot pages | set a bit; no lock |
| Eviction | exact least-recently-used | approximately LRU: clear bits as the hand sweeps |
| Sequential flood | a big scan evicts the whole working set | same, unless paired with ring buffers / old-young sublists |
| Used by | in-memory caches, textbooks | PostgreSQL clock-sweep; Linux page cache variants |
| Choose this when | Small caches, single-threaded access, when exact recency matters (and for the DSA interview). | Large shared buffer pools with many concurrent readers where the per-hit cost of exact LRU is the bottleneck. |