Understanding the URL Shortener Users stories

Hi There,
I was trying to work on the URL shortener microservice and am unable to understand:

User Story: I can pass a URL as a parameter and I will receive a shortened URL in the JSON response.

User Story: If I pass an invalid URL that doesn't follow the valid http://www.example.com format, the JSON response will contain an error instead.

User Story: When I visit that shortened URL, it will redirect me to my original link.

I understnad that:

  1. If URL cannot be shortened, it should return an error json.
  2. The correct json will have the shortened URL as well.
  3. But what I do not understand is what/how the url shortening should happen and what role will the db play in this. I would really appreciate if someone could please help me out in understand this.

I think it’s up to you to decide how you’re gonna do the shortening. Maybe generate a short unique string and associate that with the URL? Or just keep an internal counter and assign the current value to an incoming URL?

The db’s role is to store the URLs and their shortened version. So if I wanted to shorten, say, google.com, the server will make a shortened version, then store that in the db. When another user comes in and also inputs google.com, the server will just have to look it up in the db and return that.

1 Like

Why would you have a URL that can’t be shortened? Do you mean because it’s already very short? I don’t think you need to take that into account. The database is for storing the correspondence between the full URL and the short one, so that when someone tries to visit the short one (ie; yourdomain.com/shorturlfragment) it redirects to the real one. You can see my solution working here if you are interested: http://www.lttl.co/

1 Like

Whooaaaaaahhh!!! I get it. Thanks a lot @kevcomedia & @r1chard5mith

User stories are always from the perspective of the user. Users don’t care about exactly what’s happening on the back end, as long as they get a useful short URL.

1 Like

Hey folks,
I have somewhat got it up and running. I know I should have put this in the ‘Project Feedback’ section but I could not wait to show this to you folks because I was able to reach here all because of your help.


I’d really appreciate if you had a look. :slight_smile: Thanks once again.