Should give unique short URL for each long URL input.
When the short URL is queried should redirect to the actual URL
the application should scale to allow 1000s of URL fetch in second
PUT /short_url - given input url generates short url
GET /short_url - given short URL, redirects to the original URL
When user inputs url, generate short url for it. We would generate short url using a built in function, that takes allowed elements, and length and generate short url.
// Go program to generate random characters from the string
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
// String
charset := "abcdefghijklmnopqrstuvwxyz"
// Getting random character
c := charset[rand.Intn(len(charset))]
// Display the character
fmt.Println(string(c))
}
we would then check if the short url exists already in the table, we would generate new if exists already.
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
fields: