Store mappings of long URL to short URL in database. Stored as a Hashmap. When user inputs a given long URL, hash that URL to a given short URL and return it to the user.
Reverse map of short URL to long URL for retreival. Both mappings are created when a user generates a short URL.
Purge uncommon mappings on a regular bases (Ex: weekly). More common mappings can persist longer to prevent unecessary creations and deletions. Add a deletion date to new short URL requests, stored in database. Daily sweeper will check for expired short URLs and delete them.
Separate full URL into components and generate common prefixes for them. Ex: "google.com" has a set prefix. "google.com/search?q=asdf" is separated into the google.com prefix and search?q=asdf suffix. Each "/" character can act as a separator for prefixes. Hash these separately and store common database pulls in cache for faster retreival.
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
createURL() - creates mappings for shortURL -> fullURL and vicer versa and stores in database. Returns the shortURL to the user on request.
retrieveURL() - retreives fullURL mapping for a given shortURL mapping on request. Pulls from database, with more common entries stored in cache.
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
Define the data model. Identify the main entities, their attributes, and relationships. Consider the choice of database type (SQL vs NoSQL) and justify your decision based on access patterns...
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.