Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.



Non-Functional Requirements:


  • high availability for reads
  • low latency for reads
  • A user should be able to generate as many unique links for the same long url
  • two different users should be able to generate a unique short link for the same url


API Design

Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...


createLink(longUrl: string) -> (shortUrl, err)

getLongUrl(shortUrl: string)-> (longUrl, err)



High-Level Design

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.

this is going to be a very read heavy service. Although don't expect the number of writes to be high. we will use an in memory cache, holding onto most recently used key value pairs for short -> long urls

if a client requests a url not in cache server will write to cache first and the response will be made directly from cache


db schema:

uuid(be able to have unique short->long urls)

shortLink

longLink

createdAt

lastAccessed(identify what to push off LRU cache)

user_uuid (so that users can delete their own links when they want to invalidate)




Detailed Component Design

Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.