views:

301

answers:

5

Note: When I refer to tier, I mean a physical tier. Many of the questions on this site relating to "tiers" are referring to logical layers, which is not what I'm asking about.

I am designing an app using a standard "3 layer" architecture, with presentation, business logic (BLL) and data access (DAL) layers. The technology is WPF, C#, LINQ and SQL Server 2008. My question relates to the physical architecture of this app.

I can place the BLL/DAL in a standard DLL which is loaded and run on the user machine, making a 2 tier architecture - client machine and database server. But it is not too difficult to turn the BLL/DAL into a WCF service which sits on an app server and is called from the user machine. This would give me a 3 tier architecture - client machine, app server and database server.

My question is this - what is the advantage of using a 3 tier architecture? I've often been told that 3 tiers add scalability, but it's not immediately apparent to me why this would be. And surely you are going to take a performance hit with the same data having to make two hops over the wire - from database server to app server, then from app server to client machine.

I would appreciate the advice of experienced architects and developers out there.

+1  A: 

It can be. It depends on what has been implemented and how.

The driving force for creating a 3 tier physical architecture is not necessarily performance related.

The reason scalability is quoted is that a service might run on a server farm, but the clients would be unaware of this. The size of the server farm can be increased to meet demand if the architecture has been designed to support it.

Mitch Wheat
+4  A: 

It depends on the use of your application and your requirement for security. If your application is being used over the Internet, and you're storing anything that is potentially sensitive in any way, adding the physical remove for the database is strongly recommended. Never, ever let anyone from the outside onto any machine with direct access to your database. People can and will attempt to break your security for no better reason than they have nothing better to do.

Scalability can be a factor as well, both in front of the presentation layer (in front of the web servers) and in the database. Placing a load balancer in front of the presentation layer allows incoming requests to be routed to an array of machines that can be managed independently. Machines can be added to the pool in times of need and removed for maintenance. Placing load balancers between the other layers can have the same impact. The idea is to provide a flexible, dynamic back-end environment that can be adjusted as demand requires.

jfawcett
+2  A: 

Inefficiency is in the eye of the beholder.

For example, having everything happening on the client may increase the memory footprint or CPU/network requirements of the client computers. If this work can be off-loaded to a server/server farm you may save having to do hardware upgrades of client PCs just to run your software. If more resources or upgrades are needed, they can be added/done in the business logic tier without impacting the clients.

Also, having the business logic on its own tier may be more efficient later (from a software development perspective) when you need to expose some of your application's functionality in a web-based system, or an Outlook add-in, or an iPhone app. You don't want to have to update all of these systems whenever the business logic changes slightly.

Security may be better as your users don't need direct access to the database server, they are isolated by the application server.

It also forces you to think about your application in a modular way with well defined interfaces which may have architectural benefits to the design of your application.

Chris Latta
+3  A: 

Whenever you find yourself asking the question "Is X inefficient?" you should, immediately, ask yourself three precursor questions:

  1. By "inefficient," what resource do you think it should be using efficiently and may not be? Time? Space? Bandwidth? Development hours?

  2. Why do you care? No, seriously: If you're going to spend even one minute answering this question, there has to be a reason. What is that reason?

  3. Compared to what?

As far as your comment about scalability is concerned: For a time, I had the unfortunate responsibility of maintaining a system whose architect who had been told that minimizing round-trips to the database would make an application scalable. He took that insight and ran with it. You can read about this project here. It occurs to me that I ought to have mentioned that at no point during the entire decade-plus-long lifetime of that application were there more than four users logged in simultaneously.

Robert Rossney
+1  A: 

Main advantage of 3t applications described like you did is not scalability. Maintainability maybe.

In order to make your architecture scalable you need one more technology you didn't mentioned. - you need services. I would suggest WCF.

Making your BLL WCF service (or multiple services) would make your application much more efficient and scalable, allowing your BLL to run on different/multiple machines.

Fedor Hajdu