01
Design a key-value store that supports TTL.
Tap to write answer
0 words | 0 charsPress Enter ↵ to reveal
Your Attempt
0 wordsRefined Model Answer
ReferenceI would first ask how many keys we need to support, how accurate the expiration needs to be, and whether expired values should disappear immediately or lazily. My default design would store each key with a value and an expiration timestamp, then remove expired entries on access and with a background cleanup process. The reason I choose this approach is that it keeps reads fast and avoids scanning the whole store on every request. I would also think about what happens when many keys expire at once, because that can create a cleanup spike. If the interviewer wants more depth, I would discuss indexing expirations separately so the sweeper does less work.