The Design Authentication Manager interview question involves creating a system to manage user session tokens. Each token has a specific time-to-live (TTL). You need to support generating a new token, renewing an existing (non-expired) token, and counting the number of currently active (non-expired) tokens at a given timestamp. This Design Authentication Manager coding problem focuses on time-based state management.
Oracle and Atlassian ask this to test your proficiency with Hash Table interview patterns and your ability to handle lifecycle logic. It evaluates how you manage data that has a "natural" expiration and how you perform cleanup or filtering based on a dynamic threshold (the current time).
This problem is solved using a Hash Map to track token expirations.
Map<String, Integer> tokens: Stores tokenId -> expirationTime.generate(tokenId, currentTime): Add tokenId to map with value currentTime + timeToLive.renew(tokenId, currentTime): Check if the token exists and tokens.get(tokenId) > currentTime. If so, update the expiration to currentTime + timeToLive.countUnexpiredTokens(currentTime): Iterate through the map and count how many tokens have an expiration time strictly greater than currentTime.TTL = 5.
generate("user1", 1): user1 expires at 6.renew("user1", 2): 2 < 6, so renew. user1 now expires at 7.countUnexpired(6): 7 > 6, so user1 is active. Count = 1.renew("user1", 8): 8 is not < 7. Token already expired. No renewal.countUnexpired(8): Count = 0.>= instead of > for expiration checks. A token is usually considered expired at its expiration time.countUnexpired, if there are many tokens, iteration might be slow. An Ordered Map (TreeMap) or a Doubly-Linked List (like an LRU cache) could optimize the count to or even by removing expired tokens lazily.Always ask if you should "clean up" expired tokens. While not strictly necessary for the count, deleting expired tokens from the map during countUnexpired or renew prevents memory leaks in a long-running system.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| LRU Cache | Medium | Solve | |
| All O`one Data Structure | Hard | Solve | |
| All O`one Data Structure | Hard | Solve | |
| LFU Cache | Hard | Solve | |
| Design Twitter | Medium | Solve |