TTL, Expiration, And Snapshot Semantics
Asked of: Software Engineer
Last updated

What's being tested
This tests time-aware in-memory state management: storing records whose visibility depends on currentTime, ttl, and snapshot/restore rules. Interviewers are probing whether you can design clean data structures, implement deterministic expiration, and preserve correctness across scans, quotas, backups, restores, and versioned mutations.
Patterns & templates
-
Lazy expiration — check
expireAt <= nowinsideget,scan,list, andbackup; avoid eager cleanup unless required. -
Absolute expiry timestamps — store
expireAt = timestamp + ttl, not remaining TTL; useNoneorINFfor non-expiring records. -
Snapshot semantics —
backup(now)should persist only live records, often as remaining TTL:remaining = expireAt - now. -
Restore semantics — rebuild expiry relative to restore time:
newExpireAt = restoreTime + savedRemainingTtl; preserve non-expiring values unchanged. -
Nested maps — common shape is
db[key][field] = {value, expireAt}; operations are usuallyO(1)point lookup andO(k log k)sorted scans. -
Deterministic scans — prefix scans require filtering live fields first, then lexicographic sort; do not rely on hash-map iteration order.
-
Quota plus TTL accounting — storage usage must exclude expired files/tasks; call
purgeExpired(user, now)before capacity checks or priority lists.
Common pitfalls
Pitfall: Treating TTL as duration forever instead of converting to an absolute deadline causes incorrect behavior after multiple reads, backups, or restores.
Pitfall: Backing up expired records because they still exist in the hash map violates snapshot semantics; logical liveness matters more than physical presence.
Pitfall: Sorting before filtering can leak expired fields into prefix scans or produce wrong ordering when deleted/reinserted records share names.
Practice these
The practice cards below cover the canonical variants — solve all of them and time yourself.
Featured in interview prep guides
Practice questions
- Design a task management system with TTLCoinbase · Software Engineer · Take-home Project · medium
- Implement cloud storage with quotas and compressionCoinbase · Software Engineer · Technical Screen · medium
- Implement a versioned recipe management systemCoinbase · Software Engineer · Take-home Project · medium
- Design an in-memory database with TTL and backupsCoinbase · Software Engineer · Take-home Project · medium
- Design a scalable URL shortener with expiration and securityCoinbase · Software Engineer · Onsite · hard
Related concepts
- Caching And Stateful Data Structure DesignCoding & Algorithms
- Temporal Event Processing And Interval AlgorithmsCoding & Algorithms
- Messaging, Event Pipelines, and Delivery SemanticsSystem Design
- Fault Tolerance, Idempotency, And Concurrency ControlSystem Design
- Intervals, Sliding Windows, And Time-Ordered StateCoding & Algorithms
- Snapshotable Collections And IteratorsCoding & Algorithms