1

I am creating one small database application. In these application I am using java swing and accessing database using Hibernate. Yesterday my friend asked me which architecture you are using two tier or three tier? My answer is I don't know. Then I searched on google and found some answers and the link for these answers are as follow.

3 Tier Architecture vs 2 Tier Architecture

Explain the different tiers of 2 tier & 3 tier architecture?

I read this two links so I understood little.

But still unable that how they are implemented practically I mean to say in programming language.

Still I am unable to understand what it is? How the are implemented? can you give me one practical example where they are implemented?

Community
  • 1
  • 1
  • one more thing is that how can i also decide or judge which tier i am using right now i mean to say two tier or three tier? –  Jun 30 '13 at 06:25

2 Answers2

3

In your application,you have a Swing based GUI and a connection to DB. When user makes some change via GUI it immediately reflects on DB(i.e. update/insert/delete etc). Hence you have a 2 tier architecture (GUI + DB).

Now suppose that when user makes some change via GUI, instead of going directly to DB, you are sending the appropriate request to some server(e.g. Web server) which handles your request and then performs the appropriate operation on DB. In this case you have a 3 tier architecture (GUI + Server + DB)

Grisha Weintraub
  • 7,803
  • 1
  • 25
  • 45
  • so now i can say that i am using 2 tier architecture. thanks. But one more thing as i specified i am using hibernate as middle then also it is two tier? –  Jun 30 '13 at 06:38
  • Hibernate is only a one of ways to work with DB. It doesn't influence the architecture. – Grisha Weintraub Jun 30 '13 at 06:44
2

As per your discussion with Grisha, it seems you need to consider the difference between Layers and Tiers.

Layers in an application are logical units of separation. For example you may have User Interface layer, Business Logic layer, Service Layer, Data Access layer. Every layer is supposed to have the code to implement that part/unit of the application.

The tier represent physical units of separation/deployment. If all layers(User Interface layer, Business Logic layer, Service Layer, Data Access layer) are deployed in same server machine, then you have just one tier.

If database is hosted on separate machine and all other layers in another server then your have two tiers.

Usually as the number of users (or the load on application) increases, a single server can not perform efficiently then we need to add more tiers if possible or need to user more powerful servers.

So number of tiers can be less or equal to number of layers you have. You can tell the number of layers in designing phase only, as the architecture of application is decided, but number of tiers can be confirmed after you have planned deployment.

Please have a look on section "Scalability Options of the Design" @ http://www.codeproject.com/Articles/70061/Architecture-Guide-ASP-NET-MVC-Framework-N-tier-En

Please feel free to discuss more if you have any further question. Thanks

Praveen Prajapati
  • 969
  • 1
  • 16
  • 21
  • so,As per your answer if i say my database application will be implemented on single machine so it is one tier. Am i right? –  Jul 01 '13 at 13:27
  • 1
    Yes, If database application will be implemented on single machine, and the same machine is going to host other parts of application...then it is one tier....and You are right ! – Praveen Prajapati Jul 01 '13 at 13:30
  • And if i am having two machines one machine will have full application with database and another machine will have only one form of application then? –  Jul 01 '13 at 13:38
  • 2
    then it would be two tier...as you will be having User Interface Layer (one form of application) in one machine and rest of the application in other one. – Praveen Prajapati Jul 01 '13 at 13:45