3

How does Stack Overflow map its users' accounts?

I tried to figure out how it does, but I can't find an answer. If you see the links when you hover over an user, you'll see this "pattern":

/users/number/username For example: users/2136639/leomestizo (my profile).

My guess is (imagine that Stack Overflow is programmed with Java):

  1. SO stores a JSP page for each user (doesn't seem to be the answer. If there's more than million users, there will be more than a million JSP pages! Not automatized)
  2. SO has a servlet (without the MVC pattern) that sends the HTML based in the parameter send to it, for example if the servlet is called "ProfileServlet", it could have an anchor tag like this: profileServlet?username="leomestizo". I think this could be an answer, but why the URL is always /user/number/username ?

Sorry if this seems to be a stupid question. I'm student and I do my best.

6
  • 6
    Stack Overflow doesn't use Java Server Pages. Users are stored in a SQL Server database, and mapped by their ID (that number you see in the URL); the user name is in the URL for SEO reasons, but is not used for mapping. User pages are automatically generated by ASP.NET MVC; a View Template is used to generate the HTML, among other things.
    – user102937
    Dec 24, 2013 at 16:53
  • I know nothing about JSP, but the Wikipedia article states that pages are generated dynamically, which almost certainly means that it doesn't store a million pages, but only one, which would be used to dynamically generate all the user pages (if Stack Overflow had used JSP).
    – user102937
    Dec 24, 2013 at 16:59
  • @TheGrinch Oh, ok! But, if you inspect the HTML code, you'll see the above pattern (I mean /user/number/username). Where would be the "controller"? As far as I know, if we have to map for a page, you have to put the name of the file of code in the URL, for example if we had a servlet called "RegisterServlet" (a servlet for register users and store them in the database), we have to map in the URL like "register".
    – leoMestizo
    Dec 24, 2013 at 17:11
  • The controller would be specified by the user part of the URL. The controller already knows which View template to use. There's a routing engine that deals with each part in the URL; it routes this particular URL to the UserController, and specifies the UserID as a parameter to the handling function. More info about ASP.NET MVC and how it specifically works can be found at asp.net/mvc, if you're so inclined.
    – user102937
    Dec 24, 2013 at 17:12
  • Sorry, I didn't understand you. You mean that the user (a person) be the controller? As far as I know, in the MVC pattern, the M (Model) are the business classes, the V (View) are the UI, and the C (Controller) are the "bridge" that allow the "communication" between the UI and the business.
    – leoMestizo
    Dec 24, 2013 at 17:18
  • 1
    A detailed tutorial on ASP.NET MVC is probably beyond the scope of this question, but it basically goes like this: POST URL --> Routing Engine --> Controller --> Controller Method --> Dynamically Generated View
    – user102937
    Dec 24, 2013 at 17:21

1 Answer 1

4

This is what I think. I am not 100% sure about it.

As you say format of the URL is:

https://meta.stackoverflow.com/users/number/user_name

There will be some file say user.aspx such that when a user visit https://meta.stackoverflow.com/users/x/y the request is redirected to https://meta.stackoverflow.com/user.aspx?num=x&user_name=y

Here, number is a unique ID associated with every user. Neither it can be change nor two users can have it same.

Then come user_name part. I think this is just for SEO and so that user will feel that his/her name is shown in URL. You can actually try different values for it but it will show same profile every time. e.g. both https://meta.stackoverflow.com/users/219322/varunagw and https://meta.stackoverflow.com/users/219322/varun redirects to my profile. It is of no special use

5
  • This is what I've been looking for! Can you explain me the "request part" ("when a user visit [...]" part). That's what I don't understand. I mean, how it's possible that an anchor tag with the "stackoverflow.com/user/x/z" value in the href attribute will be redirect to another page?
    – leoMestizo
    Dec 24, 2013 at 17:31
  • 1
    In web servers you can certain rules like when a user visit http://example.com/dir/filename, the page at http://example.com/handler will execute and it will also get the value of filename. In this way you can have lot of different files without creating a different page for each.
    – user219322
    Dec 24, 2013 at 17:36
  • You can see examples at google.com/…
    – user219322
    Dec 24, 2013 at 17:37
  • Thanks a lot! I'll find if there's the same solution in Tomcat web container! Thanks again!
    – leoMestizo
    Dec 24, 2013 at 17:38
  • 1
    Most of latest web server supports this. You can check documentation for your server.
    – user219322
    Dec 24, 2013 at 17:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .