none
N tier or N layer? RRS feed

  • Question

  • I'm working on a enterprise project(in .net framework 4.0) , Something like microsoft outlook express but a bit diffrent, actually I should store all the messages and other data  in a centeral database ,

    At first I desgined it as a n layer application (I use entity framework 4.0 as datalayer)

    But I've read an article about EF 4.0 and N tier application recently { The article is here: http://msdn.microsoft.com/en-us/magazine/ee335715.aspx

    And I decided to change the architect to Ntier and use wcf servie ... [you can see the architect in the article I linked above]

    But I'm not sure that , my decide is correct or not ??!!

    So It's nice to hear your idea about this.

    one more thing is my UI is windows form now but It might be changed to asp.net web site

    thanks alot,

    Tuesday, November 16, 2010 8:04 AM

Answers

  • N tier shares the load across machines.   Maybe you've heard of the saying "many hands make lighter work". 

    If you look at it in simple terms your one machine has X processing power and Y memory.

    Add a second server and you have 2X processing power and Y memory.

    There are complications like passing data across and firing up new processes so you don't really get that full return but let's gloss over that for now.

    Say you add another machine and you've got 3 machines then  = 3 X processing and 3Y memory. 

    Compared to this, your one machine is going to hit it's limits faster as usage goes up.

    Let's consider in some detail a 6 machine set up for a high throughput web site.

    1 & 2 are web servers.  They cache to a server 3.  When some pages are served they come straight out the cache, user session data out 3.  Machine 4 handles business objects and caches some of these on machine 5.  Many read only transactions involve one of machine 1 or 2, machine 3, 4 and 5.  Updates also go to machine 6, the database server, 6.

    The database server is also used for other internal applications.  None of these impinge on machines 1 through 5. 

    If you just have 1 user then one machine would have been fine and you didn't need all that complexity.  As you get into thousands of users though you will see huge benefits from that caching.  With one server you'd have less memory caching pages, session and business data.  That one server would hit it's limit at a lower number of users and then the cached objects would be forced out of memory and more page hits would have to hit the database ( server ). 

    Say your site carries on getting more and more popular.  You can add another web server, maybe split the business objects into two types and add another pair of business server + cache server. 

    Now you might ask why you can't just add memory and processing power to just that one server.  If you do that though there are diminishing returns.  You quickly get to a point where an extra server would be cheaper.   Should your single expensive server have a problem then your site is down until you solve it.  If you have a whole bunch of the things sharing the load then you can potentially have a spare and re-route traffic to that whilst you take one offline.

    • Marked as answer by Hamid Moghadam Tuesday, November 16, 2010 1:38 PM
    Tuesday, November 16, 2010 11:02 AM

All replies

  • Both are correct.

    Which is best depends on the amount of traffic your app ends up handling.

    Multi tier spreads the load across multiple servers but makes it a bit more complicated and introduces inefficiency,

    Multi layer is on one machine so inherently easier to communicate between the layers and that bit quicker for the first so many users.  As you get more and more traffic though, it'll slow down and eventually hit a ceiling.

    If you are expecting many users then multi tier is the way to go.

    If you aren't then multi layer.

    • Marked as answer by Hamid Moghadam Tuesday, November 16, 2010 9:33 AM
    • Unmarked as answer by Hamid Moghadam Tuesday, November 16, 2010 9:37 AM
    Tuesday, November 16, 2010 8:10 AM
  • thank you Andy,

    But could you please explain that why the nlayer program reduce the performanc in the case which traffic is hight?

    Tuesday, November 16, 2010 9:41 AM
  • Hi,

    You can refer this link for more details.

    http://davidhayden.com/blog/dave/archive/2005/07/22/2401.aspx

     

    Thanks,

    PHarlapur

    Tuesday, November 16, 2010 10:22 AM
  • N tier shares the load across machines.   Maybe you've heard of the saying "many hands make lighter work". 

    If you look at it in simple terms your one machine has X processing power and Y memory.

    Add a second server and you have 2X processing power and Y memory.

    There are complications like passing data across and firing up new processes so you don't really get that full return but let's gloss over that for now.

    Say you add another machine and you've got 3 machines then  = 3 X processing and 3Y memory. 

    Compared to this, your one machine is going to hit it's limits faster as usage goes up.

    Let's consider in some detail a 6 machine set up for a high throughput web site.

    1 & 2 are web servers.  They cache to a server 3.  When some pages are served they come straight out the cache, user session data out 3.  Machine 4 handles business objects and caches some of these on machine 5.  Many read only transactions involve one of machine 1 or 2, machine 3, 4 and 5.  Updates also go to machine 6, the database server, 6.

    The database server is also used for other internal applications.  None of these impinge on machines 1 through 5. 

    If you just have 1 user then one machine would have been fine and you didn't need all that complexity.  As you get into thousands of users though you will see huge benefits from that caching.  With one server you'd have less memory caching pages, session and business data.  That one server would hit it's limit at a lower number of users and then the cached objects would be forced out of memory and more page hits would have to hit the database ( server ). 

    Say your site carries on getting more and more popular.  You can add another web server, maybe split the business objects into two types and add another pair of business server + cache server. 

    Now you might ask why you can't just add memory and processing power to just that one server.  If you do that though there are diminishing returns.  You quickly get to a point where an extra server would be cheaper.   Should your single expensive server have a problem then your site is down until you solve it.  If you have a whole bunch of the things sharing the load then you can potentially have a spare and re-route traffic to that whilst you take one offline.

    • Marked as answer by Hamid Moghadam Tuesday, November 16, 2010 1:38 PM
    Tuesday, November 16, 2010 11:02 AM